From 3b51a08c6a78ed09578f198f6a13dd769d460bef Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Tue, 22 Sep 2015 19:39:15 +0200 Subject: [PATCH] ... --- appli/ImageMPR/ImageMPR.cxx | 47 ++++- appli/ImageMPR/ImageMPR.h | 8 +- appli/examples/CMakeLists.txt | 2 +- appli/examples/example_MPR.cxx | 99 ++++------ appli/examples/example_ReadWriteImage.cxx | 5 + .../SecondRankDiffusionTensorToPolyData.cxx | 181 ++++++++++++++++++ .../SecondRankDiffusionTensorToPolyData.h | 53 +++++ lib/cpExtensions/Visualization/MPRActors.cxx | 3 - .../Interface/Instances_itkImage.cxx | 2 + lib/cpPlugins/Plugins/CMakeLists.txt | 1 + lib/cpPlugins/Plugins/Host.cxx | 2 + lib/cpPlugins/Plugins/ImageReader.cxx | 15 ++ .../SecondRankDiffusionTensorToPolyData.cxx | 82 ++++++++ .../SecondRankDiffusionTensorToPolyData.h | 55 ++++++ 14 files changed, 481 insertions(+), 74 deletions(-) create mode 100644 lib/cpExtensions/Algorithms/SecondRankDiffusionTensorToPolyData.cxx create mode 100644 lib/cpExtensions/Algorithms/SecondRankDiffusionTensorToPolyData.h create mode 100644 lib/cpPlugins/Plugins/SecondRankDiffusionTensorToPolyData.cxx create mode 100644 lib/cpPlugins/Plugins/SecondRankDiffusionTensorToPolyData.h diff --git a/appli/ImageMPR/ImageMPR.cxx b/appli/ImageMPR/ImageMPR.cxx index def9fc4..337aac1 100644 --- a/appli/ImageMPR/ImageMPR.cxx +++ b/appli/ImageMPR/ImageMPR.cxx @@ -30,12 +30,18 @@ ImageMPR::ImageMPR( QWidget* parent ) this->m_UI->setupUi( this ); // Create and associate renderers - this->m_MPR = new TMPR( - this->m_UI->m_XPlaneVTK->GetRenderWindow( ), - this->m_UI->m_YPlaneVTK->GetRenderWindow( ), - this->m_UI->m_ZPlaneVTK->GetRenderWindow( ), - this->m_UI->m_3DVTK->GetRenderWindow( ) - ); + this->m_MPRActors = vtkSmartPointer< TMPRActors >::New( ); + + for( unsigned int i = 0; i < 4; ++i ) + { + this->m_Renderers[ i ] = vtkSmartPointer< vtkRenderer >::New( ); + this->m_Renderers[ i ]->SetBackground( 0.1, 0.3, 0.8 ); + + } // rof + this->m_UI->m_XPlaneVTK->GetRenderWindow( )->AddRenderer( this->m_Renderers[ 0 ] ); + this->m_UI->m_YPlaneVTK->GetRenderWindow( )->AddRenderer( this->m_Renderers[ 1 ] ); + this->m_UI->m_ZPlaneVTK->GetRenderWindow( )->AddRenderer( this->m_Renderers[ 2 ] ); + this->m_UI->m_3DVTK->GetRenderWindow( )->AddRenderer( this->m_Renderers[ 3 ] ); // signals <-> slots QObject::connect( @@ -68,7 +74,6 @@ ImageMPR:: // Delete objects delete this->m_UI; - delete this->m_MPR; } // ------------------------------------------------------------------------- @@ -193,7 +198,31 @@ _triggered_actionOpenInputImage( ) dynamic_cast< TPluginImage* >( reader->GetOutput( 0 ) ); reader->DisconnectOutputs( ); if( this->m_InputImage.IsNotNull( ) ) - this->m_MPR->SetImage( this->m_InputImage->GetVTKImageData( ) ); + { + this->m_MPRActors->SetInputData( this->m_InputImage->GetVTKImageData( ) ); + this->m_MPRActors->PushDataInto( + this->m_Renderers[ 0 ], + this->m_Renderers[ 1 ], + this->m_Renderers[ 2 ], + this->m_Renderers[ 3 ] + ); + + /* + this->m_MPR.AssociatePlaneInteractor( 0, this->m_UI->m_XPlaneVTK->GetRenderWindow( )->GetInteractor( ) ); + this->m_MPR.AssociatePlaneInteractor( 1, this->m_UI->m_YPlaneVTK->GetRenderWindow( )->GetInteractor( ) ); + this->m_MPR.AssociatePlaneInteractor( 2, this->m_UI->m_ZPlaneVTK->GetRenderWindow( )->GetInteractor( ) ); + */ + + } // fi + this->m_Renderers[ 0 ]->ResetCamera( ); + this->m_Renderers[ 1 ]->ResetCamera( ); + this->m_Renderers[ 2 ]->ResetCamera( ); + this->m_Renderers[ 3 ]->ResetCamera( ); + + this->m_UI->m_XPlaneVTK->GetRenderWindow( )->Render( ); + this->m_UI->m_YPlaneVTK->GetRenderWindow( )->Render( ); + this->m_UI->m_ZPlaneVTK->GetRenderWindow( )->Render( ); + this->m_UI->m_3DVTK->GetRenderWindow( )->Render( ); } else QMessageBox::critical( @@ -264,6 +293,7 @@ _triggered_actionOpenInputPolyData( ) void ImageMPR:: _triggered_actionImageToImage( ) { + /* TODO if( this->m_InputImage.IsNull( ) ) return; @@ -305,6 +335,7 @@ _triggered_actionImageToImage( ) tr( "Error executing filter" ), tr( err.c_str( ) ) ); + */ } // ------------------------------------------------------------------------- diff --git a/appli/ImageMPR/ImageMPR.h b/appli/ImageMPR/ImageMPR.h index 1418bf6..808c0ab 100644 --- a/appli/ImageMPR/ImageMPR.h +++ b/appli/ImageMPR/ImageMPR.h @@ -9,14 +9,15 @@ #include // vtk stuff +#include #include +#include // Plugins interface #include #include #include #include -#include // ------------------------------------------------------------------------- namespace Ui @@ -43,7 +44,7 @@ public: typedef cpPlugins::Interface::Parameters TParameters; typedef std::set< std::string > TStringContainer; - typedef cpExtensions::Visualization::MPRWithDifferentWindows TMPR; + typedef cpExtensions::Visualization::MPRActors TMPRActors; public: explicit ImageMPR( QWidget* parent = 0 ); @@ -78,7 +79,8 @@ private: TPluginMesh::Pointer m_InputMesh; // Visualization stuff - TMPR* m_MPR; + vtkSmartPointer< TMPRActors > m_MPRActors; + vtkSmartPointer< vtkRenderer > m_Renderers[ 4 ]; vtkSmartPointer< vtkPolyDataMapper > m_InputMeshMapper; vtkSmartPointer< vtkActor > m_InputMeshActor; diff --git a/appli/examples/CMakeLists.txt b/appli/examples/CMakeLists.txt index 7d12653..f233136 100644 --- a/appli/examples/CMakeLists.txt +++ b/appli/examples/CMakeLists.txt @@ -15,7 +15,7 @@ SET( ## example_ReadImageSeriesWriteImage ## example_ReadQuadEdgeMesh ## example_RenderQuadEdgeMesh - ## example_MPR + example_MPR ) FOREACH(prog ${EXAMPLES_PROGRAMS}) diff --git a/appli/examples/example_MPR.cxx b/appli/examples/example_MPR.cxx index f3dbffb..1691e08 100644 --- a/appli/examples/example_MPR.cxx +++ b/appli/examples/example_MPR.cxx @@ -5,31 +5,24 @@ #include #include #include -#include +#include -#include -#include -#include #include #include #include -#include int main( int argc, char* argv[] ) { - if( argc < 4 ) + if( argc < 3 ) { std::cerr << "Usage: " << argv[ 0 ] - << " plugins_file" - << " input_image" - << " pixel_type" << std::endl; + << " plugins_file input_image(s)" + << std::endl; return( 1 ); } // fi std::string plugins_file = argv[ 1 ]; - std::string input_image_file = argv[ 2 ]; - std::string pixel_type = argv[ 3 ]; // Create interface typedef cpPlugins::Interface::Interface TInterface; @@ -42,8 +35,7 @@ int main( int argc, char* argv[] ) typedef cpPlugins::Interface::ProcessObject TProcessObject; typedef cpPlugins::Interface::Parameters TParameters; cpPlugins::Interface::ProcessObject::Pointer reader; - - reader = plugins.CreateProcessObject( "cpPlugins::Plugins::ImageReader" ); + reader = plugins.CreateProcessObject( "cpPlugins::ImageReader" ); if( reader.IsNull( ) ) { std::cerr << "No suitable reader found in plugins." << std::endl; @@ -53,67 +45,56 @@ int main( int argc, char* argv[] ) // Configure reader TParameters reader_params = reader->GetDefaultParameters( ); - reader_params.AddValueToStringList( "FileNames", input_image_file ); - reader_params.SetValueAsString( "PixelType", pixel_type ); - reader_params.SetValueAsUint( "ImageDimension", 3 ); - reader_params.SetValueAsUint( "IsColorImage", 0 ); + for( int i = 2; i < argc; ++i ) + reader_params.AddValueToStringList( "FileNames", argv[ i ] ); reader->SetParameters( reader_params ); // Execute reader std::string msg = reader->Update( ); - if( msg != "" ) + { std::cerr << "ERROR: " << msg << std::endl; + return( 1 ); + + } // fi + cpPlugins::Interface::Image* image = + dynamic_cast< cpPlugins::Interface::Image* >( reader->GetOutput( 0 ) ); + vtkImageData* vtk_image = image->GetVTKImageData( ); + if( vtk_image == NULL ) + { + std::cerr + << "ERROR: read image does not have a valid VTK conversion." + << std::endl; + return( 1 ); + + } // fi // Visualization stuff - vtkSmartPointer< vtkRenderWindow > window = + vtkSmartPointer< vtkRenderWindow > window = vtkSmartPointer< vtkRenderWindow >::New( ); + window->SetSize( 700, 700 ); - vtkSmartPointer< vtkRenderWindowInteractor > interactor = + // Renderers + vtkSmartPointer< vtkRenderer > renderer = + vtkSmartPointer< vtkRenderer >::New( ); + window->AddRenderer( renderer ); + + // Interactor + vtkSmartPointer< vtkRenderWindowInteractor > interactor = vtkSmartPointer< vtkRenderWindowInteractor >::New( ); - interactor->SetRenderWindow( window ); - // Renderers - vtkSmartPointer< vtkRenderer > xrenderer = - vtkSmartPointer< vtkRenderer >::New( ); - vtkSmartPointer< vtkRenderer > yrenderer = - vtkSmartPointer< vtkRenderer >::New( ); - vtkSmartPointer< vtkRenderer > zrenderer = - vtkSmartPointer< vtkRenderer >::New( ); - vtkSmartPointer< vtkRenderer > wrenderer = - vtkSmartPointer< vtkRenderer >::New( ); - - xrenderer->SetBackground( 0.7, 0.5, 0.5 ); - yrenderer->SetBackground( 0.5, 0.7, 0.5 ); - zrenderer->SetBackground( 0.5, 0.5, 0.7 ); - wrenderer->SetBackground( 0.5, 0.5, 0.5 ); - - xrenderer->SetViewport( 0, 0, 0.5, 0.5 ); - yrenderer->SetViewport( 0, 0.5, 0.5, 1 ); - zrenderer->SetViewport( 0.5, 0, 1, 0.5 ); - wrenderer->SetViewport( 0.5, 0.5, 1, 1 ); - - window->AddRenderer( xrenderer ); - window->AddRenderer( yrenderer ); - window->AddRenderer( zrenderer ); - window->AddRenderer( wrenderer ); - - // Create actors - typedef cpPlugins::Extensions::Visualization::MPRActors TMPRActors; - vtkSmartPointer< TMPRActors > mprActors = - vtkSmartPointer< TMPRActors >::New( ); - mprActors->SetInputData( - dynamic_cast< cpPlugins::Interface::Image* >( reader->GetOutput( 0 ) )-> - GetVTKImageData( ) - ); - mprActors->PushDataInto( xrenderer, yrenderer, zrenderer, wrenderer ); + // Actors + cpExtensions::Visualization::MPRObjects mpr; + mpr.SetImage( vtk_image ); + /* + mpr.AssociatePlaneInteractor( 0, interactor ); + mpr.AssociatePlaneInteractor( 1, interactor ); + mpr.AssociatePlaneInteractor( 2, interactor ); + */ // Begin interaction - xrenderer->ResetCamera( ); - yrenderer->ResetCamera( ); - zrenderer->ResetCamera( ); - wrenderer->ResetCamera( ); + renderer->ResetCamera( ); window->Render( ); interactor->Start( ); diff --git a/appli/examples/example_ReadWriteImage.cxx b/appli/examples/example_ReadWriteImage.cxx index 8c562a9..0098973 100644 --- a/appli/examples/example_ReadWriteImage.cxx +++ b/appli/examples/example_ReadWriteImage.cxx @@ -5,6 +5,8 @@ #include #include +#include + int main( int argc, char* argv[] ) { if( argc < 4 ) @@ -69,6 +71,9 @@ int main( int argc, char* argv[] ) return( 1 ); } // fi + + dynamic_cast< cpPlugins::Interface::Image* >( reader->GetOutput( 0 ) )->GetVTKImageData( )->Print( std::cout ); + return( 0 ); } diff --git a/lib/cpExtensions/Algorithms/SecondRankDiffusionTensorToPolyData.cxx b/lib/cpExtensions/Algorithms/SecondRankDiffusionTensorToPolyData.cxx new file mode 100644 index 0000000..0645898 --- /dev/null +++ b/lib/cpExtensions/Algorithms/SecondRankDiffusionTensorToPolyData.cxx @@ -0,0 +1,181 @@ +// ------------------------------------------------------------------------- +// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) +// ------------------------------------------------------------------------- + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +template< class I > +typename cpExtensions::Algorithms::SecondRankDiffusionTensorToPolyData< I >:: +Self* cpExtensions::Algorithms::SecondRankDiffusionTensorToPolyData< I >:: +New( ) +{ + return( new Self ); +} + +// ------------------------------------------------------------------------- +template< class I > +void cpExtensions::Algorithms::SecondRankDiffusionTensorToPolyData< I >:: +SetInputData( const I* image ) +{ + this->m_ITKImage = image; + this->Modified( ); +} + +// ------------------------------------------------------------------------- +template< class I > +cpExtensions::Algorithms::SecondRankDiffusionTensorToPolyData< I >:: +SecondRankDiffusionTensorToPolyData( ) + : vtkPolyDataAlgorithm( ) +{ + this->SetNumberOfInputPorts( 0 ); +} + +// ------------------------------------------------------------------------- +template< class I > +cpExtensions::Algorithms::SecondRankDiffusionTensorToPolyData< I >:: +~SecondRankDiffusionTensorToPolyData( ) +{ +} + +// ------------------------------------------------------------------------- +template< class I > +int cpExtensions::Algorithms::SecondRankDiffusionTensorToPolyData< I >:: +RequestData( + vtkInformation* request, + vtkInformationVector** inputVector, + vtkInformationVector* outputVector + ) +{ + if( this->m_ITKImage.IsNull( ) ) + return( 0 ); + + // get the info objects + vtkInformation* outInfo = outputVector->GetInformationObject( 0 ); + vtkPolyData* polyData = vtkPolyData::SafeDownCast( + outInfo->Get(vtkDataObject::DATA_OBJECT()) + ); + + itk::ImageRegionConstIteratorWithIndex< I > tensorIt( this->m_ITKImage, this->m_ITKImage->GetRequestedRegion() ); + + vtkSmartPointer points = vtkSmartPointer::New(); + vtkSmartPointer vtkTensors = vtkSmartPointer::New(); + vtkTensors->SetNumberOfComponents(9); + for ( tensorIt.GoToBegin(); !tensorIt.IsAtEnd(); ++tensorIt ) + { + typename I::IndexType tensorIndex = tensorIt.GetIndex(); + typename I::PixelType tensor = tensorIt.Get(); + typename I::PointType ptensor; + + // TODO: std::cout << "\n Index [" << tensorIndex[0] << ", " << tensorIndex[1] << ", " << tensorIndex[2] << "]" << std::endl; + this->m_ITKImage->TransformIndexToPhysicalPoint( tensorIndex, ptensor ); + vtkIdType vtkPointID = points->InsertNextPoint(ptensor[0], ptensor[1], ptensor[2]); + + /** + * Definition included in cdifTypes. + * typedef itk::SymmetricSecondRankTensor< double > Diffusion2ndRankTensor; + */ + //Diffusion2ndRankTensor Diffusion2ndRankTensor; + + + /** + * SYMMETRIC SECOND RANK TENSOR + * + * The upper-right triangle of the matrix: + * + * | 0 1 2 | + * | X 3 4 | + * | X X 5 | + * + * | xx xy xz | + * | X yy yz | + * | X X zz | + */ + /* + Diffusion2ndRankTensor = tensor[0]; + Diffusion2ndRankTensor = tensor[1]; + Diffusion2ndRankTensor = tensor[2]; + Diffusion2ndRankTensor = tensor[3]; + Diffusion2ndRankTensor = tensor[4]; + Diffusion2ndRankTensor = tensor[5]; + */ + typename I::PixelType::EigenValuesArrayType evalues; + typename I::PixelType::EigenVectorsMatrixType evectors; + + /** + * Return an array containing EigenValues, + * and a matrix containing Eigenvectors. + */ + tensor.ComputeEigenAnalysis(evalues, evectors); + + /* + std::cout << "[C-DIFFUSION - NRRD Tensors Example] Eigen values: " << evalues[0] << ", " << evalues[1] << ", " << evalues[2] << std::endl; + + std::cout << "[C-DIFFUSION - NRRD Tensors Example] Eigen vectors: " + + << "(" << evectors(0,0) << ", " << evectors(0,1) << ", " << evectors(0,2) << "), " + << "(" << evectors(1,0) << ", " << evectors(1,1) << ", " << evectors(1,2) << "), " + << "(" << evectors(2,0) << ", " << evectors(2,1) << ", " << evectors(2,2) << ")" << std::endl; + */ + evectors.GetVnlMatrix().scale_row(0, evalues[0]); + evectors.GetVnlMatrix().scale_row(1, evalues[1]); + evectors.GetVnlMatrix().scale_row(2, evalues[2]); + + /* + std::cout << "[C-DIFFUSION - NRRD Tensors Example] Eigen values x Eigen vectors : " + + << "(" << evectors(0,0) << ", " << evectors(0,1) << ", " << evectors(0,2) << "), " + << "(" << evectors(1,0) << ", " << evectors(1,1) << ", " << evectors(1,2) << "), " + << "(" << evectors(2,0) << ", " << evectors(2,1) << ", " << evectors(2,2) << ")" << std::endl; + */ + vtkTensors->InsertTuple9( + vtkPointID, + evectors(0,0), evectors(0,1), evectors(0,2), + evectors(1,0), evectors(1,1), evectors(1,2), + evectors(2,0), evectors(2,1), evectors(2,2) + ); + } // rof + + polyData->SetPoints( points ); + vtkSmartPointer pointData = polyData->GetPointData(); + pointData->SetTensors( vtkTensors ); + return( 1 ); + + /** + * VISUALISATION CODE BELOW + */ + +// vtkSmartPointer cubeSource = vtkSmartPointer::New(); +// cubeSource->Update(); +// +// vtkSmartPointer tensorGlyph = vtkSmartPointer::New(); +//#if VTK_MAJOR_VERSION <= 5 +// tensorGlyph->SetInput(polyData); +//#else +// tensorGlyph->SetInputData(polyData); +//#endif +// tensorGlyph->SetSourceConnection(cubeSource->GetOutputPort()); +// tensorGlyph->ColorGlyphsOff(); +// tensorGlyph->ThreeGlyphsOff(); +// tensorGlyph->ExtractEigenvaluesOff(); +// tensorGlyph->Update(); +// . +// . +// . + +} + +// ------------------------------------------------------------------------- +template class cpExtensions::Algorithms::SecondRankDiffusionTensorToPolyData< itk::Image< itk::SymmetricSecondRankTensor< float, 3 >, 3 > >; +template class cpExtensions::Algorithms::SecondRankDiffusionTensorToPolyData< itk::Image< itk::SymmetricSecondRankTensor< double, 3 >, 3 > >; + +// eof - $RCSfile$ diff --git a/lib/cpExtensions/Algorithms/SecondRankDiffusionTensorToPolyData.h b/lib/cpExtensions/Algorithms/SecondRankDiffusionTensorToPolyData.h new file mode 100644 index 0000000..1861263 --- /dev/null +++ b/lib/cpExtensions/Algorithms/SecondRankDiffusionTensorToPolyData.h @@ -0,0 +1,53 @@ +// ------------------------------------------------------------------------- +// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) +// ------------------------------------------------------------------------- + +#ifndef __CPEXTENSIONS__ALGORITHMS__SECONDRANKDIFFUSIONTENSORTOPOLYDATA__H__ +#define __CPEXTENSIONS__ALGORITHMS__SECONDRANKDIFFUSIONTENSORTOPOLYDATA__H__ + +#include + +#include + +namespace cpExtensions +{ + namespace Algorithms + { + /** + */ + template< class I > + class cpExtensions_EXPORT SecondRankDiffusionTensorToPolyData + : public vtkPolyDataAlgorithm + { + public: + typedef SecondRankDiffusionTensorToPolyData Self; + + public: + static Self* New( ); + vtkTypeMacro( SecondRankDiffusionTensorToPolyData, vtkPolyDataAlgorithm ); + + void SetInputData( const I* image ); + + protected: + SecondRankDiffusionTensorToPolyData( ); + virtual ~SecondRankDiffusionTensorToPolyData( ); + + virtual int RequestData( + vtkInformation* , vtkInformationVector**, vtkInformationVector* + ); + + private: + SecondRankDiffusionTensorToPolyData( const Self& other ); + Self& operator=( const Self& other ); + + protected: + typename I::ConstPointer m_ITKImage; + }; + + } // ecapseman + +} // ecapseman + +#endif // __CPEXTENSIONS__ALGORITHMS__SECONDRANKDIFFUSIONTENSORTOPOLYDATA__H__ + +// eof - $RCSfile$ diff --git a/lib/cpExtensions/Visualization/MPRActors.cxx b/lib/cpExtensions/Visualization/MPRActors.cxx index b7ebc24..43600a3 100644 --- a/lib/cpExtensions/Visualization/MPRActors.cxx +++ b/lib/cpExtensions/Visualization/MPRActors.cxx @@ -70,10 +70,7 @@ PushDataInto( vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w ) } // rof if( w != NULL ) - { w->AddActor( this->ImageOutlineActor ); - - } // fi } // ------------------------------------------------------------------------- diff --git a/lib/cpPlugins/Interface/Instances_itkImage.cxx b/lib/cpPlugins/Interface/Instances_itkImage.cxx index ab8d38a..8fadae0 100644 --- a/lib/cpPlugins/Interface/Instances_itkImage.cxx +++ b/lib/cpPlugins/Interface/Instances_itkImage.cxx @@ -124,6 +124,8 @@ cpPlugins_ImageArray_Export_AllDimensions( cpPlugins_Image_Export( itk::DiffusionTensor3D< float >, 3 ); cpPlugins_Image_Export( itk::DiffusionTensor3D< double >, 3 ); +cpPlugins_Image_Export( itk::DiffusionTensor3D< float >, 4 ); +cpPlugins_Image_Export( itk::DiffusionTensor3D< double >, 4 ); cpPlugins_Image_Export( itk::Offset< 2 >, 2 ); cpPlugins_Image_Export( itk::Offset< 3 >, 3 ); cpPlugins_Image_Export( itk::Offset< 4 >, 4 ); diff --git a/lib/cpPlugins/Plugins/CMakeLists.txt b/lib/cpPlugins/Plugins/CMakeLists.txt index 6f972d2..d908e42 100644 --- a/lib/cpPlugins/Plugins/CMakeLists.txt +++ b/lib/cpPlugins/Plugins/CMakeLists.txt @@ -31,6 +31,7 @@ GENERATE_EXPORT_HEADER( ) TARGET_LINK_LIBRARIES( ${LIBRARY_NAME} + cpExtensions cpPlugins_Interface ) diff --git a/lib/cpPlugins/Plugins/Host.cxx b/lib/cpPlugins/Plugins/Host.cxx index 81488eb..e07b5b0 100644 --- a/lib/cpPlugins/Plugins/Host.cxx +++ b/lib/cpPlugins/Plugins/Host.cxx @@ -6,6 +6,7 @@ #include #include #include +#include /// TODO: doc PLUMA_CONNECTOR @@ -20,6 +21,7 @@ bool connect( pluma::Host& host ) host.add( new MarchingCubesProvider( ) ); host.add( new OtsuThresholdImageFilterProvider( ) ); host.add( new RGBImageToOtherChannelsFilterProvider( ) ); + host.add( new SecondRankDiffusionTensorToPolyDataProvider( ) ); return( true ); } diff --git a/lib/cpPlugins/Plugins/ImageReader.cxx b/lib/cpPlugins/Plugins/ImageReader.cxx index 25bdc7a..fc752ef 100644 --- a/lib/cpPlugins/Plugins/ImageReader.cxx +++ b/lib/cpPlugins/Plugins/ImageReader.cxx @@ -366,6 +366,21 @@ _GD0( itk::ImageIOBase* io, const TStringList& names ) break; } // hctiws } + else if( D == 4 ) + { + switch( ct ) + { + case itk::ImageIOBase::FLOAT: + r = this->_RealGD< itk::DiffusionTensor3D< float >, 4 >( names ); + break; + case itk::ImageIOBase::DOUBLE: + r = this->_RealGD< itk::DiffusionTensor3D< double >, 4 >( names ); + break; + default: + r = "ImageReader: Diffusion tensor type not supported."; + break; + } // hctiws + } else r = "ImageReader: Diffusion tensor dimension not supported."; } diff --git a/lib/cpPlugins/Plugins/SecondRankDiffusionTensorToPolyData.cxx b/lib/cpPlugins/Plugins/SecondRankDiffusionTensorToPolyData.cxx new file mode 100644 index 0000000..47261cc --- /dev/null +++ b/lib/cpPlugins/Plugins/SecondRankDiffusionTensorToPolyData.cxx @@ -0,0 +1,82 @@ +#include +#include +#include + +#include +#include + +// ------------------------------------------------------------------------- +cpPlugins::Plugins::SecondRankDiffusionTensorToPolyData:: +SecondRankDiffusionTensorToPolyData( ) + : Superclass( ), + m_Algorithm( NULL ) +{ + this->m_ClassName = "cpPlugins::SecondRankDiffusionTensorToPolyData"; + this->m_ClassCategory = "ImageToMeshFilter"; + + this->SetNumberOfInputs( 1 ); + this->SetNumberOfOutputs( 1 ); + this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 ); + + using namespace cpPlugins::Interface; + this->m_Parameters = this->m_DefaultParameters; +} + +// ------------------------------------------------------------------------- +cpPlugins::Plugins::SecondRankDiffusionTensorToPolyData:: +~SecondRankDiffusionTensorToPolyData( ) +{ + if( this->m_Algorithm != NULL ) + this->m_Algorithm->Delete( ); +} + +// ------------------------------------------------------------------------- +std::string cpPlugins::Plugins::SecondRankDiffusionTensorToPolyData:: +_GenerateData( ) +{ + // Get input + cpPlugins::Interface::Image* image = + this->_Input< cpPlugins::Interface::Image >( 0 ); + if( image == NULL ) + return( "SecondRankDiffusionTensorToPolyData: Input data is not a valid image." ); + + itk::DataObject* itk_image = NULL; + std::string r = ""; + cpPlugins_ImageArray_Input_Demangle( itk::SymmetricSecondRankTensor, float, 3, 3, image, itk_image, r, _RealGD ); + else cpPlugins_ImageArray_Input_Demangle( itk::SymmetricSecondRankTensor, double, 3, 3, image, itk_image, r, _RealGD ); + else + r = "SecondRankDiffusionTensorToPolyData: Input does not have a DiffusionTensor3D."; + return( r ); +} + +// ------------------------------------------------------------------------- +template< class I > +std::string cpPlugins::Plugins::SecondRankDiffusionTensorToPolyData:: +_RealGD( itk::DataObject* image ) +{ + typedef cpExtensions::Algorithms::SecondRankDiffusionTensorToPolyData< I > _F; + + // Configure filter + _F* f = NULL; + if( this->m_Algorithm == NULL ) + { + f = _F::New( ); + this->m_Algorithm = f; + + } // fi + f->SetInputData( dynamic_cast< I* >( image ) ); + this->m_Algorithm->Update( ); + + // Connect output + cpPlugins::Interface::Mesh* out = + this->_Output< cpPlugins::Interface::Mesh >( 0 ); + if( out != NULL ) + { + out->SetVTKMesh( this->m_Algorithm->GetOutput( ) ); + return( "" ); + } + else + return( "OtsuThresholdImageFilter: output not correctly created." ); +} + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Plugins/SecondRankDiffusionTensorToPolyData.h b/lib/cpPlugins/Plugins/SecondRankDiffusionTensorToPolyData.h new file mode 100644 index 0000000..ff03716 --- /dev/null +++ b/lib/cpPlugins/Plugins/SecondRankDiffusionTensorToPolyData.h @@ -0,0 +1,55 @@ +#ifndef __CPPLUGINS__PLUGINS__SECONDRANKDIFFUSIONTENSORTOPOLYDATA__H__ +#define __CPPLUGINS__PLUGINS__SECONDRANKDIFFUSIONTENSORTOPOLYDATA__H__ + +#include +#include + +class vtkPolyDataAlgorithm; + +namespace cpPlugins +{ + namespace Plugins + { + /** + */ + class cpPlugins_EXPORT SecondRankDiffusionTensorToPolyData + : public cpPlugins::Interface::ImageToMeshFilter + { + public: + typedef SecondRankDiffusionTensorToPolyData Self; + typedef cpPlugins::Interface::ImageToMeshFilter Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + public: + itkNewMacro( Self ); + itkTypeMacro( SecondRankDiffusionTensorToPolyData, cpPluginsInterfaceImageToMeshFilter ); + + protected: + SecondRankDiffusionTensorToPolyData( ); + virtual ~SecondRankDiffusionTensorToPolyData( ); + + virtual std::string _GenerateData( ); + + template< class I > + inline std::string _RealGD( itk::DataObject* image ); + + private: + // Purposely not implemented + SecondRankDiffusionTensorToPolyData( const Self& ); + Self& operator=( const Self& ); + + protected: + vtkPolyDataAlgorithm* m_Algorithm; + }; + + // --------------------------------------------------------------------- + CPPLUGINS_INHERIT_PROVIDER( SecondRankDiffusionTensorToPolyData ); + + } // ecapseman + +} // ecapseman + +#endif // __CPPLUGINS__PLUGINS__SECONDRANKDIFFUSIONTENSORTOPOLYDATA__H__ + +// eof - $RCSfile$ -- 2.45.1