1 #include <cpPlugins/Interface/Image.h>
3 #define ITK_MANUAL_INSTANTIATION
5 #include <itkRGBPixel.h>
6 #include <itkImageToVTKImageFilter.h>
8 // -------------------------------------------------------------------------
9 #define cpPlugins_Interface_Image_Dimension( d, dobj, func ) \
10 if( dynamic_cast< itk::ImageBase< d >* >( dobj ) != NULL ) \
13 // -------------------------------------------------------------------------
14 #define cpPlugins_Interface_Image_Pixel( p, d, dobj, func ) \
15 if( dynamic_cast< itk::Image< p, d >* >( dobj ) != NULL ) \
18 // -------------------------------------------------------------------------
19 #define cpPlugins_Interface_Image_RGB( p, d, dobj, func ) \
20 if( dynamic_cast< itk::Image< itk::RGBPixel< p >, d >* >( dobj ) != NULL ) \
21 this->func< itk::RGBPixel< p >, d >( )
23 // -------------------------------------------------------------------------
24 cpPlugins::Interface::Image::
27 m_VTKImageData( NULL )
31 // -------------------------------------------------------------------------
32 cpPlugins::Interface::Image::
37 // -------------------------------------------------------------------------
38 std::string cpPlugins::Interface::Image::
41 return( "cpPlugins::Interface::Image" );
44 // -------------------------------------------------------------------------
45 void cpPlugins::Interface::Image::
46 SetDataObject( itk::DataObject* dobj )
48 this->Superclass::SetDataObject( dobj );
50 // WARNING: Only 2 and 3 dimensions at this moment
51 cpPlugins_Interface_Image_Dimension( 2, dobj, _ConnectToVTK_0 );
52 else cpPlugins_Interface_Image_Dimension( 3, dobj, _ConnectToVTK_0 );
55 // -------------------------------------------------------------------------
56 vtkImageData* cpPlugins::Interface::Image::
57 GetVTKImageData( ) const
59 return( this->m_VTKImageData );
62 // -------------------------------------------------------------------------
63 template< unsigned int D >
64 void cpPlugins::Interface::Image::
67 itk::DataObject* dobj = this->Superclass::GetDataObject( );
69 cpPlugins_Interface_Image_Pixel( char, D, dobj, _ConnectToVTK_1 );
70 else cpPlugins_Interface_Image_Pixel( short, D, dobj, _ConnectToVTK_1 );
71 else cpPlugins_Interface_Image_Pixel( int, D, dobj, _ConnectToVTK_1 );
72 else cpPlugins_Interface_Image_Pixel( long, D, dobj, _ConnectToVTK_1 );
73 else cpPlugins_Interface_Image_Pixel( unsigned char, D, dobj, _ConnectToVTK_1 );
74 else cpPlugins_Interface_Image_Pixel( unsigned short, D, dobj, _ConnectToVTK_1 );
75 else cpPlugins_Interface_Image_Pixel( unsigned int, D, dobj, _ConnectToVTK_1 );
76 else cpPlugins_Interface_Image_Pixel( unsigned long, D, dobj, _ConnectToVTK_1 );
77 else cpPlugins_Interface_Image_Pixel( float, D, dobj, _ConnectToVTK_1 );
78 else cpPlugins_Interface_Image_Pixel( double, D, dobj, _ConnectToVTK_1 );
79 else cpPlugins_Interface_Image_RGB( char, D, dobj, _ConnectToVTK_1 );
80 else cpPlugins_Interface_Image_RGB( short, D, dobj, _ConnectToVTK_1 );
81 else cpPlugins_Interface_Image_RGB( int, D, dobj, _ConnectToVTK_1 );
82 else cpPlugins_Interface_Image_RGB( long, D, dobj, _ConnectToVTK_1 );
83 else cpPlugins_Interface_Image_RGB( unsigned char, D, dobj, _ConnectToVTK_1 );
84 else cpPlugins_Interface_Image_RGB( unsigned short, D, dobj, _ConnectToVTK_1 );
85 else cpPlugins_Interface_Image_RGB( unsigned int, D, dobj, _ConnectToVTK_1 );
86 else cpPlugins_Interface_Image_RGB( unsigned long, D, dobj, _ConnectToVTK_1 );
87 else cpPlugins_Interface_Image_RGB( float, D, dobj, _ConnectToVTK_1 );
88 else cpPlugins_Interface_Image_RGB( double, D, dobj, _ConnectToVTK_1 );
91 // -------------------------------------------------------------------------
92 template< class P, unsigned int D >
93 void cpPlugins::Interface::Image::
96 typedef itk::Image< P, D > _TImage;
97 typedef itk::ImageToVTKImageFilter< _TImage > _TFilter;
100 dynamic_cast< _TImage* >( this->Superclass::GetDataObject( ) );
101 typename _TFilter::Pointer filter = _TFilter::New( );
102 filter->SetInput( img );
104 this->m_VTKImageData = filter->GetOutput( );
105 this->m_Image2VTKImageData = filter;