From: Leonardo Florez-Valencia Date: Tue, 9 Dec 2014 17:44:34 +0000 (+0100) Subject: Integration of new functionalities into ProcessObject and DataObject X-Git-Tag: v0.1~447 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=1adce86c283e253ec41f762652bc477d56d617a5;p=cpPlugins.git Integration of new functionalities into ProcessObject and DataObject --- diff --git a/cmake/cpPluginsConfig.cmake.in b/cmake/cpPluginsConfig.cmake.in index bb9819a..a31bc50 100644 --- a/cmake/cpPluginsConfig.cmake.in +++ b/cmake/cpPluginsConfig.cmake.in @@ -11,7 +11,7 @@ FIND_PATH( FIND_PATH( cpPlugins_INCLUDE_DIR2 - cpPlugins/Interface/cpPlugins_Export.h + cpPlugins/Interface/cpPlugins_Interface_Export.h PATHS /usr/include /usr/local/include @@ -34,7 +34,7 @@ FIND_PATH( INCLUDE_DIRECTORIES( ${cpPlugins_INCLUDE_DIR1} ${cpPlugins_INCLUDE_DIR2} - ${cpPlugins_INCLUDE_DIR2} + ${cpPlugins_INCLUDE_DIR3} ) FIND_LIBRARY( @@ -47,9 +47,29 @@ FIND_LIBRARY( @CMAKE_INSTALL_PREFIX@/lib ) +FIND_LIBRARY( + cpPlugins_LIBRARY_NAME + cpPlugins + PATHS + /usr/lib + /usr/local/lib + @PROJECT_BINARY_DIR@ + @CMAKE_INSTALL_PREFIX@/lib + ) + +SET( + cpPlugins_Interface_INCLUDE_DIRS + ${cpPlugins_INCLUDE_DIR1} + ${cpPlugins_INCLUDE_DIR2} + ${cpPlugins_INCLUDE_DIR2} + ) SET( cpPlugins_Interface_LIBRARIES ${cpPlugins_Interface_LIBRARY_NAME} ) +SET( + cpPlugins_LIBRARIES + ${cpPlugins_LIBRARY_NAME} + ) ## eof - $RCSfile$ diff --git a/lib/cpPlugins/Interface/CMakeLists.txt b/lib/cpPlugins/Interface/CMakeLists.txt index e51b0ef..0ee961e 100644 --- a/lib/cpPlugins/Interface/CMakeLists.txt +++ b/lib/cpPlugins/Interface/CMakeLists.txt @@ -32,6 +32,7 @@ GENERATE_EXPORT_HEADER( TARGET_LINK_LIBRARIES( ${LIBRARY_NAME} cpPlugins_Pluma + ${ITK_LIBRARIES} ) ## eof - $RCSfile$ diff --git a/lib/cpPlugins/Interface/DataObject.cxx b/lib/cpPlugins/Interface/DataObject.cxx index 9c15346..4ec6223 100644 --- a/lib/cpPlugins/Interface/DataObject.cxx +++ b/lib/cpPlugins/Interface/DataObject.cxx @@ -30,9 +30,9 @@ GetDataObject( ) const // ------------------------------------------------------------------------- void cpPlugins::Interface::DataObject:: -SetDataObject( itk::DataObject* src ) +SetDataObject( itk::DataObject* dobj ) { - this->m_DataObject = src; + this->m_DataObject = dobj; } // ------------------------------------------------------------------------- diff --git a/lib/cpPlugins/Interface/DataObject.h b/lib/cpPlugins/Interface/DataObject.h index c083654..9edf92b 100644 --- a/lib/cpPlugins/Interface/DataObject.h +++ b/lib/cpPlugins/Interface/DataObject.h @@ -29,7 +29,7 @@ namespace cpPlugins virtual std::string GetClassName( ) const; itk::DataObject* GetDataObject( ) const; - virtual void SetDataObject( itk::DataObject* src ); + virtual void SetDataObject( itk::DataObject* dobj ); ProcessObject* GetSource( ) const; void SetSource( ProcessObject* src ); diff --git a/lib/cpPlugins/Interface/Image.cxx b/lib/cpPlugins/Interface/Image.cxx index 9b55ed2..d8a47c8 100644 --- a/lib/cpPlugins/Interface/Image.cxx +++ b/lib/cpPlugins/Interface/Image.cxx @@ -1,9 +1,29 @@ #include +#include +#include +#include + +// ------------------------------------------------------------------------- +#define cpPlugins_Interface_Image_Dimension( d, dobj, func ) \ + if( dynamic_cast< itk::ImageBase< d >* >( dobj ) != NULL ) \ + this->func< d >( ) + +// ------------------------------------------------------------------------- +#define cpPlugins_Interface_Image_Pixel( p, d, dobj, func ) \ + if( dynamic_cast< itk::Image< p, d >* >( dobj ) != NULL ) \ + this->func< p, d >( ) + +// ------------------------------------------------------------------------- +#define cpPlugins_Interface_Image_RGB( p, d, dobj, func ) \ + if( dynamic_cast< itk::Image< itk::RGBPixel< p >, d >* >( dobj ) != NULL ) \ + this->func< itk::RGBPixel< p >, d >( ) + // ------------------------------------------------------------------------- cpPlugins::Interface::Image:: Image( ) - : Superclass( ) + : Superclass( ), + m_VTKImageData( NULL ) { } @@ -20,4 +40,68 @@ GetClassName( ) const return( "cpPlugins::Interface::Image" ); } +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Image:: +SetDataObject( itk::DataObject* dobj ) +{ + this->Superclass::SetDataObject( dobj ); + + // WARNING: Only 2 and 3 dimensions at this moment + cpPlugins_Interface_Image_Dimension( 2, dobj, _ConnectToVTK_0 ); + else cpPlugins_Interface_Image_Dimension( 3, dobj, _ConnectToVTK_0 ); +} + +// ------------------------------------------------------------------------- +vtkImageData* cpPlugins::Interface::Image:: +GetVTKImageData( ) const +{ + return( this->m_VTKImageData ); +} + +// ------------------------------------------------------------------------- +template< unsigned int D > +void cpPlugins::Interface::Image:: +_ConnectToVTK_0( ) +{ + itk::DataObject* dobj = this->Superclass::GetDataObject( ); + + cpPlugins_Interface_Image_Pixel( char, D, dobj, _ConnectToVTK_1 ); + else cpPlugins_Interface_Image_Pixel( short, D, dobj, _ConnectToVTK_1 ); + else cpPlugins_Interface_Image_Pixel( int, D, dobj, _ConnectToVTK_1 ); + else cpPlugins_Interface_Image_Pixel( long, D, dobj, _ConnectToVTK_1 ); + else cpPlugins_Interface_Image_Pixel( unsigned char, D, dobj, _ConnectToVTK_1 ); + else cpPlugins_Interface_Image_Pixel( unsigned short, D, dobj, _ConnectToVTK_1 ); + else cpPlugins_Interface_Image_Pixel( unsigned int, D, dobj, _ConnectToVTK_1 ); + else cpPlugins_Interface_Image_Pixel( unsigned long, D, dobj, _ConnectToVTK_1 ); + else cpPlugins_Interface_Image_Pixel( float, D, dobj, _ConnectToVTK_1 ); + else cpPlugins_Interface_Image_Pixel( double, D, dobj, _ConnectToVTK_1 ); + else cpPlugins_Interface_Image_RGB( char, D, dobj, _ConnectToVTK_1 ); + else cpPlugins_Interface_Image_RGB( short, D, dobj, _ConnectToVTK_1 ); + else cpPlugins_Interface_Image_RGB( int, D, dobj, _ConnectToVTK_1 ); + else cpPlugins_Interface_Image_RGB( long, D, dobj, _ConnectToVTK_1 ); + else cpPlugins_Interface_Image_RGB( unsigned char, D, dobj, _ConnectToVTK_1 ); + else cpPlugins_Interface_Image_RGB( unsigned short, D, dobj, _ConnectToVTK_1 ); + else cpPlugins_Interface_Image_RGB( unsigned int, D, dobj, _ConnectToVTK_1 ); + else cpPlugins_Interface_Image_RGB( unsigned long, D, dobj, _ConnectToVTK_1 ); + else cpPlugins_Interface_Image_RGB( float, D, dobj, _ConnectToVTK_1 ); + else cpPlugins_Interface_Image_RGB( double, D, dobj, _ConnectToVTK_1 ); +} + +// ------------------------------------------------------------------------- +template< class P, unsigned int D > +void cpPlugins::Interface::Image:: +_ConnectToVTK_1( ) +{ + typedef itk::Image< P, D > _TImage; + typedef itk::ImageToVTKImageFilter< _TImage > _TFilter; + + _TImage* img = + dynamic_cast< _TImage* >( this->Superclass::GetDataObject( ) ); + typename _TFilter::Pointer filter = _TFilter::New( ); + filter->SetInput( img ); + filter->Update( ); + this->m_VTKImageData = filter->GetOutput( ); + this->m_Image2VTKImageData = filter; +} + // eof - $RCSfile$ diff --git a/lib/cpPlugins/Interface/Image.h b/lib/cpPlugins/Interface/Image.h index cbdc219..e6b2b77 100644 --- a/lib/cpPlugins/Interface/Image.h +++ b/lib/cpPlugins/Interface/Image.h @@ -7,6 +7,8 @@ #include #include +class vtkImageData; + namespace cpPlugins { namespace Interface @@ -25,6 +27,20 @@ namespace cpPlugins virtual ~Image( ); virtual std::string GetClassName( ) const; + virtual void SetDataObject( itk::DataObject* dobj ); + + vtkImageData* GetVTKImageData( ) const; + + protected: + template< unsigned int D > + void _ConnectToVTK_0( ); + + template< class P, unsigned int D > + void _ConnectToVTK_1( ); + + protected: + itk::ProcessObject::Pointer m_Image2VTKImageData; + vtkImageData* m_VTKImageData; }; } // ecapseman diff --git a/lib/cpPlugins/Interface/ProcessObject.cxx b/lib/cpPlugins/Interface/ProcessObject.cxx index 79fc2ab..a595e0e 100644 --- a/lib/cpPlugins/Interface/ProcessObject.cxx +++ b/lib/cpPlugins/Interface/ProcessObject.cxx @@ -4,7 +4,8 @@ // ------------------------------------------------------------------------- cpPlugins::Interface::ProcessObject:: ProcessObject( ) - : Superclass( ) + : Superclass( ), + m_OutputsDisconnected( false ) { } @@ -12,6 +13,7 @@ ProcessObject( ) cpPlugins::Interface::ProcessObject:: ~ProcessObject( ) { + this->_DeleteOutputs( ); } // ------------------------------------------------------------------------- @@ -62,12 +64,10 @@ SetNumberOfInputs( unsigned int n ) void cpPlugins::Interface::ProcessObject:: SetNumberOfOutputs( unsigned int n ) { + this->_DeleteOutputs( ); this->m_Outputs.clear( ); - this->m_Outputs.resize( n ); - - // Sync outputs with this source - for( unsigned int odx = 0; odx < this->m_Outputs.size( ); ++odx ) - this->m_Outputs[ odx ].SetSource( this ); + this->m_Outputs.resize( n, NULL ); + this->m_OutputsDisconnected = false; } // ------------------------------------------------------------------------- @@ -85,7 +85,7 @@ cpPlugins::Interface::DataObject* cpPlugins::Interface::ProcessObject:: GetOutput( unsigned int idx ) { if( idx < this->m_Outputs.size( ) ) - return( &( this->m_Outputs[ idx ] ) ); + return( this->m_Outputs[ idx ] ); else return( NULL ); } @@ -100,11 +100,22 @@ Update( ) // Current update std::string ret = this->_GenerateData( ); + this->m_OutputsDisconnected = false; // Return error description, if any return( ret ); } +// ------------------------------------------------------------------------- +void cpPlugins::Interface::ProcessObject:: +DisconnectOutputs( ) +{ + this->m_OutputsDisconnected = true; + for( unsigned int idx = 0; idx < this->m_Outputs.size( ); ++idx ) + if( this->m_Outputs[ idx ] != NULL ) + this->m_Outputs[ idx ]->GetDataObject( )->DisconnectPipeline( ); +} + // ------------------------------------------------------------------------- itk::DataObject* cpPlugins::Interface::ProcessObject:: _GetInput( unsigned int idx ) @@ -120,7 +131,18 @@ void cpPlugins::Interface::ProcessObject:: _SetOutput( unsigned int idx, itk::DataObject* dobj ) { if( idx < this->m_Outputs.size( ) ) - this->m_Outputs[ idx ].SetDataObject( dobj ); + if( this->m_Outputs[ idx ] != NULL ) + this->m_Outputs[ idx ]->SetDataObject( dobj ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::ProcessObject:: +_DeleteOutputs( ) +{ + if( !( this->m_OutputsDisconnected ) ) + for( unsigned int idx = 0; idx < this->m_Outputs.size( ); ++idx ) + if( this->m_Outputs[ idx ] != NULL ) + delete this->m_Outputs[ idx ]; } // eof - $RCSfile$ diff --git a/lib/cpPlugins/Interface/ProcessObject.h b/lib/cpPlugins/Interface/ProcessObject.h index aa7dea3..4b2adc7 100644 --- a/lib/cpPlugins/Interface/ProcessObject.h +++ b/lib/cpPlugins/Interface/ProcessObject.h @@ -43,10 +43,26 @@ namespace cpPlugins virtual DataObject* GetOutput( unsigned int idx ); virtual std::string Update( ); + virtual void DisconnectOutputs( ); protected: virtual itk::DataObject* _GetInput( unsigned int idx ); virtual void _SetOutput( unsigned int idx, itk::DataObject* dobj ); + virtual void _DeleteOutputs( ); + + template< class O > + void _MakeOutput( unsigned int idx ) + { + if( idx >= this->m_Outputs.size( ) ) + return; + + if( !( this->m_OutputsDisconnected ) ) + if( this->m_Outputs[ idx ] != NULL ) + delete this->m_Outputs[ idx ]; + + this->m_Outputs[ idx ] = new O( ); + } + virtual std::string _GenerateData( ) = 0; protected: @@ -54,7 +70,8 @@ namespace cpPlugins TParameters m_Parameters; std::vector< const DataObject* > m_Inputs; - std::vector< DataObject > m_Outputs; + std::vector< DataObject* > m_Outputs; + bool m_OutputsDisconnected; }; } // ecapseman diff --git a/lib/cpPlugins/Plugins/ImageReader.cxx b/lib/cpPlugins/Plugins/ImageReader.cxx index b232268..2d25301 100644 --- a/lib/cpPlugins/Plugins/ImageReader.cxx +++ b/lib/cpPlugins/Plugins/ImageReader.cxx @@ -1,4 +1,5 @@ #include +#include #include @@ -12,6 +13,7 @@ ImageReader( ) : Superclass( ) { this->SetNumberOfOutputs( 1 ); + this->_MakeOutput< cpPlugins::Interface::Image >( 0 ); this->m_DefaultParameters[ "FileName" ] = TParameter( "string", "no_file_name" );