FIND_PATH(
cpPlugins_INCLUDE_DIR2
- cpPlugins/Interface/cpPlugins_Export.h
+ cpPlugins/Interface/cpPlugins_Interface_Export.h
PATHS
/usr/include
/usr/local/include
INCLUDE_DIRECTORIES(
${cpPlugins_INCLUDE_DIR1}
${cpPlugins_INCLUDE_DIR2}
- ${cpPlugins_INCLUDE_DIR2}
+ ${cpPlugins_INCLUDE_DIR3}
)
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$
TARGET_LINK_LIBRARIES(
${LIBRARY_NAME}
cpPlugins_Pluma
+ ${ITK_LIBRARIES}
)
## eof - $RCSfile$
// -------------------------------------------------------------------------
void cpPlugins::Interface::DataObject::
-SetDataObject( itk::DataObject* src )
+SetDataObject( itk::DataObject* dobj )
{
- this->m_DataObject = src;
+ this->m_DataObject = dobj;
}
// -------------------------------------------------------------------------
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 );
#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 )
{
}
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$
#include <cpPlugins/Interface/cpPlugins_Interface_Export.h>
#include <cpPlugins/Interface/DataObject.h>
+class vtkImageData;
+
namespace cpPlugins
{
namespace Interface
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
// -------------------------------------------------------------------------
cpPlugins::Interface::ProcessObject::
ProcessObject( )
- : Superclass( )
+ : Superclass( ),
+ m_OutputsDisconnected( false )
{
}
cpPlugins::Interface::ProcessObject::
~ProcessObject( )
{
+ this->_DeleteOutputs( );
}
// -------------------------------------------------------------------------
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;
}
// -------------------------------------------------------------------------
GetOutput( unsigned int idx )
{
if( idx < this->m_Outputs.size( ) )
- return( &( this->m_Outputs[ idx ] ) );
+ return( this->m_Outputs[ idx ] );
else
return( NULL );
}
// 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 )
_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$
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:
TParameters m_Parameters;
std::vector< const DataObject* > m_Inputs;
- std::vector< DataObject > m_Outputs;
+ std::vector< DataObject* > m_Outputs;
+ bool m_OutputsDisconnected;
};
} // ecapseman
#include <cpPlugins/Plugins/ImageReader.h>
+#include <cpPlugins/Interface/Image.h>
#include <itkImageFileReader.h>
: Superclass( )
{
this->SetNumberOfOutputs( 1 );
+ this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
this->m_DefaultParameters[ "FileName" ] =
TParameter( "string", "no_file_name" );