]> Creatis software - cpPlugins.git/commitdiff
Integration of new functionalities into ProcessObject and DataObject
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 9 Dec 2014 17:44:34 +0000 (18:44 +0100)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 9 Dec 2014 17:44:34 +0000 (18:44 +0100)
cmake/cpPluginsConfig.cmake.in
lib/cpPlugins/Interface/CMakeLists.txt
lib/cpPlugins/Interface/DataObject.cxx
lib/cpPlugins/Interface/DataObject.h
lib/cpPlugins/Interface/Image.cxx
lib/cpPlugins/Interface/Image.h
lib/cpPlugins/Interface/ProcessObject.cxx
lib/cpPlugins/Interface/ProcessObject.h
lib/cpPlugins/Plugins/ImageReader.cxx

index bb9819a928367f60029a8b4fbf400d9cfc9a95fd..a31bc50f8a57827d65783e2f346623947cc163f2 100644 (file)
@@ -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$
index e51b0ef7c3ccebe4cdd2187f6a7817a823c03d89..0ee961e87652f137d5c1e923e7a18a72559c0650 100644 (file)
@@ -32,6 +32,7 @@ GENERATE_EXPORT_HEADER(
 TARGET_LINK_LIBRARIES(
   ${LIBRARY_NAME}
   cpPlugins_Pluma
+  ${ITK_LIBRARIES}
   )
 
 ## eof - $RCSfile$
index 9c15346370e3d4b970f3672208fa802d5133c7e5..4ec6223b6096d995f662b45e276311ae598035f7 100644 (file)
@@ -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;
 }
 
 // -------------------------------------------------------------------------
index c08365463e5e9a8abf736a85a4df4f90bf1da078..9edf92b0cb30502e143ea386154f6b48e6c85432 100644 (file)
@@ -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 );
index 9b55ed27d17cea446ab6e26a8a325ea3ca9905f7..d8a47c81cb27eb46688d74918d3c04f90fc5a441 100644 (file)
@@ -1,9 +1,29 @@
 #include <cpPlugins/Interface/Image.h>
 
+#include <itkImage.h>
+#include <itkRGBPixel.h>
+#include <itkImageToVTKImageFilter.h>
+
+// -------------------------------------------------------------------------
+#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$
index cbdc219f7590e296f375204abbaffc360e35b323..e6b2b7762708360c5781af9651fe1f6ffc91212d 100644 (file)
@@ -7,6 +7,8 @@
 #include <cpPlugins/Interface/cpPlugins_Interface_Export.h>
 #include <cpPlugins/Interface/DataObject.h>
 
+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
index 79fc2ab7f84880c3cdb59bdd002d38e8abc94f34..a595e0ec3f71d60df5c583d4d7d9b29bd72d0696 100644 (file)
@@ -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$
index aa7dea35fbf39d724e74ea8d066b27593f0518c4..4b2adc7db5c35e3fe962e37a7bdb1c5928d91774 100644 (file)
@@ -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
index b232268917881a0a99c36e52aa2f45f5e9d64112..2d25301b04ba35fcbba36d0dc1b32b04ef706e1f 100644 (file)
@@ -1,4 +1,5 @@
 #include <cpPlugins/Plugins/ImageReader.h>
+#include <cpPlugins/Interface/Image.h>
 
 #include <itkImageFileReader.h>
 
@@ -12,6 +13,7 @@ ImageReader( )
   : Superclass( )
 {
   this->SetNumberOfOutputs( 1 );
+  this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
 
   this->m_DefaultParameters[ "FileName" ] =
     TParameter( "string", "no_file_name" );