diff --git a/Modules/DiffusionImaging/Connectomics/Algorithms/itkConnectomicsNetworkToConnectivityMatrixImageFilter.cpp b/Modules/DiffusionImaging/Connectomics/Algorithms/itkConnectomicsNetworkToConnectivityMatrixImageFilter.cpp index 947032fbb8..5baaf2fa7e 100644 --- a/Modules/DiffusionImaging/Connectomics/Algorithms/itkConnectomicsNetworkToConnectivityMatrixImageFilter.cpp +++ b/Modules/DiffusionImaging/Connectomics/Algorithms/itkConnectomicsNetworkToConnectivityMatrixImageFilter.cpp @@ -1,185 +1,186 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef ITK_ConnectomicsNetworkToConnectivityMatrixImageFilter_CPP #define ITK_ConnectomicsNetworkToConnectivityMatrixImageFilter_CPP #include #include itk::ConnectomicsNetworkToConnectivityMatrixImageFilter::ConnectomicsNetworkToConnectivityMatrixImageFilter() - : m_BinaryConnectivity(false) - , m_RescaleConnectivity(false) - , m_InputNetwork(NULL) + : m_BinaryConnectivity(false) + , m_RescaleConnectivity(false) + , m_InputNetwork(NULL) { } itk::ConnectomicsNetworkToConnectivityMatrixImageFilter::~ConnectomicsNetworkToConnectivityMatrixImageFilter() { } void itk::ConnectomicsNetworkToConnectivityMatrixImageFilter::GenerateData() { - this->AllocateOutputs(); + this->AllocateOutputs(); - OutputImageType::Pointer output = this->GetOutput(); + OutputImageType::Pointer output = this->GetOutput(); - if(m_InputNetwork.IsNull()) - { - MITK_ERROR << "Failed to generate data, no valid network was set."; - return; - } + if(m_InputNetwork.IsNull()) + { + MITK_ERROR << "Failed to generate data, no valid network was set."; + return; + } - typedef mitk::ConnectomicsNetwork::NetworkType NetworkType; - typedef boost::graph_traits< NetworkType >::vertex_descriptor DescriptorType; - typedef boost::graph_traits< NetworkType >::vertex_iterator IteratorType; + typedef mitk::ConnectomicsNetwork::NetworkType NetworkType; + typedef boost::graph_traits< NetworkType >::vertex_descriptor DescriptorType; + typedef boost::graph_traits< NetworkType >::vertex_iterator IteratorType; - // prepare connectivity matrix for data - std::vector< std::vector< int > > connectivityMatrix; - int numberOfVertices = m_InputNetwork->GetNumberOfVertices(); + // prepare connectivity matrix for data + std::vector< std::vector< int > > connectivityMatrix; + int numberOfVertices = m_InputNetwork->GetNumberOfVertices(); - connectivityMatrix.resize( numberOfVertices ); - for( int index(0); index < numberOfVertices; index++ ) - { - connectivityMatrix[ index ].resize( numberOfVertices ); - } + connectivityMatrix.resize( numberOfVertices ); + for( int index(0); index < numberOfVertices; index++ ) + { + connectivityMatrix[ index ].resize( numberOfVertices ); + } - // Create LabelToIndex translation - std::map< std::string, DescriptorType > labelToIndexMap; + // Create LabelToIndex translation + std::map< std::string, DescriptorType > labelToIndexMap; - NetworkType boostGraph = *(m_InputNetwork->GetBoostGraph()); + NetworkType boostGraph = *(m_InputNetwork->GetBoostGraph()); - // translate index to label - IteratorType iterator, end; - boost::tie(iterator, end) = boost::vertices( boostGraph ); + // translate index to label + IteratorType iterator, end; + boost::tie(iterator, end) = boost::vertices( boostGraph ); - for ( ; iterator != end; ++iterator) - { - labelToIndexMap.insert( - std::pair< std::string, DescriptorType >( - boostGraph[ *iterator ].label, *iterator ) - ); - } + for ( ; iterator != end; ++iterator) + { + labelToIndexMap.insert( + std::pair< std::string, DescriptorType >( + boostGraph[ *iterator ].label, *iterator ) + ); + } - std::vector< std::string > indexToLabel; + std::vector< std::string > indexToLabel; - // translate index to label - indexToLabel.resize( numberOfVertices ); + // translate index to label + indexToLabel.resize( numberOfVertices ); - boost::tie(iterator, end) = boost::vertices( boostGraph ); + boost::tie(iterator, end) = boost::vertices( boostGraph ); - for ( ; iterator != end; ++iterator) - { - indexToLabel[ *iterator ] = boostGraph[ *iterator ].label; - } + for ( ; iterator != end; ++iterator) + { + indexToLabel[ *iterator ] = boostGraph[ *iterator ].label; + } - //translate label to position - std::vector< std::string > positionToLabelVector; - positionToLabelVector = indexToLabel; + //translate label to position + std::vector< std::string > positionToLabelVector; + positionToLabelVector = indexToLabel; - std::sort ( positionToLabelVector.begin(), positionToLabelVector.end() ); + std::sort ( positionToLabelVector.begin(), positionToLabelVector.end() ); - for( int outerLoop( 0 ); outerLoop < numberOfVertices; outerLoop++ ) + for( int outerLoop( 0 ); outerLoop < numberOfVertices; outerLoop++ ) + { + DescriptorType fromVertexDescriptor = labelToIndexMap.find( positionToLabelVector[ outerLoop ] )->second; + for( int innerLoop( outerLoop + 1 ); innerLoop < numberOfVertices; innerLoop++ ) { - DescriptorType fromVertexDescriptor = labelToIndexMap.find( positionToLabelVector[ outerLoop ] )->second; - for( int innerLoop( outerLoop + 1 ); innerLoop < numberOfVertices; innerLoop++ ) - { - DescriptorType toVertexDescriptor = labelToIndexMap.find( positionToLabelVector[ innerLoop ] )->second; + DescriptorType toVertexDescriptor = labelToIndexMap.find( positionToLabelVector[ innerLoop ] )->second; - int weight( 0 ); + int weight( 0 ); - if( boost::edge(toVertexDescriptor, fromVertexDescriptor, boostGraph ).second ) - { - weight = m_InputNetwork->GetEdge( fromVertexDescriptor , toVertexDescriptor ).weight;; - } - connectivityMatrix[outerLoop][innerLoop] = weight; - connectivityMatrix[innerLoop][outerLoop] = weight; - } + if( boost::edge(toVertexDescriptor, fromVertexDescriptor, boostGraph ).second ) + { + weight = m_InputNetwork->GetEdge( fromVertexDescriptor , toVertexDescriptor ).weight;; + } + connectivityMatrix[outerLoop][innerLoop] = weight; + connectivityMatrix[innerLoop][outerLoop] = weight; } - - - OutputImageType::SpacingType spacing; - spacing[0] = 1.0; - spacing[1] = 1.0; - OutputImageType::PointType origin; - origin[0] = 0.0; - origin[1] = 0.0; - OutputImageType::IndexType index; - index[0] = 0.0; - index[1] = 0.0; - OutputImageType::SizeType size; - size[0] = numberOfVertices; - size[1] = numberOfVertices; - OutputImageType::RegionType region; - region.SetIndex( index ); - region.SetSize( size ); - - output->SetSpacing( spacing ); // Set the image spacing - output->SetOrigin( origin ); // Set the image origin - output->SetRegions( region ); - output->Allocate(); - output->FillBuffer(0); - - - itk::ImageRegionIterator< OutputImageType > it_connect(output, output->GetLargestPossibleRegion()); - - int counter( 0 ); - - double rescaleFactor( 1.0 ); - double rescaleMax( 1.0 ); - - if( m_RescaleConnectivity ) - { - rescaleFactor = rescaleMax / m_InputNetwork->GetMaximumWeight(); - } - - // Colour pixels according to connectivity - if( m_BinaryConnectivity ) + } + + + OutputImageType::SpacingType spacing; + spacing[0] = 1.0; + spacing[1] = 1.0; + OutputImageType::PointType origin; + origin[0] = 0.0; + origin[1] = 0.0; + OutputImageType::IndexType index; + index[0] = 0.0; + index[1] = 0.0; + OutputImageType::SizeType size; + size[0] = numberOfVertices; + size[1] = numberOfVertices; + OutputImageType::RegionType region; + region.SetIndex( index ); + region.SetSize( size ); + + output->SetSpacing( spacing ); // Set the image spacing + output->SetOrigin( origin ); // Set the image origin + output->SetRegions( region ); + output->Allocate(); + output->FillBuffer(0); + + + itk::ImageRegionIterator< OutputImageType > it_connect(output, output->GetLargestPossibleRegion()); + + int counter( 0 ); + + double rescaleFactor( 1.0 ); + double rescaleMax( 255.0 ); + + if( m_RescaleConnectivity ) + { + rescaleFactor = rescaleMax / m_InputNetwork->GetMaximumWeight(); + } + + // Colour pixels according to connectivity + if( m_BinaryConnectivity ) + { + // binary connectivity + while( !it_connect.IsAtEnd() ) { - // binary connectivity - while( !it_connect.IsAtEnd() ) - { - if( connectivityMatrix[ ( counter - counter % numberOfVertices ) / numberOfVertices][ counter % numberOfVertices ] ) - { - it_connect.Set( 1 ); - } - else - { - it_connect.Set( 0 ); - } - ++it_connect; - counter++; - } + if( connectivityMatrix[ ( counter - counter % numberOfVertices ) / numberOfVertices][ counter % numberOfVertices ] ) + { + it_connect.Set( 1 ); + } + else + { + it_connect.Set( 0 ); + } + ++it_connect; + counter++; } - else + } + else + { + // if desired rescale to the 0-255 range + while( !it_connect.IsAtEnd() ) { - // if desired rescale to the 0-255 range - while( !it_connect.IsAtEnd() ) - { - double val = rescaleFactor*connectivityMatrix[ ( counter - counter % numberOfVertices ) / numberOfVertices][ counter % numberOfVertices ]; - it_connect.Set( val ); - ++it_connect; - counter++; - } + it_connect.Set( ( unsigned short ) rescaleFactor * + connectivityMatrix[ ( counter - counter % numberOfVertices ) / numberOfVertices][ counter % numberOfVertices ] + ); + ++it_connect; + counter++; } + } } #endif diff --git a/Modules/DiffusionImaging/Connectomics/Algorithms/itkConnectomicsNetworkToConnectivityMatrixImageFilter.h b/Modules/DiffusionImaging/Connectomics/Algorithms/itkConnectomicsNetworkToConnectivityMatrixImageFilter.h index f1133a6030..6d984feba8 100644 --- a/Modules/DiffusionImaging/Connectomics/Algorithms/itkConnectomicsNetworkToConnectivityMatrixImageFilter.h +++ b/Modules/DiffusionImaging/Connectomics/Algorithms/itkConnectomicsNetworkToConnectivityMatrixImageFilter.h @@ -1,80 +1,80 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef ITK_ConnectomicsNetworkToConnectivityMatrixImageFilter_H #define ITK_ConnectomicsNetworkToConnectivityMatrixImageFilter_H // ITK includes #include #include // MITK includes #include "mitkConnectomicsNetwork.h" namespace itk { - class ConnectomicsNetworkToConnectivityMatrixImageFilter : public ImageSource< itk::Image< double, 2 > > + class ConnectomicsNetworkToConnectivityMatrixImageFilter : public ImageSource< itk::Image< unsigned short, 2 > > { public: typedef ConnectomicsNetworkToConnectivityMatrixImageFilter Self; typedef ProcessObject Superclass; typedef SmartPointer< Self > Pointer; typedef SmartPointer< const Self > ConstPointer; - typedef itk::Image< double, 2 > OutputImageType; + typedef itk::Image< unsigned short, 2 > OutputImageType; typedef OutputImageType::PixelType OutPixelType; typedef mitk::ConnectomicsNetwork InputType; itkNewMacro(Self) itkTypeMacro( ConnectomicsNetworkToConnectivityMatrixImageFilter, ImageSource ) /** Get/Set m_BinaryConnectivity **/ itkSetMacro( BinaryConnectivity, bool) itkGetMacro( BinaryConnectivity, bool) /** Get/Set m_RescaleConnectivity **/ itkSetMacro( RescaleConnectivity, bool) itkGetMacro( RescaleConnectivity, bool) itkSetMacro( InputNetwork, InputType::Pointer) void GenerateData(); protected: ConnectomicsNetworkToConnectivityMatrixImageFilter(); virtual ~ConnectomicsNetworkToConnectivityMatrixImageFilter(); /** Controls whether the connectivity matrix is binary */ bool m_BinaryConnectivity; /** Controls whether the connectivity matrix entries are rescaled to lie between 0 and 255*/ bool m_RescaleConnectivity; InputType::Pointer m_InputNetwork; }; } #ifndef ITK_MANUAL_INSTANTIATION #include "itkConnectomicsNetworkToConnectivityMatrixImageFilter.cpp" #endif #endif /* ITK_ConnectomicsNetworkToConnectivityMatrixImageFilter_H */ diff --git a/Modules/DiffusionImaging/Connectomics/Algorithms/mitkConnectomicsNetworkCreator.cpp b/Modules/DiffusionImaging/Connectomics/Algorithms/mitkConnectomicsNetworkCreator.cpp old mode 100755 new mode 100644 index 9644bd7aa9..ea5f62a746 --- a/Modules/DiffusionImaging/Connectomics/Algorithms/mitkConnectomicsNetworkCreator.cpp +++ b/Modules/DiffusionImaging/Connectomics/Algorithms/mitkConnectomicsNetworkCreator.cpp @@ -1,860 +1,840 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkConnectomicsNetworkCreator.h" #include #include #include "mitkConnectomicsConstantsManager.h" #include "mitkImageAccessByItk.h" #include "mitkImageStatisticsHolder.h" #include "mitkImageCast.h" #include "itkImageRegionIteratorWithIndex.h" // VTK #include #include #include mitk::ConnectomicsNetworkCreator::ConnectomicsNetworkCreator() : m_FiberBundle() , m_Segmentation() , m_ConNetwork( mitk::ConnectomicsNetwork::New() ) , idCounter(0) , m_LabelToVertexMap() , m_LabelToNodePropertyMap() -, allowLoops( true ) -, m_UseCoMCoordinates( true ) +, allowLoops( false ) +, m_UseCoMCoordinates( false ) , m_LabelsToCoordinatesMap() -, m_MappingStrategy( EndElementPosition ) +, m_MappingStrategy( EndElementPositionAvoidingWhiteMatter ) , m_EndPointSearchRadius( 10.0 ) { } mitk::ConnectomicsNetworkCreator::ConnectomicsNetworkCreator( mitk::Image::Pointer segmentation, mitk::FiberBundleX::Pointer fiberBundle ) : m_FiberBundle(fiberBundle) , m_Segmentation(segmentation) , m_ConNetwork( mitk::ConnectomicsNetwork::New() ) , idCounter(0) , m_LabelToVertexMap() , m_LabelToNodePropertyMap() , allowLoops( false ) , m_LabelsToCoordinatesMap() -, m_MappingStrategy( EndElementPosition ) +, m_MappingStrategy( EndElementPositionAvoidingWhiteMatter ) , m_EndPointSearchRadius( 10.0 ) { } mitk::ConnectomicsNetworkCreator::~ConnectomicsNetworkCreator() { } void mitk::ConnectomicsNetworkCreator::SetFiberBundle(mitk::FiberBundleX::Pointer fiberBundle) { m_FiberBundle = fiberBundle; } void mitk::ConnectomicsNetworkCreator::SetSegmentation(mitk::Image::Pointer segmentation) { m_Segmentation = segmentation; } itk::Point mitk::ConnectomicsNetworkCreator::GetItkPoint(double point[3]) { itk::Point itkPoint; itkPoint[0] = point[0]; itkPoint[1] = point[1]; itkPoint[2] = point[2]; return itkPoint; } void mitk::ConnectomicsNetworkCreator::CreateNetworkFromFibersAndSegmentation() { //empty graph m_ConNetwork->clear(); m_LabelToVertexMap.clear(); m_LabelToNodePropertyMap.clear(); - { - CalculateCenterOfMass(); - } - - std::cout << m_ConNetwork->GetNumberOfVertices() << std::endl; vtkSmartPointer fiberPolyData = m_FiberBundle->GetFiberPolyData(); + vtkSmartPointer vLines = fiberPolyData->GetLines(); + vLines->InitTraversal(); int numFibers = m_FiberBundle->GetNumFibers(); for( int fiberID( 0 ); fiberID < numFibers; fiberID++ ) { - vtkCell* cell = fiberPolyData->GetCell(fiberID); - int numPoints = cell->GetNumberOfPoints(); - vtkPoints* points = cell->GetPoints(); + vtkIdType numPointsInCell(0); + vtkIdType* pointsInCell(NULL); + vLines->GetNextCell ( numPointsInCell, pointsInCell ); TractType::Pointer singleTract = TractType::New(); - for( int pointInCellID( 0 ); pointInCellID < numPoints ; pointInCellID++) + for( int pointInCellID( 0 ); pointInCellID < numPointsInCell ; pointInCellID++) { // push back point - PointType point = GetItkPoint( points->GetPoint( pointInCellID ) ); + PointType point = GetItkPoint( fiberPolyData->GetPoint( pointsInCell[ pointInCellID ] ) ); singleTract->InsertElement( singleTract->Size(), point ); } if ( singleTract && ( singleTract->Size() > 0 ) ) { AddConnectionToNetwork( ReturnAssociatedVertexPairForLabelPair( ReturnLabelForFiberTract( singleTract, m_MappingStrategy ) ) ); } } // Prune unconnected nodes //m_ConNetwork->PruneUnconnectedSingleNodes(); // provide network with geometry m_ConNetwork->SetGeometry( dynamic_cast(m_Segmentation->GetGeometry()->Clone().GetPointer()) ); m_ConNetwork->UpdateBounds(); m_ConNetwork->SetIsModified( true ); MBI_INFO << mitk::ConnectomicsConstantsManager::CONNECTOMICS_WARNING_INFO_NETWORK_CREATED; } void mitk::ConnectomicsNetworkCreator::AddConnectionToNetwork(ConnectionType newConnection) { VertexType vertexA = newConnection.first; VertexType vertexB = newConnection.second; // check for loops (if they are not allowed) if( allowLoops || !( vertexA == vertexB ) ) { // If the connection already exists, increment weight, else create connection if ( m_ConNetwork->EdgeExists( vertexA, vertexB ) ) { m_ConNetwork->IncreaseEdgeWeight( vertexA, vertexB ); } else { m_ConNetwork->AddEdge( vertexA, vertexB ); } } } mitk::ConnectomicsNetworkCreator::VertexType mitk::ConnectomicsNetworkCreator::ReturnAssociatedVertexForLabel( ImageLabelType label ) { // if label is not known, create entry if( ! ( m_LabelToVertexMap.count( label ) > 0 ) ) { VertexType newVertex = m_ConNetwork->AddVertex( idCounter ); idCounter++; SupplyVertexWithInformation(label, newVertex); m_LabelToVertexMap.insert( std::pair< ImageLabelType, VertexType >( label, newVertex ) ); } //return associated vertex return m_LabelToVertexMap.find( label )->second; } mitk::ConnectomicsNetworkCreator::ConnectionType mitk::ConnectomicsNetworkCreator::ReturnAssociatedVertexPairForLabelPair( ImageLabelPairType labelpair ) { //hand both labels through to the single label function ConnectionType connection( ReturnAssociatedVertexForLabel(labelpair.first), ReturnAssociatedVertexForLabel(labelpair.second) ); return connection; } mitk::ConnectomicsNetworkCreator::ImageLabelPairType mitk::ConnectomicsNetworkCreator::ReturnLabelForFiberTract( TractType::Pointer singleTract, mitk::ConnectomicsNetworkCreator::MappingStrategy strategy) { switch( strategy ) { case EndElementPosition: { return EndElementPositionLabel( singleTract ); } case PrecomputeAndDistance: { return PrecomputeVertexLocationsBySegmentation( singleTract ); } case JustEndPointVerticesNoLabel: { return JustEndPointVerticesNoLabelTest( singleTract ); } case EndElementPositionAvoidingWhiteMatter: { return EndElementPositionLabelAvoidingWhiteMatter( singleTract ); } } // To remove warnings, this code should never be reached MBI_ERROR << mitk::ConnectomicsConstantsManager::CONNECTOMICS_ERROR_INVALID_MAPPING; ImageLabelPairType nullPair( NULL, NULL ); return nullPair; } mitk::ConnectomicsNetworkCreator::ImageLabelPairType mitk::ConnectomicsNetworkCreator::EndElementPositionLabel( TractType::Pointer singleTract ) { ImageLabelPairType labelpair; {// Note: .fib image tracts are safed using index coordinates mitk::Point3D firstElementFiberCoord, lastElementFiberCoord; mitk::Point3D firstElementSegCoord, lastElementSegCoord; mitk::Index3D firstElementSegIndex, lastElementSegIndex; if( singleTract->front().Size() != 3 ) { MBI_ERROR << mitk::ConnectomicsConstantsManager::CONNECTOMICS_ERROR_INVALID_DIMENSION_NEED_3; } for( int index = 0; index < singleTract->front().Size(); index++ ) { firstElementFiberCoord.SetElement( index, singleTract->front().GetElement( index ) ); lastElementFiberCoord.SetElement( index, singleTract->back().GetElement( index ) ); } // convert from fiber index coordinates to segmentation index coordinates FiberToSegmentationCoords( firstElementFiberCoord, firstElementSegCoord ); FiberToSegmentationCoords( lastElementFiberCoord, lastElementSegCoord ); for( int index = 0; index < 3; index++ ) { firstElementSegIndex.SetElement( index, firstElementSegCoord.GetElement( index ) ); lastElementSegIndex.SetElement( index, lastElementSegCoord.GetElement( index ) ); } int firstLabel = m_Segmentation->GetPixelValueByIndex( firstElementSegIndex ); int lastLabel = m_Segmentation->GetPixelValueByIndex( lastElementSegIndex ); labelpair.first = firstLabel; labelpair.second = lastLabel; // Add property to property map CreateNewNode( firstLabel, firstElementSegIndex, m_UseCoMCoordinates ); CreateNewNode( lastLabel, lastElementSegIndex, m_UseCoMCoordinates ); } return labelpair; } mitk::ConnectomicsNetworkCreator::ImageLabelPairType mitk::ConnectomicsNetworkCreator::PrecomputeVertexLocationsBySegmentation( TractType::Pointer singleTract ) { ImageLabelPairType labelpair; return labelpair; } mitk::ConnectomicsNetworkCreator::ImageLabelPairType mitk::ConnectomicsNetworkCreator::EndElementPositionLabelAvoidingWhiteMatter( TractType::Pointer singleTract ) { ImageLabelPairType labelpair; {// Note: .fib image tracts are safed using index coordinates mitk::Point3D firstElementFiberCoord, lastElementFiberCoord; mitk::Point3D firstElementSegCoord, lastElementSegCoord; mitk::Index3D firstElementSegIndex, lastElementSegIndex; if( singleTract->front().Size() != 3 ) { MBI_ERROR << mitk::ConnectomicsConstantsManager::CONNECTOMICS_ERROR_INVALID_DIMENSION_NEED_3; } for( int index = 0; index < singleTract->front().Size(); index++ ) { firstElementFiberCoord.SetElement( index, singleTract->front().GetElement( index ) ); lastElementFiberCoord.SetElement( index, singleTract->back().GetElement( index ) ); } // convert from fiber index coordinates to segmentation index coordinates FiberToSegmentationCoords( firstElementFiberCoord, firstElementSegCoord ); FiberToSegmentationCoords( lastElementFiberCoord, lastElementSegCoord ); for( int index = 0; index < 3; index++ ) { firstElementSegIndex.SetElement( index, firstElementSegCoord.GetElement( index ) ); lastElementSegIndex.SetElement( index, lastElementSegCoord.GetElement( index ) ); } int firstLabel = m_Segmentation->GetPixelValueByIndex( firstElementSegIndex ); int lastLabel = m_Segmentation->GetPixelValueByIndex( lastElementSegIndex ); // Check whether the labels belong to the white matter (which means, that the fibers ended early) bool extendFront(false), extendEnd(false), retractFront(false), retractEnd(false); extendFront = !IsNonWhiteMatterLabel( firstLabel ); extendEnd = !IsNonWhiteMatterLabel( lastLabel ); retractFront = IsBackgroundLabel( firstLabel ); retractEnd = IsBackgroundLabel( lastLabel ); //if( extendFront || extendEnd ) //{ //MBI_INFO << "Before Start: " << firstLabel << " at " << firstElementSegIndex[ 0 ] << " " << firstElementSegIndex[ 1 ] << " " << firstElementSegIndex[ 2 ] << " End: " << lastLabel << " at " << lastElementSegIndex[ 0 ] << " " << lastElementSegIndex[ 1 ] << " " << lastElementSegIndex[ 2 ]; //} if ( extendFront ) { std::vector< int > indexVectorOfPointsToUse; //Use first two points for direction indexVectorOfPointsToUse.push_back( 1 ); indexVectorOfPointsToUse.push_back( 0 ); // label and coordinate temp storage int tempLabel( firstLabel ); mitk::Index3D tempIndex = firstElementSegIndex; LinearExtensionUntilGreyMatter( indexVectorOfPointsToUse, singleTract, tempLabel, tempIndex ); firstLabel = tempLabel; firstElementSegIndex = tempIndex; } if ( extendEnd ) { std::vector< int > indexVectorOfPointsToUse; //Use last two points for direction indexVectorOfPointsToUse.push_back( singleTract->Size() - 2 ); indexVectorOfPointsToUse.push_back( singleTract->Size() - 1 ); // label and coordinate temp storage int tempLabel( lastLabel ); mitk::Index3D tempIndex = lastElementSegIndex; LinearExtensionUntilGreyMatter( indexVectorOfPointsToUse, singleTract, tempLabel, tempIndex ); lastLabel = tempLabel; lastElementSegIndex = tempIndex; } if ( retractFront ) { // label and coordinate temp storage int tempLabel( firstLabel ); mitk::Index3D tempIndex = firstElementSegIndex; RetractionUntilBrainMatter( true, singleTract, tempLabel, tempIndex ); firstLabel = tempLabel; firstElementSegIndex = tempIndex; } if ( retractEnd ) { // label and coordinate temp storage int tempLabel( lastLabel ); mitk::Index3D tempIndex = lastElementSegIndex; RetractionUntilBrainMatter( false, singleTract, tempLabel, tempIndex ); lastLabel = tempLabel; lastElementSegIndex = tempIndex; } //if( extendFront || extendEnd ) //{ // MBI_INFO << "After Start: " << firstLabel << " at " << firstElementSegIndex[ 0 ] << " " << firstElementSegIndex[ 1 ] << " " << firstElementSegIndex[ 2 ] << " End: " << lastLabel << " at " << lastElementSegIndex[ 0 ] << " " << lastElementSegIndex[ 1 ] << " " << lastElementSegIndex[ 2 ]; //} labelpair.first = firstLabel; labelpair.second = lastLabel; // Add property to property map CreateNewNode( firstLabel, firstElementSegIndex, m_UseCoMCoordinates ); CreateNewNode( lastLabel, lastElementSegIndex, m_UseCoMCoordinates ); } return labelpair; } mitk::ConnectomicsNetworkCreator::ImageLabelPairType mitk::ConnectomicsNetworkCreator::JustEndPointVerticesNoLabelTest( TractType::Pointer singleTract ) { ImageLabelPairType labelpair; {// Note: .fib image tracts are safed using index coordinates mitk::Point3D firstElementFiberCoord, lastElementFiberCoord; mitk::Point3D firstElementSegCoord, lastElementSegCoord; mitk::Index3D firstElementSegIndex, lastElementSegIndex; if( singleTract->front().Size() != 3 ) { MBI_ERROR << mitk::ConnectomicsConstantsManager::CONNECTOMICS_ERROR_INVALID_DIMENSION_NEED_3; } for( int index = 0; index < singleTract->front().Size(); index++ ) { firstElementFiberCoord.SetElement( index, singleTract->front().GetElement( index ) ); lastElementFiberCoord.SetElement( index, singleTract->back().GetElement( index ) ); } // convert from fiber index coordinates to segmentation index coordinates FiberToSegmentationCoords( firstElementFiberCoord, firstElementSegCoord ); FiberToSegmentationCoords( lastElementFiberCoord, lastElementSegCoord ); for( int index = 0; index < 3; index++ ) { firstElementSegIndex.SetElement( index, firstElementSegCoord.GetElement( index ) ); lastElementSegIndex.SetElement( index, lastElementSegCoord.GetElement( index ) ); } int firstLabel = 1 * firstElementSegIndex[ 0 ] + 1000 * firstElementSegIndex[ 1 ] + 1000000 * firstElementSegIndex[ 2 ]; int lastLabel = 1 * firstElementSegIndex[ 0 ] + 1000 * firstElementSegIndex[ 1 ] + 1000000 * firstElementSegIndex[ 2 ]; labelpair.first = firstLabel; labelpair.second = lastLabel; // Add property to property map CreateNewNode( firstLabel, firstElementSegIndex, m_UseCoMCoordinates ); CreateNewNode( lastLabel, lastElementSegIndex, m_UseCoMCoordinates ); } return labelpair; } void mitk::ConnectomicsNetworkCreator::SupplyVertexWithInformation( ImageLabelType& label, VertexType& vertex ) { // supply a vertex with the additional information belonging to the label // TODO: Implement additional information acquisition m_ConNetwork->SetLabel( vertex, m_LabelToNodePropertyMap.find( label )->second.label ); m_ConNetwork->SetCoordinates( vertex, m_LabelToNodePropertyMap.find( label )->second.coordinates ); } std::string mitk::ConnectomicsNetworkCreator::LabelToString( ImageLabelType& label ) { int tempInt = (int) label; std::stringstream ss;//create a stringstream std::string tempString; ss << tempInt;//add number to the stream tempString = ss.str(); return tempString;//return a string with the contents of the stream } mitk::ConnectomicsNetwork::Pointer mitk::ConnectomicsNetworkCreator::GetNetwork() { return m_ConNetwork; } void mitk::ConnectomicsNetworkCreator::FiberToSegmentationCoords( mitk::Point3D& fiberCoord, mitk::Point3D& segCoord ) { mitk::Point3D tempPoint; // convert from fiber index coordinates to segmentation index coordinates m_FiberBundle->GetGeometry()->IndexToWorld( fiberCoord, tempPoint ); m_Segmentation->GetGeometry()->WorldToIndex( tempPoint, segCoord ); } void mitk::ConnectomicsNetworkCreator::SegmentationToFiberCoords( mitk::Point3D& segCoord, mitk::Point3D& fiberCoord ) { mitk::Point3D tempPoint; // convert from fiber index coordinates to segmentation index coordinates m_Segmentation->GetGeometry()->IndexToWorld( segCoord, tempPoint ); m_FiberBundle->GetGeometry()->WorldToIndex( tempPoint, fiberCoord ); } bool mitk::ConnectomicsNetworkCreator::IsNonWhiteMatterLabel( int labelInQuestion ) { bool isWhite( false ); isWhite = ( ( labelInQuestion == freesurfer_Left_Cerebral_White_Matter ) || ( labelInQuestion == freesurfer_Left_Cerebellum_White_Matter ) || ( labelInQuestion == freesurfer_Right_Cerebral_White_Matter ) || ( labelInQuestion == freesurfer_Right_Cerebellum_White_Matter )|| ( labelInQuestion == freesurfer_Left_Cerebellum_Cortex ) || ( labelInQuestion == freesurfer_Right_Cerebellum_Cortex ) || ( labelInQuestion == freesurfer_Brain_Stem ) ); return !isWhite; } bool mitk::ConnectomicsNetworkCreator::IsBackgroundLabel( int labelInQuestion ) { bool isBackground( false ); isBackground = ( labelInQuestion == 0 ); return isBackground; } void mitk::ConnectomicsNetworkCreator::LinearExtensionUntilGreyMatter( std::vector & indexVectorOfPointsToUse, TractType::Pointer singleTract, int & label, mitk::Index3D & mitkIndex ) { if( indexVectorOfPointsToUse.size() > singleTract->Size() ) { MBI_WARN << mitk::ConnectomicsConstantsManager::CONNECTOMICS_WARNING_MORE_POINTS_THAN_PRESENT; return; } if( indexVectorOfPointsToUse.size() < 2 ) { MBI_WARN << mitk::ConnectomicsConstantsManager::CONNECTOMICS_WARNING_ESTIMATING_LESS_THAN_2; return; } for( int index( 0 ); index < indexVectorOfPointsToUse.size(); index++ ) { if( indexVectorOfPointsToUse[ index ] > singleTract->Size() ) { MBI_WARN << mitk::ConnectomicsConstantsManager::CONNECTOMICS_WARNING_ESTIMATING_BEYOND_END; return; } if( indexVectorOfPointsToUse[ index ] < 0 ) { MBI_WARN << mitk::ConnectomicsConstantsManager::CONNECTOMICS_WARNING_ESTIMATING_BEYOND_START; return; } } mitk::Point3D startPoint, endPoint; std::vector< double > differenceVector; differenceVector.resize( singleTract->front().Size() ); { // which points to use, currently only last two //TODO correct using all points int endPointIndex = indexVectorOfPointsToUse.size() - 1; int startPointIndex = indexVectorOfPointsToUse.size() - 2; // convert to segmentation coords mitk::Point3D startFiber, endFiber; for( int index = 0; index < singleTract->front().Size(); index++ ) { endFiber.SetElement( index, singleTract->GetElement( indexVectorOfPointsToUse[ endPointIndex ] ).GetElement( index ) ); startFiber.SetElement( index, singleTract->GetElement( indexVectorOfPointsToUse[ startPointIndex ] ).GetElement( index ) ); } FiberToSegmentationCoords( endFiber, endPoint ); FiberToSegmentationCoords( startFiber, startPoint ); // calculate straight line for( int index = 0; index < singleTract->front().Size(); index++ ) { differenceVector[ index ] = endPoint.GetElement( index ) - startPoint.GetElement( index ); } // normalizing direction vector double length( 0.0 ); double sum( 0.0 ); for( int index = 0; index < differenceVector.size() ; index++ ) { sum = sum + differenceVector[ index ] * differenceVector[ index ]; } length = std::sqrt( sum ); for( int index = 0; index < differenceVector.size() ; index++ ) { differenceVector[ index ] = differenceVector[ index ] / length; } // follow line until first non white matter label mitk::Index3D tempIndex; int tempLabel( label ); bool keepOn( true ); for( int parameter( 0 ) ; keepOn ; parameter++ ) { if( parameter > 1000 ) { MBI_WARN << mitk::ConnectomicsConstantsManager::CONNECTOMICS_WARNING_DID_NOT_FIND_WHITE; break; } for( int index( 0 ); index < 3; index++ ) { tempIndex.SetElement( index, endPoint.GetElement( index ) + parameter * differenceVector[ index ] ); } tempLabel = m_Segmentation->GetPixelValueByIndex( tempIndex ); if( IsNonWhiteMatterLabel( tempLabel ) ) { if( tempLabel < 1 ) { keepOn = false; //MBI_WARN << mitk::ConnectomicsConstantsManager::CONNECTOMICS_WARNING_NOT_EXTEND_TO_WHITE; } else { label = tempLabel; mitkIndex = tempIndex; keepOn = false; } } } } } void mitk::ConnectomicsNetworkCreator::RetractionUntilBrainMatter( bool retractFront, TractType::Pointer singleTract, int & label, mitk::Index3D & mitkIndex ) { int retractionStartIndex( singleTract->Size() - 1 ); int retractionStepIndexSize( -1 ); int retractionTerminationIndex( 0 ); if( retractFront ) { retractionStartIndex = 0; retractionStepIndexSize = 1; retractionTerminationIndex = singleTract->Size() - 1; } int currentRetractionIndex = retractionStartIndex; bool keepRetracting( true ); mitk::Point3D currentPoint, nextPoint; std::vector< double > differenceVector; differenceVector.resize( singleTract->front().Size() ); while( keepRetracting && ( currentRetractionIndex != retractionTerminationIndex ) ) { // convert to segmentation coords mitk::Point3D currentPointFiberCoord, nextPointFiberCoord; for( int index = 0; index < singleTract->front().Size(); index++ ) { currentPointFiberCoord.SetElement( index, singleTract->GetElement( currentRetractionIndex ).GetElement( index ) ); nextPointFiberCoord.SetElement( index, singleTract->GetElement( currentRetractionIndex + retractionStepIndexSize ).GetElement( index ) ); } FiberToSegmentationCoords( currentPointFiberCoord, currentPoint ); FiberToSegmentationCoords( nextPointFiberCoord, nextPoint ); // calculate straight line for( int index = 0; index < singleTract->front().Size(); index++ ) { differenceVector[ index ] = nextPoint.GetElement( index ) - currentPoint.GetElement( index ); } // calculate length of direction vector double length( 0.0 ); double sum( 0.0 ); for( int index = 0; index < differenceVector.size() ; index++ ) { sum = sum + differenceVector[ index ] * differenceVector[ index ]; } length = std::sqrt( sum ); - if( length < mitk::eps ) - { - continue; - } - // retract mitk::Index3D tempIndex; int tempLabel( label ); for( int parameter( 0 ) ; parameter < length ; parameter++ ) { for( int index( 0 ); index < 3; index++ ) { tempIndex.SetElement( index, currentPoint.GetElement( index ) + ( 1.0 + parameter ) / ( 1.0 + length ) * differenceVector[ index ] ); } tempLabel = m_Segmentation->GetPixelValueByIndex( tempIndex ); if( !IsBackgroundLabel( tempLabel ) ) { // check whether result is within the search space { mitk::Point3D endPoint, foundPointSegmentation, foundPointFiber; for( int index = 0; index < singleTract->front().Size(); index++ ) { // this is in fiber (world) coordinates endPoint.SetElement( index, singleTract->GetElement( retractionStartIndex ).GetElement( index ) ); } for( int index( 0 ); index < 3; index++ ) { foundPointSegmentation.SetElement( index, currentPoint.GetElement( index ) + ( 1.0 + parameter ) / ( 1.0 + length ) * differenceVector[ index ] ); } SegmentationToFiberCoords( foundPointSegmentation, foundPointFiber ); std::vector< double > finalDistance; finalDistance.resize( singleTract->front().Size() ); for( int index = 0; index < singleTract->front().Size(); index++ ) { finalDistance[ index ] = foundPointFiber.GetElement( index ) - endPoint.GetElement( index ); } // calculate length of direction vector double finalLength( 0.0 ); double finalSum( 0.0 ); for( int index = 0; index < finalDistance.size() ; index++ ) { finalSum = finalSum + finalDistance[ index ] * finalDistance[ index ]; } finalLength = std::sqrt( finalSum ); if( finalLength > m_EndPointSearchRadius ) { // the found point was not within the search space return; } } label = tempLabel; mitkIndex = tempIndex; return; } // hit next point without finding brain matter currentRetractionIndex = currentRetractionIndex + retractionStepIndexSize; if( ( currentRetractionIndex < 1 ) || ( currentRetractionIndex > ( singleTract->Size() - 2 ) ) ) { keepRetracting = false; } } } } void mitk::ConnectomicsNetworkCreator::CalculateCenterOfMass() { const int dimensions = 3; typedef itk::Image ITKImageType; ITKImageType::Pointer itkImage = ITKImageType::New(); mitk::CastToItkImage( m_Segmentation, itkImage ); int max = m_Segmentation->GetStatistics()->GetScalarValueMax(); int min = m_Segmentation->GetStatistics()->GetScalarValueMin(); int range = max - min +1; // each label owns a vector of coordinates std::vector< std::vector< std::vector< double> > > coordinatesPerLabelVector; coordinatesPerLabelVector.resize( range ); itk::ImageRegionIteratorWithIndex it_itkImage( itkImage, itkImage->GetLargestPossibleRegion() ); for( it_itkImage.GoToBegin(); !it_itkImage.IsAtEnd(); ++it_itkImage ) { std::vector< double > coordinates; coordinates.resize(dimensions); itk::Index< dimensions > index = it_itkImage.GetIndex(); for( int loop(0); loop < dimensions; loop++) { coordinates.at( loop ) = index.GetElement( loop ); } // add the coordinates to the corresponding label vector coordinatesPerLabelVector.at( it_itkImage.Value() - min ).push_back( coordinates ); } for(int currentIndex(0), currentLabel( min ); currentIndex < range; currentIndex++, currentLabel++ ) { std::vector< double > currentCoordinates; currentCoordinates.resize(dimensions); int numberOfPoints = coordinatesPerLabelVector.at( currentIndex ).size(); std::vector< double > sumCoords; sumCoords.resize( dimensions ); for( int loop(0); loop < numberOfPoints; loop++ ) { for( int loopDimension( 0 ); loopDimension < dimensions; loopDimension++ ) { sumCoords.at( loopDimension ) += coordinatesPerLabelVector.at( currentIndex ).at( loop ).at( loopDimension ); } } for( int loopDimension( 0 ); loopDimension < dimensions; loopDimension++ ) { currentCoordinates.at( loopDimension ) = sumCoords.at( loopDimension ) / numberOfPoints; } m_LabelsToCoordinatesMap.insert( std::pair< int, std::vector >( currentLabel, currentCoordinates ) ); - - // Peter Hack - { - CreateNewNode( currentLabel, mitk::Index3D(), true ); - if( ! ( m_LabelToVertexMap.count( currentLabel ) > 0 ) ) - { - VertexType newVertex = m_ConNetwork->AddVertex( idCounter ); - idCounter++; - SupplyVertexWithInformation(currentLabel, newVertex); - m_LabelToVertexMap.insert( std::pair< ImageLabelType, VertexType >( currentLabel, newVertex ) ); - } - } } //can now use center of mass coordinates m_UseCoMCoordinates = true; } std::vector< double > mitk::ConnectomicsNetworkCreator::GetCenterOfMass( int label ) { // if label is not known, warn if( ! ( m_LabelsToCoordinatesMap.count( label ) > 0 ) ) { MITK_ERROR << "Label " << label << " not found. Could not return coordinates."; std::vector< double > nullVector; nullVector.resize(3); return nullVector; } //return associated coordinates return m_LabelsToCoordinatesMap.find( label )->second; } void mitk::ConnectomicsNetworkCreator::CreateNewNode( int label, mitk::Index3D index, bool useCoM ) { // Only create node if it does not exist yet if( ! ( m_LabelToNodePropertyMap.count( label ) > 0 ) ) { NetworkNode newNode; newNode.coordinates.resize( 3 ); if( !useCoM ) { for( unsigned int loop = 0; loop < newNode.coordinates.size() ; loop++ ) { newNode.coordinates[ loop ] = index[ loop ] ; } } else { std::vector labelCoords = GetCenterOfMass( label ); for( unsigned int loop = 0; loop < newNode.coordinates.size() ; loop++ ) { newNode.coordinates[ loop ] = labelCoords.at( loop ) ; } } newNode.label = LabelToString( label ); m_LabelToNodePropertyMap.insert( std::pair< ImageLabelType, NetworkNode >( label, newNode ) ); } } diff --git a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/Connectomics/QmitkConnectomicsDataView.cpp b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/Connectomics/QmitkConnectomicsDataView.cpp old mode 100755 new mode 100644 index 4d83a87d16..d089e8f2ee --- a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/Connectomics/QmitkConnectomicsDataView.cpp +++ b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/Connectomics/QmitkConnectomicsDataView.cpp @@ -1,388 +1,392 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // ####### Blueberry includes ####### #include #include // ####### Qmitk includes ####### #include "QmitkConnectomicsDataView.h" #include "QmitkStdMultiWidget.h" // ####### Qt includes ####### #include // ####### ITK includes ####### #include // ####### MITK includes ####### #include #include "mitkConnectomicsSyntheticNetworkGenerator.h" #include "mitkConnectomicsSimulatedAnnealingManager.h" #include "mitkConnectomicsSimulatedAnnealingPermutationModularity.h" #include "mitkConnectomicsSimulatedAnnealingCostFunctionModularity.h" //#include // Includes for image casting between ITK and MITK #include "mitkImageCast.h" #include "mitkITKImageImport.h" #include "mitkImageAccessByItk.h" -#include const std::string QmitkConnectomicsDataView::VIEW_ID = "org.mitk.views.connectomicsdata"; QmitkConnectomicsDataView::QmitkConnectomicsDataView() - : QmitkFunctionality() - , m_Controls( 0 ) - , m_MultiWidget( NULL ) - , m_ConnectomicsNetworkCreator( mitk::ConnectomicsNetworkCreator::New() ) - , m_demomode( false ) - , m_currentIndex( 0 ) +: QmitkFunctionality() +, m_Controls( 0 ) +, m_MultiWidget( NULL ) +, m_ConnectomicsNetworkCreator( mitk::ConnectomicsNetworkCreator::New() ) +, m_demomode( false ) +, m_currentIndex( 0 ) { } QmitkConnectomicsDataView::~QmitkConnectomicsDataView() { } void QmitkConnectomicsDataView::CreateQtPartControl( QWidget *parent ) { - // build up qt view, unless already done - if ( !m_Controls ) - { - // create GUI widgets from the Qt Designer's .ui file - m_Controls = new Ui::QmitkConnectomicsDataViewControls; - m_Controls->setupUi( parent ); - - QObject::connect( m_Controls->networkifyPushButton, SIGNAL(clicked()), this, SLOT(OnNetworkifyPushButtonClicked()) ); - QObject::connect( m_Controls->syntheticNetworkCreationPushButton, SIGNAL(clicked()), this, SLOT(OnSyntheticNetworkCreationPushButtonClicked()) ); - QObject::connect( (QObject*)( m_Controls->syntheticNetworkComboBox ), SIGNAL(currentIndexChanged (int)), this, SLOT(OnSyntheticNetworkComboBoxCurrentIndexChanged(int)) ); - } - - // GUI is different for developer and demo mode - m_demomode = true; - if( m_demomode ) - { - this->m_Controls->networkifyPushButton->show(); - this->m_Controls->networkifyPushButton->setText( "Create Network" ); - this->m_Controls->syntheticNetworkOptionsGroupBox->show(); - //--------------------------- fill comboBox--------------------------- - this->m_Controls->syntheticNetworkComboBox->insertItem(0,"Regular lattice"); - this->m_Controls->syntheticNetworkComboBox->insertItem(1,"Heterogenic sphere"); - this->m_Controls->syntheticNetworkComboBox->insertItem(2,"Random network"); - } - else - { - this->m_Controls->networkifyPushButton->show(); - this->m_Controls->networkifyPushButton->setText( "Networkify" ); - this->m_Controls->syntheticNetworkOptionsGroupBox->show(); - //--------------------------- fill comboBox--------------------------- - this->m_Controls->syntheticNetworkComboBox->insertItem(0,"Regular lattice"); - this->m_Controls->syntheticNetworkComboBox->insertItem(1,"Heterogenic sphere"); - this->m_Controls->syntheticNetworkComboBox->insertItem(2,"Random network"); - this->m_Controls->syntheticNetworkComboBox->insertItem(3,"Scale free network"); - this->m_Controls->syntheticNetworkComboBox->insertItem(4,"Small world network"); - } - - this->WipeDisplay(); + // build up qt view, unless already done + if ( !m_Controls ) + { + // create GUI widgets from the Qt Designer's .ui file + m_Controls = new Ui::QmitkConnectomicsDataViewControls; + m_Controls->setupUi( parent ); + + QObject::connect( m_Controls->networkifyPushButton, SIGNAL(clicked()), this, SLOT(OnNetworkifyPushButtonClicked()) ); + QObject::connect( m_Controls->syntheticNetworkCreationPushButton, SIGNAL(clicked()), this, SLOT(OnSyntheticNetworkCreationPushButtonClicked()) ); + QObject::connect( (QObject*)( m_Controls->syntheticNetworkComboBox ), SIGNAL(currentIndexChanged (int)), this, SLOT(OnSyntheticNetworkComboBoxCurrentIndexChanged(int)) ); + } + + // GUI is different for developer and demo mode + m_demomode = true; + if( m_demomode ) + { + this->m_Controls->networkifyPushButton->show(); + this->m_Controls->networkifyPushButton->setText( "Create Network" ); + this->m_Controls->syntheticNetworkOptionsGroupBox->show(); + //--------------------------- fill comboBox--------------------------- + this->m_Controls->syntheticNetworkComboBox->insertItem(0,"Regular lattice"); + this->m_Controls->syntheticNetworkComboBox->insertItem(1,"Heterogenic sphere"); + this->m_Controls->syntheticNetworkComboBox->insertItem(2,"Random network"); + } + else + { + this->m_Controls->networkifyPushButton->show(); + this->m_Controls->networkifyPushButton->setText( "Networkify" ); + this->m_Controls->syntheticNetworkOptionsGroupBox->show(); + //--------------------------- fill comboBox--------------------------- + this->m_Controls->syntheticNetworkComboBox->insertItem(0,"Regular lattice"); + this->m_Controls->syntheticNetworkComboBox->insertItem(1,"Heterogenic sphere"); + this->m_Controls->syntheticNetworkComboBox->insertItem(2,"Random network"); + this->m_Controls->syntheticNetworkComboBox->insertItem(3,"Scale free network"); + this->m_Controls->syntheticNetworkComboBox->insertItem(4,"Small world network"); + } + + this->WipeDisplay(); } void QmitkConnectomicsDataView::StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget) { - m_MultiWidget = &stdMultiWidget; + m_MultiWidget = &stdMultiWidget; } void QmitkConnectomicsDataView::StdMultiWidgetNotAvailable() { - m_MultiWidget = NULL; + m_MultiWidget = NULL; } void QmitkConnectomicsDataView::WipeDisplay() { - m_Controls->lblWarning->setVisible( true ); - m_Controls->inputImageOneNameLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH ); - m_Controls->inputImageOneNameLabel->setVisible( false ); - m_Controls->inputImageOneLabel->setVisible( false ); - m_Controls->inputImageTwoNameLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH ); - m_Controls->inputImageTwoNameLabel->setVisible( false ); - m_Controls->inputImageTwoLabel->setVisible( false ); + m_Controls->lblWarning->setVisible( true ); + m_Controls->inputImageOneNameLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH ); + m_Controls->inputImageOneNameLabel->setVisible( false ); + m_Controls->inputImageOneLabel->setVisible( false ); + m_Controls->inputImageTwoNameLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH ); + m_Controls->inputImageTwoNameLabel->setVisible( false ); + m_Controls->inputImageTwoLabel->setVisible( false ); } void QmitkConnectomicsDataView::OnSelectionChanged( std::vector nodes ) { - this->WipeDisplay(); - - // Valid options are either - // 1 image (parcellation) - // - // 1 image (parcellation) - // 1 fiber bundle - // - // 1 network - if( nodes.size() < 2 ) + this->WipeDisplay(); + + // Valid options are either + // 1 image (parcellation) + // + // 1 image (parcellation) + // 1 fiber bundle + // + // 1 network + if( nodes.size() > 2 ) + { + return; + } + + bool alreadyFiberBundleSelected( false ), alreadyImageSelected( false ), currentFormatUnknown( true ); + // iterate all selected objects, adjust warning visibility + for( std::vector::iterator it = nodes.begin(); + it != nodes.end(); + ++it ) + { + mitk::DataNode::Pointer node = *it; + currentFormatUnknown = true; + + if( node.IsNotNull() && dynamic_cast(node->GetData()) ) { + currentFormatUnknown = false; + if( alreadyImageSelected ) + { + this->WipeDisplay(); return; + } + alreadyImageSelected = true; + m_Controls->lblWarning->setVisible( false ); + m_Controls->inputImageOneNameLabel->setText(node->GetName().c_str()); + m_Controls->inputImageOneNameLabel->setVisible( true ); + m_Controls->inputImageOneLabel->setVisible( true ); } - m_SelectedParcellationImage = NULL; - m_SelectedFiberBundles.clear(); - - bool alreadyImageSelected( false ), currentFormatUnknown( true ); - // iterate all selected objects, adjust warning visibility - for( std::vector::iterator it = nodes.begin(); - it != nodes.end(); - ++it ) + if( node.IsNotNull() && dynamic_cast(node->GetData()) ) { - mitk::DataNode::Pointer node = *it; - currentFormatUnknown = true; + currentFormatUnknown = false; + // a fiber bundle has to be in conjunction with a parcellation + if( nodes.size() != 2 || alreadyFiberBundleSelected ) + { + this->WipeDisplay(); + return; + } + alreadyFiberBundleSelected = true; + m_Controls->lblWarning->setVisible( false ); + m_Controls->inputImageTwoNameLabel->setText(node->GetName().c_str()); + m_Controls->inputImageTwoNameLabel->setVisible( true ); + m_Controls->inputImageTwoLabel->setVisible( true ); + } - if( node.IsNotNull() && dynamic_cast(node->GetData()) ) + { // network section + mitk::ConnectomicsNetwork* network = dynamic_cast( node->GetData() ); + if( node.IsNotNull() && network ) + { + currentFormatUnknown = false; + if( nodes.size() != 1 ) { - currentFormatUnknown = false; - if( alreadyImageSelected ) - { - this->WipeDisplay(); - return; - } - - m_SelectedParcellationImage = node; - - alreadyImageSelected = true; - m_Controls->lblWarning->setVisible( false ); - m_Controls->inputImageOneNameLabel->setText(node->GetName().c_str()); - m_Controls->inputImageOneNameLabel->setVisible( true ); - m_Controls->inputImageOneLabel->setVisible( true ); + // only valid option is a single network + this->WipeDisplay(); + return; } + m_Controls->lblWarning->setVisible( false ); + m_Controls->inputImageOneNameLabel->setText(node->GetName().c_str()); + m_Controls->inputImageOneNameLabel->setVisible( true ); + m_Controls->inputImageOneLabel->setVisible( true ); - if( node.IsNotNull() && dynamic_cast(node->GetData()) ) - { - currentFormatUnknown = false; - // a fiber bundle has to be in conjunction with a parcellation - if( nodes.size() < 2 ) - { - this->WipeDisplay(); - return; - } - - m_SelectedFiberBundles.push_back(node); - m_Controls->lblWarning->setVisible( false ); - m_Controls->inputImageTwoNameLabel->setText(node->GetName().c_str()); - m_Controls->inputImageTwoNameLabel->setVisible( true ); - m_Controls->inputImageTwoLabel->setVisible( true ); - } + } + } // end network section - { // network section - mitk::ConnectomicsNetwork* network = dynamic_cast( node->GetData() ); - if( node.IsNotNull() && network ) - { - currentFormatUnknown = false; - if( nodes.size() != 1 ) - { - // only valid option is a single network - this->WipeDisplay(); - return; - } - m_Controls->lblWarning->setVisible( false ); - m_Controls->inputImageOneNameLabel->setText(node->GetName().c_str()); - m_Controls->inputImageOneNameLabel->setVisible( true ); - m_Controls->inputImageOneLabel->setVisible( true ); - - } - } // end network section - - if ( currentFormatUnknown ) - { - this->WipeDisplay(); - return; - } - } // end for loop + if ( currentFormatUnknown ) + { + this->WipeDisplay(); + return; + } + } // end for loop } void QmitkConnectomicsDataView::OnSyntheticNetworkComboBoxCurrentIndexChanged(int currentIndex) { - m_currentIndex = currentIndex; + m_currentIndex = currentIndex; switch (m_currentIndex) { - case 0: - this->m_Controls->parameterOneLabel->setText( "Nodes per side" ); - this->m_Controls->parameterTwoLabel->setText( "Internode distance" ); - this->m_Controls->parameterOneSpinBox->setEnabled( true ); - this->m_Controls->parameterOneSpinBox->setValue( 5 ); - this->m_Controls->parameterTwoDoubleSpinBox->setEnabled( true ); - this->m_Controls->parameterTwoDoubleSpinBox->setMaximum( 999.999 ); - this->m_Controls->parameterTwoDoubleSpinBox->setValue( 10.0 ); - break; - case 1: - this->m_Controls->parameterOneLabel->setText( "Number of nodes" ); - this->m_Controls->parameterTwoLabel->setText( "Radius" ); - this->m_Controls->parameterOneSpinBox->setEnabled( true ); - this->m_Controls->parameterOneSpinBox->setValue( 1000 ); - this->m_Controls->parameterTwoDoubleSpinBox->setEnabled( true ); - this->m_Controls->parameterTwoDoubleSpinBox->setMaximum( 999.999 ); - this->m_Controls->parameterTwoDoubleSpinBox->setValue( 50.0 ); - break; - case 2: - this->m_Controls->parameterOneLabel->setText( "Number of nodes" ); - this->m_Controls->parameterTwoLabel->setText( "Edge percentage" ); - this->m_Controls->parameterOneSpinBox->setEnabled( true ); - this->m_Controls->parameterOneSpinBox->setValue( 100 ); - this->m_Controls->parameterTwoDoubleSpinBox->setEnabled( true ); - this->m_Controls->parameterTwoDoubleSpinBox->setMaximum( 1.0 ); - this->m_Controls->parameterTwoDoubleSpinBox->setValue( 0.5 ); - break; - case 3: - //GenerateSyntheticScaleFreeNetwork( network, 1000 ); - break; - case 4: - //GenerateSyntheticSmallWorldNetwork( network, 1000 ); - break; - default: - this->m_Controls->parameterOneLabel->setText( "Parameter 1" ); - this->m_Controls->parameterTwoLabel->setText( "Paramater 2" ); - this->m_Controls->parameterOneSpinBox->setEnabled( false ); - this->m_Controls->parameterOneSpinBox->setValue( 0 ); - this->m_Controls->parameterTwoDoubleSpinBox->setEnabled( false ); - this->m_Controls->parameterTwoDoubleSpinBox->setValue( 0.0 ); + case 0: + this->m_Controls->parameterOneLabel->setText( "Nodes per side" ); + this->m_Controls->parameterTwoLabel->setText( "Internode distance" ); + this->m_Controls->parameterOneSpinBox->setEnabled( true ); + this->m_Controls->parameterOneSpinBox->setValue( 5 ); + this->m_Controls->parameterTwoDoubleSpinBox->setEnabled( true ); + this->m_Controls->parameterTwoDoubleSpinBox->setMaximum( 999.999 ); + this->m_Controls->parameterTwoDoubleSpinBox->setValue( 10.0 ); + break; + case 1: + this->m_Controls->parameterOneLabel->setText( "Number of nodes" ); + this->m_Controls->parameterTwoLabel->setText( "Radius" ); + this->m_Controls->parameterOneSpinBox->setEnabled( true ); + this->m_Controls->parameterOneSpinBox->setValue( 1000 ); + this->m_Controls->parameterTwoDoubleSpinBox->setEnabled( true ); + this->m_Controls->parameterTwoDoubleSpinBox->setMaximum( 999.999 ); + this->m_Controls->parameterTwoDoubleSpinBox->setValue( 50.0 ); + break; + case 2: + this->m_Controls->parameterOneLabel->setText( "Number of nodes" ); + this->m_Controls->parameterTwoLabel->setText( "Edge percentage" ); + this->m_Controls->parameterOneSpinBox->setEnabled( true ); + this->m_Controls->parameterOneSpinBox->setValue( 100 ); + this->m_Controls->parameterTwoDoubleSpinBox->setEnabled( true ); + this->m_Controls->parameterTwoDoubleSpinBox->setMaximum( 1.0 ); + this->m_Controls->parameterTwoDoubleSpinBox->setValue( 0.5 ); + break; + case 3: + //GenerateSyntheticScaleFreeNetwork( network, 1000 ); + break; + case 4: + //GenerateSyntheticSmallWorldNetwork( network, 1000 ); + break; + default: + this->m_Controls->parameterOneLabel->setText( "Parameter 1" ); + this->m_Controls->parameterTwoLabel->setText( "Paramater 2" ); + this->m_Controls->parameterOneSpinBox->setEnabled( false ); + this->m_Controls->parameterOneSpinBox->setValue( 0 ); + this->m_Controls->parameterTwoDoubleSpinBox->setEnabled( false ); + this->m_Controls->parameterTwoDoubleSpinBox->setValue( 0.0 ); } } void QmitkConnectomicsDataView::OnSyntheticNetworkCreationPushButtonClicked() { - // warn if trying to create a very big network - // big network is a network with > 5000 nodes (estimate) - // this might fill up the memory to the point it freezes - int numberOfNodes( 0 ); - switch (m_currentIndex) { - case 0: - numberOfNodes = this->m_Controls->parameterOneSpinBox->value() - * this->m_Controls->parameterOneSpinBox->value() - * this->m_Controls->parameterOneSpinBox->value(); - break; - case 1: - numberOfNodes = this->m_Controls->parameterOneSpinBox->value(); - break; - case 2: - numberOfNodes = this->m_Controls->parameterOneSpinBox->value(); - break; - case 3: - // not implemented yet - break; - case 4: - // not implemented yet - break; - default: - break; - - } - - if( numberOfNodes > 5000 ) - { - QMessageBox msgBox; - msgBox.setText("Trying to generate very large network."); - msgBox.setIcon( QMessageBox::Warning ); - msgBox.setInformativeText("You are trying to generate a network with more than 5000 nodes, this is very resource intensive and might lead to program instability. Proceed with network generation?"); - msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); - msgBox.setDefaultButton(QMessageBox::No); - int ret = msgBox.exec(); - - switch (ret) { - case QMessageBox::Yes: - // continue - break; - case QMessageBox::No: - // stop - return; - break; - - default: - // should never be reached - break; - } - } - - // proceed - mitk::ConnectomicsSyntheticNetworkGenerator::Pointer generator = mitk::ConnectomicsSyntheticNetworkGenerator::New(); + // warn if trying to create a very big network + // big network is a network with > 5000 nodes (estimate) + // this might fill up the memory to the point it freezes + int numberOfNodes( 0 ); + switch (m_currentIndex) { + case 0: + numberOfNodes = this->m_Controls->parameterOneSpinBox->value() + * this->m_Controls->parameterOneSpinBox->value() + * this->m_Controls->parameterOneSpinBox->value(); + break; + case 1: + numberOfNodes = this->m_Controls->parameterOneSpinBox->value(); + break; + case 2: + numberOfNodes = this->m_Controls->parameterOneSpinBox->value(); + break; + case 3: + // not implemented yet + break; + case 4: + // not implemented yet + break; + default: + break; + + } + + if( numberOfNodes > 5000 ) + { + QMessageBox msgBox; + msgBox.setText("Trying to generate very large network."); + msgBox.setIcon( QMessageBox::Warning ); + msgBox.setInformativeText("You are trying to generate a network with more than 5000 nodes, this is very resource intensive and might lead to program instability. Proceed with network generation?"); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::No); + int ret = msgBox.exec(); + + switch (ret) { + case QMessageBox::Yes: + // continue + break; + case QMessageBox::No: + // stop + return; + break; - mitk::DataNode::Pointer networkNode = mitk::DataNode::New(); - int parameterOne = this->m_Controls->parameterOneSpinBox->value(); - double parameterTwo = this->m_Controls->parameterTwoDoubleSpinBox->value(); - //add network to datastorage - networkNode->SetData( generator->CreateSyntheticNetwork( m_currentIndex, parameterOne, parameterTwo ) ); - networkNode->SetName( mitk::ConnectomicsConstantsManager::CONNECTOMICS_PROPERTY_DEFAULT_CNF_NAME ); - if( generator->WasGenerationSuccessfull() ) - { - this->GetDefaultDataStorage()->Add( networkNode ); - } - else - { - MITK_WARN << "Problem occured during synthetic network generation."; + default: + // should never be reached + break; } - - return; + } + + // proceed + mitk::ConnectomicsSyntheticNetworkGenerator::Pointer generator = mitk::ConnectomicsSyntheticNetworkGenerator::New(); + + mitk::DataNode::Pointer networkNode = mitk::DataNode::New(); + int parameterOne = this->m_Controls->parameterOneSpinBox->value(); + double parameterTwo = this->m_Controls->parameterTwoDoubleSpinBox->value(); + //add network to datastorage + networkNode->SetData( generator->CreateSyntheticNetwork( m_currentIndex, parameterOne, parameterTwo ) ); + networkNode->SetName( mitk::ConnectomicsConstantsManager::CONNECTOMICS_PROPERTY_DEFAULT_CNF_NAME ); + if( generator->WasGenerationSuccessfull() ) + { + this->GetDefaultDataStorage()->Add( networkNode ); + } + else + { + MITK_WARN << "Problem occured during synthetic network generation."; + } + + return; } -#include - void QmitkConnectomicsDataView::OnNetworkifyPushButtonClicked() { - if ( m_SelectedParcellationImage.IsNull() || m_SelectedFiberBundles.empty() ) - { - QMessageBox::information( NULL, mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_CONNECTOMICS_CREATION, mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_SELECTION_WARNING); - return; - } - - mitk::Image::Pointer image = dynamic_cast< mitk::Image* >(m_SelectedParcellationImage->GetData()); - for (int i=0; i( m_SelectedFiberBundles.at(i)->GetData() ); - - m_ConnectomicsNetworkCreator= mitk::ConnectomicsNetworkCreator::New(); - m_ConnectomicsNetworkCreator->SetSegmentation( image ); - m_ConnectomicsNetworkCreator->SetFiberBundle( fiberBundle ); - m_ConnectomicsNetworkCreator->CalculateCenterOfMass(); - m_ConnectomicsNetworkCreator->SetEndPointSearchRadius( 15 ); - m_ConnectomicsNetworkCreator->CreateNetworkFromFibersAndSegmentation(); - mitk::DataNode::Pointer networkNode = mitk::DataNode::New(); + std::vector nodes = this->GetDataManagerSelection(); + if ( nodes.empty() ) + { + QMessageBox::information( NULL, mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_CONNECTOMICS_CREATION, mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_SELECTION_WARNING); + return; + } + if (! ( nodes.size() == 2 ) ) + { + QMessageBox::information( NULL, mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_CONNECTOMICS_CREATION, mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_SELECTION_WARNING); + return; + } + mitk::DataNode* firstNode = nodes.front(); + mitk::DataNode* secondNode = nodes.at(1); + + if (!firstNode) + { + // Nothing selected. Inform the user and return + QMessageBox::information( NULL, mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_CONNECTOMICS_CREATION, mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_SELECTION_WARNING); + return; + } - //add network to datastorage - QString name("/local/data/Fibercup/connectomics/networks/"); - name += m_SelectedFiberBundles.at(i)->GetName().c_str(); - name += "_Connectome.cnf"; - networkNode->SetData( m_ConnectomicsNetworkCreator->GetNetwork() ); - networkNode->SetName( name.toStdString().c_str() ); + // here we have a valid mitk::DataNode - mitk::ConnectomicsNetwork::Pointer nw = m_ConnectomicsNetworkCreator->GetNetwork(); + // a node itself is not very useful, we need its data item (the image) + mitk::BaseData* firstData = firstNode->GetData(); + mitk::BaseData* secondData = secondNode->GetData(); + if (firstData && secondData) + { + // test if this data item is an image or not (could also be a surface or something totally different) + mitk::Image* image = dynamic_cast( firstData ); + mitk::FiberBundleX* fiberBundle = dynamic_cast( secondData ); - mitk::CoreObjectFactory::FileWriterList fileWriters = mitk::CoreObjectFactory::GetInstance()->GetFileWriters(); - for (mitk::CoreObjectFactory::FileWriterList::iterator it = fileWriters.begin() ; it != fileWriters.end() ; ++it) - { - if ( (*it)->CanWriteBaseDataType(nw.GetPointer()) ) { - MITK_INFO << "writing " << name.toStdString(); - (*it)->SetFileName( name.toStdString().c_str() ); - (*it)->DoWrite( nw.GetPointer() ); - } - } + // check whether order was switched + if (! (image && fiberBundle) ) + { + image = dynamic_cast( secondData ); + fiberBundle = dynamic_cast( firstData ); + } - //this->GetDefaultDataStorage()->Add( networkNode, m_SelectedParcellationImage ); - //mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + if (image && fiberBundle) + { + m_ConnectomicsNetworkCreator->SetSegmentation( image ); + m_ConnectomicsNetworkCreator->SetFiberBundle( fiberBundle ); + m_ConnectomicsNetworkCreator->CalculateCenterOfMass(); + m_ConnectomicsNetworkCreator->SetEndPointSearchRadius( 15 ); + m_ConnectomicsNetworkCreator->CreateNetworkFromFibersAndSegmentation(); + mitk::DataNode::Pointer networkNode = mitk::DataNode::New(); + + //add network to datastorage + networkNode->SetData( m_ConnectomicsNetworkCreator->GetNetwork() ); + networkNode->SetName( mitk::ConnectomicsConstantsManager::CONNECTOMICS_PROPERTY_DEFAULT_CNF_NAME ); + this->GetDefaultDataStorage()->Add( networkNode ); } + } + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } diff --git a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/Connectomics/QmitkConnectomicsDataView.h b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/Connectomics/QmitkConnectomicsDataView.h old mode 100755 new mode 100644 index 6ef3a2d6fd..1e184dff6e --- a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/Connectomics/QmitkConnectomicsDataView.h +++ b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/Connectomics/QmitkConnectomicsDataView.h @@ -1,107 +1,104 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QmitkConnectomicsDataView_h #define QmitkConnectomicsDataView_h #include #include #include "ui_QmitkConnectomicsDataViewControls.h" #include "mitkConnectomicsNetworkCreator.h" #include "mitkConnectomicsNetworkMapper3D.h" // ####### ITK includes ####### #include /*! \brief QmitkConnectomicsDataView This view provides functionality for the generation of networks. Either from parcellation and fiber bundle or synthetically. \sa QmitkFunctionality \ingroup Functionalities */ class QmitkConnectomicsDataView : public QmitkFunctionality { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT public: static const std::string VIEW_ID; QmitkConnectomicsDataView(); virtual ~QmitkConnectomicsDataView(); virtual void CreateQtPartControl(QWidget *parent); virtual void StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget); virtual void StdMultiWidgetNotAvailable(); protected slots: /// \brief Align two images by copying the geometry void OnNetworkifyPushButtonClicked(); /// \brief Create synthetic networks void OnSyntheticNetworkCreationPushButtonClicked(); /// \brief Adjust parameters depending on synthetic network type void OnSyntheticNetworkComboBoxCurrentIndexChanged(int currentIndex); protected: // ####### Functions ####### /// \brief called by QmitkFunctionality when DataManager's selection has changed virtual void OnSelectionChanged( std::vector nodes ); /// \brief Converts an image into a RGBA image template < typename TPixel, unsigned int VImageDimension > void TurnIntoRGBA( itk::Image* inputImage); /// \brief Wipe display and empty statistics void WipeDisplay(); // ####### Variables ####### Ui::QmitkConnectomicsDataViewControls* m_Controls; QmitkStdMultiWidget* m_MultiWidget; - mitk::ConnectomicsNetworkCreator::Pointer m_ConnectomicsNetworkCreator; + mitk::ConnectomicsNetworkCreator::Pointer m_ConnectomicsNetworkCreator; - mitk::ConnectomicsNetworkMapper3D::Pointer m_NetworkMapper; - - mitk::DataNode::Pointer m_SelectedParcellationImage; - std::vector< mitk::DataNode::Pointer > m_SelectedFiberBundles; + mitk::ConnectomicsNetworkMapper3D::Pointer m_NetworkMapper; // Demo/Developer mode toggle bool m_demomode; // The selected synthetic network type int m_currentIndex; }; #endif // _QMITKBRAINNETWORKANALYSISVIEW_H_INCLUDED diff --git a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/Connectomics/QmitkConnectomicsDataViewControls.ui b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/Connectomics/QmitkConnectomicsDataViewControls.ui old mode 100755 new mode 100644 diff --git a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/Connectomics/QmitkConnectomicsNetworkOperationsView.cpp b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/Connectomics/QmitkConnectomicsNetworkOperationsView.cpp old mode 100755 new mode 100644 index d5d585637f..f6528f5b15 --- a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/Connectomics/QmitkConnectomicsNetworkOperationsView.cpp +++ b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/Connectomics/QmitkConnectomicsNetworkOperationsView.cpp @@ -1,507 +1,488 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // ####### Blueberry includes ####### #include #include // ####### Qmitk includes ####### #include "QmitkConnectomicsNetworkOperationsView.h" #include "QmitkStdMultiWidget.h" // ####### Qt includes ####### #include // ####### ITK includes ####### #include // ####### MITK includes ####### #include #include "mitkConnectomicsSimulatedAnnealingManager.h" #include "mitkConnectomicsSimulatedAnnealingPermutationModularity.h" #include "mitkConnectomicsSimulatedAnnealingCostFunctionModularity.h" #include -#include // Includes for image casting between ITK and MITK #include "mitkImageCast.h" #include "mitkITKImageImport.h" #include "mitkImageAccessByItk.h" const std::string QmitkConnectomicsNetworkOperationsView::VIEW_ID = "org.mitk.views.connectomicsnetworkoperations"; QmitkConnectomicsNetworkOperationsView::QmitkConnectomicsNetworkOperationsView() - : QmitkFunctionality() - , m_Controls( 0 ) - , m_MultiWidget( NULL ) - , m_demomode( false ) - , m_currentIndex( 0 ) +: QmitkFunctionality() +, m_Controls( 0 ) +, m_MultiWidget( NULL ) +, m_demomode( false ) +, m_currentIndex( 0 ) { } QmitkConnectomicsNetworkOperationsView::~QmitkConnectomicsNetworkOperationsView() { } void QmitkConnectomicsNetworkOperationsView::CreateQtPartControl( QWidget *parent ) { - // build up qt view, unless already done - if ( !m_Controls ) - { - // create GUI widgets from the Qt Designer's .ui file - m_Controls = new Ui::QmitkConnectomicsNetworkOperationsViewControls; - m_Controls->setupUi( parent ); - - QObject::connect( m_Controls->convertToRGBAImagePushButton, SIGNAL(clicked()), this, SLOT(OnConvertToRGBAImagePushButtonClicked()) ); - QObject::connect( (QObject*)( m_Controls->modularizePushButton ), SIGNAL(clicked()), this, SLOT(OnModularizePushButtonClicked()) ); - QObject::connect( (QObject*)( m_Controls->prunePushButton ), SIGNAL(clicked()), this, SLOT(OnPrunePushButtonClicked()) ); - QObject::connect( (QObject*)( m_Controls->createConnectivityMatrixImagePushButton ), SIGNAL(clicked()), this, SLOT(OnCreateConnectivityMatrixImagePushButtonClicked()) ); - } - - // GUI is different for developer and demo mode - m_demomode = true; - if( m_demomode ) - { - this->m_Controls->convertToRGBAImagePushButton->show(); - this->m_Controls->modularizePushButton->hide(); - this->m_Controls->pruneOptionsGroupBox->hide(); - } - else - { - this->m_Controls->convertToRGBAImagePushButton->show(); - this->m_Controls->modularizePushButton->show(); - this->m_Controls->pruneOptionsGroupBox->show(); - } - - this->WipeDisplay(); + // build up qt view, unless already done + if ( !m_Controls ) + { + // create GUI widgets from the Qt Designer's .ui file + m_Controls = new Ui::QmitkConnectomicsNetworkOperationsViewControls; + m_Controls->setupUi( parent ); + + QObject::connect( m_Controls->convertToRGBAImagePushButton, SIGNAL(clicked()), this, SLOT(OnConvertToRGBAImagePushButtonClicked()) ); + QObject::connect( (QObject*)( m_Controls->modularizePushButton ), SIGNAL(clicked()), this, SLOT(OnModularizePushButtonClicked()) ); + QObject::connect( (QObject*)( m_Controls->prunePushButton ), SIGNAL(clicked()), this, SLOT(OnPrunePushButtonClicked()) ); + QObject::connect( (QObject*)( m_Controls->createConnectivityMatrixImagePushButton ), SIGNAL(clicked()), this, SLOT(OnCreateConnectivityMatrixImagePushButtonClicked()) ); + } + + // GUI is different for developer and demo mode + m_demomode = true; + if( m_demomode ) + { + this->m_Controls->convertToRGBAImagePushButton->show(); + this->m_Controls->modularizePushButton->hide(); + this->m_Controls->pruneOptionsGroupBox->hide(); + } + else + { + this->m_Controls->convertToRGBAImagePushButton->show(); + this->m_Controls->modularizePushButton->show(); + this->m_Controls->pruneOptionsGroupBox->show(); + } + + this->WipeDisplay(); } void QmitkConnectomicsNetworkOperationsView::StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget) { - m_MultiWidget = &stdMultiWidget; + m_MultiWidget = &stdMultiWidget; } void QmitkConnectomicsNetworkOperationsView::StdMultiWidgetNotAvailable() { - m_MultiWidget = NULL; + m_MultiWidget = NULL; } void QmitkConnectomicsNetworkOperationsView::WipeDisplay() { - m_Controls->lblWarning->setVisible( true ); - m_Controls->inputImageOneNameLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH ); - m_Controls->inputImageOneNameLabel->setVisible( false ); - m_Controls->inputImageOneLabel->setVisible( false ); + m_Controls->lblWarning->setVisible( true ); + m_Controls->inputImageOneNameLabel->setText( mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_DASH ); + m_Controls->inputImageOneNameLabel->setVisible( false ); + m_Controls->inputImageOneLabel->setVisible( false ); } void QmitkConnectomicsNetworkOperationsView::OnSelectionChanged( std::vector nodes ) { - this->WipeDisplay(); + this->WipeDisplay(); - // Valid options are either - if( nodes.size() > 2 ) - { - return; - } + // Valid options are either + if( nodes.size() > 2 ) + { + return; + } - bool currentFormatUnknown(true), alreadyImageSelected(false); + bool currentFormatUnknown(true), alreadyImageSelected(false); - // iterate all selected objects, adjust warning visibility - for( std::vector::iterator it = nodes.begin(); - it != nodes.end(); - ++it ) - { - mitk::DataNode::Pointer node = *it; - currentFormatUnknown = true; + // iterate all selected objects, adjust warning visibility + for( std::vector::iterator it = nodes.begin(); + it != nodes.end(); + ++it ) + { + mitk::DataNode::Pointer node = *it; + currentFormatUnknown = true; - if( node.IsNotNull() && dynamic_cast(node->GetData()) ) - { - currentFormatUnknown = false; - if( alreadyImageSelected ) - { - this->WipeDisplay(); - return; - } - alreadyImageSelected = true; - m_Controls->lblWarning->setVisible( false ); - m_Controls->inputImageOneNameLabel->setText(node->GetName().c_str()); - m_Controls->inputImageOneNameLabel->setVisible( true ); - m_Controls->inputImageOneLabel->setVisible( true ); - } + if( node.IsNotNull() && dynamic_cast(node->GetData()) ) + { + currentFormatUnknown = false; + if( alreadyImageSelected ) + { + this->WipeDisplay(); + return; + } + alreadyImageSelected = true; + m_Controls->lblWarning->setVisible( false ); + m_Controls->inputImageOneNameLabel->setText(node->GetName().c_str()); + m_Controls->inputImageOneNameLabel->setVisible( true ); + m_Controls->inputImageOneLabel->setVisible( true ); + } - if( node.IsNotNull() ) - { // network section - mitk::ConnectomicsNetwork* network = dynamic_cast( node->GetData() ); - if( network ) - { - currentFormatUnknown = false; - if( nodes.size() != 1 ) - { - // only valid option is a single network - this->WipeDisplay(); - return; - } - m_Controls->lblWarning->setVisible( false ); - m_Controls->inputImageOneNameLabel->setText(node->GetName().c_str()); - m_Controls->inputImageOneNameLabel->setVisible( true ); - m_Controls->inputImageOneLabel->setVisible( true ); - - } - } // end network section - - if ( currentFormatUnknown ) + if( node.IsNotNull() ) + { // network section + mitk::ConnectomicsNetwork* network = dynamic_cast( node->GetData() ); + if( network ) + { + currentFormatUnknown = false; + if( nodes.size() != 1 ) { - this->WipeDisplay(); - return; + // only valid option is a single network + this->WipeDisplay(); + return; } - } // end for loop -} + m_Controls->lblWarning->setVisible( false ); + m_Controls->inputImageOneNameLabel->setText(node->GetName().c_str()); + m_Controls->inputImageOneNameLabel->setVisible( true ); + m_Controls->inputImageOneLabel->setVisible( true ); -void QmitkConnectomicsNetworkOperationsView::OnConvertToRGBAImagePushButtonClicked() -{ - std::vector nodes = this->GetDataManagerSelection(); - if (nodes.empty()) return; + } + } // end network section - mitk::DataNode* node = nodes.front(); - - if (!node) + if ( currentFormatUnknown ) { - // Nothing selected. Inform the user and return - QMessageBox::information( NULL, mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_CONNECTOMICS, mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_ONLY_PARCELLATION_SELECTION_WARNING); - return; + this->WipeDisplay(); + return; } + } // end for loop +} - // here we have a valid mitk::DataNode - - // a node itself is not very useful, we need its data item (the image) - mitk::BaseData* data = node->GetData(); - if (data) +void QmitkConnectomicsNetworkOperationsView::OnConvertToRGBAImagePushButtonClicked() +{ + std::vector nodes = this->GetDataManagerSelection(); + if (nodes.empty()) return; + + mitk::DataNode* node = nodes.front(); + + if (!node) + { + // Nothing selected. Inform the user and return + QMessageBox::information( NULL, mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_CONNECTOMICS, mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_ONLY_PARCELLATION_SELECTION_WARNING); + return; + } + + // here we have a valid mitk::DataNode + + // a node itself is not very useful, we need its data item (the image) + mitk::BaseData* data = node->GetData(); + if (data) + { + // test if this data item is an image or not (could also be a surface or something totally different) + mitk::Image* image = dynamic_cast( data ); + if (image) { - // test if this data item is an image or not (could also be a surface or something totally different) - mitk::Image* image = dynamic_cast( data ); - if (image) - { - std::stringstream message; - std::string name; - message << mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_PERFORMING_IMAGE_PROCESSING_FOR_IMAGE; - if (node->GetName(name)) - { - // a property called "name" was found for this DataNode - message << "'" << name << "'"; - } - message << "."; - MITK_INFO << message.str(); - - // Convert to RGBA - AccessByItk( image, TurnIntoRGBA ); - this->GetDefaultDataStorage()->GetNamedNode( mitk::ConnectomicsConstantsManager::CONNECTOMICS_PROPERTY_DEFAULT_RGBA_NAME )->GetData()->SetGeometry( node->GetData()->GetGeometry() ); - - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); - } - else - { - QMessageBox::information( NULL, mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_CONNECTOMICS, mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_ONLY_PARCELLATION_SELECTION_WARNING); - return; - } + std::stringstream message; + std::string name; + message << mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_PERFORMING_IMAGE_PROCESSING_FOR_IMAGE; + if (node->GetName(name)) + { + // a property called "name" was found for this DataNode + message << "'" << name << "'"; + } + message << "."; + MITK_INFO << message.str(); + + // Convert to RGBA + AccessByItk( image, TurnIntoRGBA ); + this->GetDefaultDataStorage()->GetNamedNode( mitk::ConnectomicsConstantsManager::CONNECTOMICS_PROPERTY_DEFAULT_RGBA_NAME )->GetData()->SetGeometry( node->GetData()->GetGeometry() ); + + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } else { - QMessageBox::information( NULL, mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_CONNECTOMICS, mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_ONLY_PARCELLATION_SELECTION_WARNING); - return; + QMessageBox::information( NULL, mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_CONNECTOMICS, mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_ONLY_PARCELLATION_SELECTION_WARNING); + return; } + } + else + { + QMessageBox::information( NULL, mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_CONNECTOMICS, mitk::ConnectomicsConstantsManager::CONNECTOMICS_GUI_ONLY_PARCELLATION_SELECTION_WARNING); + return; + } } template < typename TPixel, unsigned int VImageDimension > void QmitkConnectomicsNetworkOperationsView::TurnIntoRGBA( itk::Image* inputImage) { - typedef itk::RGBAPixel< unsigned char > RGBAPixelType; - typedef itk::Image< TPixel, VImageDimension > TemplateImageType; - typedef itk::Image< RGBAPixelType, VImageDimension > RGBAImageType; + typedef itk::RGBAPixel< unsigned char > RGBAPixelType; + typedef itk::Image< TPixel, VImageDimension > TemplateImageType; + typedef itk::Image< RGBAPixelType, VImageDimension > RGBAImageType; - itk::ImageRegionIterator it_inputImage(inputImage, inputImage->GetLargestPossibleRegion()); + itk::ImageRegionIterator it_inputImage(inputImage, inputImage->GetLargestPossibleRegion()); - TPixel minimumValue, maximumValue; + TPixel minimumValue, maximumValue; - it_inputImage.GoToBegin(); - maximumValue = minimumValue = it_inputImage.Value(); + it_inputImage.GoToBegin(); + maximumValue = minimumValue = it_inputImage.Value(); - for(it_inputImage.GoToBegin(); !it_inputImage.IsAtEnd(); ++it_inputImage) + for(it_inputImage.GoToBegin(); !it_inputImage.IsAtEnd(); ++it_inputImage) + { + if ( it_inputImage.Value() < minimumValue ) { - if ( it_inputImage.Value() < minimumValue ) - { - minimumValue = it_inputImage.Value(); - } - else - { - if ( it_inputImage.Value() > maximumValue ) - { - maximumValue = it_inputImage.Value(); - } - } + minimumValue = it_inputImage.Value(); } - - int range = int ( maximumValue - minimumValue ); //needs to be castable to int - int offset = int ( minimumValue ); - - if ( range < 0 ) //error + else { - return; + if ( it_inputImage.Value() > maximumValue ) + { + maximumValue = it_inputImage.Value(); + } } + } - std::vector< unsigned int > histogram; - histogram.resize( range + 1, 0 ); + int range = int ( maximumValue - minimumValue ); //needs to be castable to int + int offset = int ( minimumValue ); - for(it_inputImage.GoToBegin(); !it_inputImage.IsAtEnd(); ++it_inputImage) - { - histogram[ int ( it_inputImage.Value() ) - offset ] += 1; - } + if ( range < 0 ) //error + { + return; + } + + std::vector< unsigned int > histogram; + histogram.resize( range + 1, 0 ); + + for(it_inputImage.GoToBegin(); !it_inputImage.IsAtEnd(); ++it_inputImage) + { + histogram[ int ( it_inputImage.Value() ) - offset ] += 1; + } - int gapCounter = 0; //this variable will be used to count the empty labels + int gapCounter = 0; //this variable will be used to count the empty labels - //stores how much has to be subtracted from the image to remove gaps - std::vector< TPixel > subtractionStorage; - subtractionStorage.resize( range + 1, 0 ); + //stores how much has to be subtracted from the image to remove gaps + std::vector< TPixel > subtractionStorage; + subtractionStorage.resize( range + 1, 0 ); - for( int index = 0; index <= range; index++ ) + for( int index = 0; index <= range; index++ ) + { + if( histogram[ index ] == 0 ) { - if( histogram[ index ] == 0 ) - { - gapCounter++; //if the label is empty, increase gapCounter - } - else - { - subtractionStorage[ index ] = TPixel ( gapCounter ); - } + gapCounter++; //if the label is empty, increase gapCounter } - - //remove gaps from label image - for(it_inputImage.GoToBegin(); !it_inputImage.IsAtEnd(); ++it_inputImage) + else { - it_inputImage.Value() = it_inputImage.Value() - subtractionStorage[int ( it_inputImage.Value() ) - offset ]; + subtractionStorage[ index ] = TPixel ( gapCounter ); } + } - // create colour vector - std::vector< RGBAPixelType > lookupTable; + //remove gaps from label image + for(it_inputImage.GoToBegin(); !it_inputImage.IsAtEnd(); ++it_inputImage) + { + it_inputImage.Value() = it_inputImage.Value() - subtractionStorage[int ( it_inputImage.Value() ) - offset ]; + } + // create colour vector + std::vector< RGBAPixelType > lookupTable; + + { + RGBAPixelType backgroundColour; + for( int elementIndex = 0; elementIndex < 4; ++elementIndex ) { - RGBAPixelType backgroundColour; - for( int elementIndex = 0; elementIndex < 4; ++elementIndex ) - { - backgroundColour.SetElement( elementIndex, 0 ); - } + backgroundColour.SetElement( elementIndex, 0 ); + } - lookupTable.push_back( backgroundColour ); + lookupTable.push_back( backgroundColour ); - for(int colourNumber = 0; colourNumber < range ; ++colourNumber) - { - RGBAPixelType colour; - for( int elementIndex = 0; elementIndex < 3; ++elementIndex ) - { - colour.SetElement( elementIndex, rand() % 256 ); - } - colour.SetAlpha( 255 ); - lookupTable.push_back( colour ); - } + for(int colourNumber = 0; colourNumber < range ; ++colourNumber) + { + RGBAPixelType colour; + for( int elementIndex = 0; elementIndex < 3; ++elementIndex ) + { + colour.SetElement( elementIndex, rand() % 256 ); + } + colour.SetAlpha( 255 ); + lookupTable.push_back( colour ); } + } - // create RGBA image - typename RGBAImageType::Pointer rgbaImage = RGBAImageType::New(); + // create RGBA image + typename RGBAImageType::Pointer rgbaImage = RGBAImageType::New(); - rgbaImage->SetRegions(inputImage->GetLargestPossibleRegion().GetSize()); - rgbaImage->SetSpacing(inputImage->GetSpacing()); - rgbaImage->SetOrigin(inputImage->GetOrigin()); - rgbaImage->Allocate(); + rgbaImage->SetRegions(inputImage->GetLargestPossibleRegion().GetSize()); + rgbaImage->SetSpacing(inputImage->GetSpacing()); + rgbaImage->SetOrigin(inputImage->GetOrigin()); + rgbaImage->Allocate(); - //fill with appropriate colours - itk::ImageRegionIterator it_rgbaImage(rgbaImage, rgbaImage->GetLargestPossibleRegion()); + //fill with appropriate colours + itk::ImageRegionIterator it_rgbaImage(rgbaImage, rgbaImage->GetLargestPossibleRegion()); - for(it_inputImage.GoToBegin(), it_rgbaImage.GoToBegin(); !it_inputImage.IsAtEnd(); ++it_inputImage, ++it_rgbaImage) - { - it_rgbaImage.Value() = lookupTable[ int ( it_inputImage.Value() ) - offset ]; - } + for(it_inputImage.GoToBegin(), it_rgbaImage.GoToBegin(); !it_inputImage.IsAtEnd(); ++it_inputImage, ++it_rgbaImage) + { + it_rgbaImage.Value() = lookupTable[ int ( it_inputImage.Value() ) - offset ]; + } - mitk::Image::Pointer mitkRGBAImage = mitk::ImportItkImage( rgbaImage )->Clone(); + mitk::Image::Pointer mitkRGBAImage = mitk::ImportItkImage( rgbaImage )->Clone(); - mitk::DataNode::Pointer rgbaImageNode = mitk::DataNode::New(); - rgbaImageNode->SetData(mitkRGBAImage); - rgbaImageNode->SetProperty(mitk::ConnectomicsConstantsManager::CONNECTOMICS_PROPERTY_NAME, mitk::StringProperty::New(mitk::ConnectomicsConstantsManager::CONNECTOMICS_PROPERTY_DEFAULT_RGBA_NAME)); - rgbaImageNode->SetBoolProperty( mitk::ConnectomicsConstantsManager::CONNECTOMICS_PROPERTY_VOLUMERENDERING, true); - this->GetDefaultDataStorage()->Add( rgbaImageNode ); + mitk::DataNode::Pointer rgbaImageNode = mitk::DataNode::New(); + rgbaImageNode->SetData(mitkRGBAImage); + rgbaImageNode->SetProperty(mitk::ConnectomicsConstantsManager::CONNECTOMICS_PROPERTY_NAME, mitk::StringProperty::New(mitk::ConnectomicsConstantsManager::CONNECTOMICS_PROPERTY_DEFAULT_RGBA_NAME)); + rgbaImageNode->SetBoolProperty( mitk::ConnectomicsConstantsManager::CONNECTOMICS_PROPERTY_VOLUMERENDERING, true); + this->GetDefaultDataStorage()->Add( rgbaImageNode ); } void QmitkConnectomicsNetworkOperationsView::OnModularizePushButtonClicked() { - std::vector nodes = this->GetDataManagerSelection(); - if ( nodes.empty() ) + std::vector nodes = this->GetDataManagerSelection(); + if ( nodes.empty() ) + { + QMessageBox::information( NULL, "Modularization calculation", "Please select exactly one network."); + return; + } + + for( std::vector::iterator it = nodes.begin(); + it != nodes.end(); + ++it ) + { + mitk::DataNode::Pointer node = *it; + + if( node.IsNotNull() && dynamic_cast(node->GetData()) ) { - QMessageBox::information( NULL, "Modularization calculation", "Please select exactly one network."); - return; + return; } - for( std::vector::iterator it = nodes.begin(); - it != nodes.end(); - ++it ) { - mitk::DataNode::Pointer node = *it; + mitk::ConnectomicsNetwork* network = dynamic_cast( node->GetData() ); + if( node.IsNotNull() && network ) + { - if( node.IsNotNull() && dynamic_cast(node->GetData()) ) - { - return; - } + typedef mitk::ConnectomicsSimulatedAnnealingPermutationModularity::ToModuleMapType MappingType; - { - mitk::ConnectomicsNetwork* network = dynamic_cast( node->GetData() ); - if( node.IsNotNull() && network ) - { - - typedef mitk::ConnectomicsSimulatedAnnealingPermutationModularity::ToModuleMapType MappingType; - - int depthOfModuleRecursive( 2 ); - double startTemperature( 2.0 ); - double stepSize( 4.0 ); + int depthOfModuleRecursive( 2 ); + double startTemperature( 2.0 ); + double stepSize( 4.0 ); - mitk::ConnectomicsNetwork::Pointer connectomicsNetwork( network ); - mitk::ConnectomicsSimulatedAnnealingManager::Pointer manager = mitk::ConnectomicsSimulatedAnnealingManager::New(); - mitk::ConnectomicsSimulatedAnnealingPermutationModularity::Pointer permutation = mitk::ConnectomicsSimulatedAnnealingPermutationModularity::New(); - mitk::ConnectomicsSimulatedAnnealingCostFunctionModularity::Pointer costFunction = mitk::ConnectomicsSimulatedAnnealingCostFunctionModularity::New(); + mitk::ConnectomicsNetwork::Pointer connectomicsNetwork( network ); + mitk::ConnectomicsSimulatedAnnealingManager::Pointer manager = mitk::ConnectomicsSimulatedAnnealingManager::New(); + mitk::ConnectomicsSimulatedAnnealingPermutationModularity::Pointer permutation = mitk::ConnectomicsSimulatedAnnealingPermutationModularity::New(); + mitk::ConnectomicsSimulatedAnnealingCostFunctionModularity::Pointer costFunction = mitk::ConnectomicsSimulatedAnnealingCostFunctionModularity::New(); - permutation->SetCostFunction( costFunction.GetPointer() ); - permutation->SetNetwork( connectomicsNetwork ); - permutation->SetDepth( depthOfModuleRecursive ); - permutation->SetStepSize( stepSize ); + permutation->SetCostFunction( costFunction.GetPointer() ); + permutation->SetNetwork( connectomicsNetwork ); + permutation->SetDepth( depthOfModuleRecursive ); + permutation->SetStepSize( stepSize ); - manager->SetPermutation( permutation.GetPointer() ); + manager->SetPermutation( permutation.GetPointer() ); - manager->RunSimulatedAnnealing( startTemperature, stepSize ); + manager->RunSimulatedAnnealing( startTemperature, stepSize ); - MappingType mapping = permutation->GetMapping(); + MappingType mapping = permutation->GetMapping(); - MappingType::iterator iter = mapping.begin(); - MappingType::iterator end = mapping.end(); + MappingType::iterator iter = mapping.begin(); + MappingType::iterator end = mapping.end(); - int loop( 0 ); - while( iter != end ) - { - MBI_DEBUG << "Vertex " << iter->first << " belongs to module " << iter->second ; - MBI_INFO << "Vertex " << iter->first << " belongs to module " << iter->second ; - iter++; - } + int loop( 0 ); + while( iter != end ) + { + MBI_DEBUG << "Vertex " << iter->first << " belongs to module " << iter->second ; + MBI_INFO << "Vertex " << iter->first << " belongs to module " << iter->second ; + iter++; + } - MBI_DEBUG << "Overall number of modules is " << permutation->getNumberOfModules( &mapping ) ; - MBI_DEBUG << "Cost is " << costFunction->Evaluate( network, &mapping ) ; - MBI_INFO << "Overall number of modules is " << permutation->getNumberOfModules( &mapping ) ; - MBI_INFO << "Cost is " << costFunction->Evaluate( network, &mapping ) ; + MBI_DEBUG << "Overall number of modules is " << permutation->getNumberOfModules( &mapping ) ; + MBI_DEBUG << "Cost is " << costFunction->Evaluate( network, &mapping ) ; + MBI_INFO << "Overall number of modules is " << permutation->getNumberOfModules( &mapping ) ; + MBI_INFO << "Cost is " << costFunction->Evaluate( network, &mapping ) ; - return; - } - } + return; + } } + } } void QmitkConnectomicsNetworkOperationsView::OnPrunePushButtonClicked() { - std::vector nodes = this->GetDataManagerSelection(); - if ( nodes.empty() ) + std::vector nodes = this->GetDataManagerSelection(); + if ( nodes.empty() ) + { + QMessageBox::information( NULL, "Network pruning", "Please select one or more networks."); + return; + } + + for( std::vector::iterator it = nodes.begin(); + it != nodes.end(); + ++it ) + { + mitk::DataNode::Pointer node = *it; + + if( node.IsNotNull() && dynamic_cast(node->GetData()) ) { - QMessageBox::information( NULL, "Network pruning", "Please select one or more networks."); - return; + return; } - for( std::vector::iterator it = nodes.begin(); - it != nodes.end(); - ++it ) { - mitk::DataNode::Pointer node = *it; - - if( node.IsNotNull() && dynamic_cast(node->GetData()) ) - { - return; - } - - { - mitk::ConnectomicsNetwork* network = dynamic_cast( node->GetData() ); - if( node.IsNotNull() && network ) - { - // Edge pruning will also do node pruning - network->PruneEdgesBelowWeight( this->m_Controls->pruneEdgeWeightSpinBox->value() ); - } - } + mitk::ConnectomicsNetwork* network = dynamic_cast( node->GetData() ); + if( node.IsNotNull() && network ) + { + // Edge pruning will also do node pruning + network->PruneEdgesBelowWeight( this->m_Controls->pruneEdgeWeightSpinBox->value() ); + } } + } } void QmitkConnectomicsNetworkOperationsView::OnCreateConnectivityMatrixImagePushButtonClicked() { - std::vector nodes = this->GetDataManagerSelection(); - if ( nodes.empty() ) + std::vector nodes = this->GetDataManagerSelection(); + if ( nodes.empty() ) + { + QMessageBox::information( NULL, "Connectivity Matrix Image creation", "Please select one or more networks."); + return; + } + + for( std::vector::iterator it = nodes.begin(); + it != nodes.end(); + ++it ) + { + mitk::DataNode::Pointer node = *it; + + if( node.IsNotNull() && dynamic_cast(node->GetData()) ) { - QMessageBox::information( NULL, "Connectivity Matrix Image creation", "Please select one or more networks."); - return; + return; } - for( std::vector::iterator it = nodes.begin(); it != nodes.end(); ++it ) { - mitk::DataNode::Pointer node = *it; - - if( node.IsNotNull() && dynamic_cast( node->GetData() ) ) - { - mitk::ConnectomicsNetwork* network = dynamic_cast( node->GetData() ); - itk::ConnectomicsNetworkToConnectivityMatrixImageFilter::Pointer filter = itk::ConnectomicsNetworkToConnectivityMatrixImageFilter::New(); - filter->SetInputNetwork( network ); - filter->SetBinaryConnectivity(m_Controls->binaryCheckBox->isChecked()); - filter->SetRescaleConnectivity(m_Controls->rescaleCheckBox->isChecked()); - filter->Update(); - -// mitk::DataNode::Pointer connectivityMatrixImageNode = mitk::DataNode::New(); -// connectivityMatrixImageNode->SetData ( connectivityMatrixImage ); - -// connectivityMatrixImageNode->SetName( name.toStdString().c_str() ); -// this->GetDefaultDataStorage()->Add(connectivityMatrixImageNode, node ); - - mitk::Image::Pointer connectivityMatrixImage = mitk::ImportItkImage( filter->GetOutput())->Clone(); - if (m_Controls->binaryCheckBox->isChecked()) - { - QString name("/local/data/Fibercup/connectomics/connectivity_matrices/binary/"); - name += node->GetName().c_str(); - name += "_ConnectivityMatrix.nrrd"; - mitk::IOUtil::SaveImage(connectivityMatrixImage, name.toStdString().c_str()); - - QString name2("/local/data/Fibercup/connectomics/pics/binary/"); - name2 += node->GetName().c_str(); - name2 += "_ConnectivityMatrix.png"; - mitk::IOUtil::SaveImage(connectivityMatrixImage, name2.toStdString().c_str()); - } - else - { - QString name("/local/data/Fibercup/connectomics/connectivity_matrices/"); - name += node->GetName().c_str(); - name += "_ConnectivityMatrix.nrrd"; - mitk::IOUtil::SaveImage(connectivityMatrixImage, name.toStdString().c_str()); - - QString name2("/local/data/Fibercup/connectomics/pics/"); - name2 += node->GetName().c_str(); - name2 += "_ConnectivityMatrix.png"; - mitk::IOUtil::SaveImage(connectivityMatrixImage, name2.toStdString().c_str()); - } - } + mitk::ConnectomicsNetwork* network = dynamic_cast( node->GetData() ); + if( node.IsNotNull() && network ) + { + itk::ConnectomicsNetworkToConnectivityMatrixImageFilter::Pointer filter = itk::ConnectomicsNetworkToConnectivityMatrixImageFilter::New(); + filter->SetInputNetwork( network ); + filter->SetBinaryConnectivity(m_Controls->binaryCheckBox->isChecked()); + filter->SetRescaleConnectivity(m_Controls->rescaleCheckBox->isChecked()); + filter->Update(); + + mitk::Image::Pointer connectivityMatrixImage = mitk::ImportItkImage( filter->GetOutput())->Clone(); + mitk::DataNode::Pointer connectivityMatrixImageNode = mitk::DataNode::New(); + connectivityMatrixImageNode->SetData ( connectivityMatrixImage ); + connectivityMatrixImageNode->SetName( "Connectivity matrix" ); + this->GetDefaultDataStorage()->Add(connectivityMatrixImageNode, node ); + } } -} - + } +} \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/Connectomics/QmitkConnectomicsNetworkOperationsView.h b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/Connectomics/QmitkConnectomicsNetworkOperationsView.h old mode 100755 new mode 100644 diff --git a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/Connectomics/QmitkConnectomicsNetworkOperationsViewControls.ui b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/Connectomics/QmitkConnectomicsNetworkOperationsViewControls.ui old mode 100755 new mode 100644