1 #include <cpPlugins/Interface/Image.h>
4 #include <itkRGBPixel.h>
5 #include <itkImageToVTKImageFilter.h>
7 // -------------------------------------------------------------------------
8 #define cpPlugins_Interface_Image_Dimension( d, dobj, func ) \
9 if( dynamic_cast< itk::ImageBase< d >* >( dobj ) != NULL ) \
12 // -------------------------------------------------------------------------
13 #define cpPlugins_Interface_Image_Pixel( p, d, dobj, func ) \
14 if( dynamic_cast< itk::Image< p, d >* >( dobj ) != NULL ) \
17 // -------------------------------------------------------------------------
18 #define cpPlugins_Interface_Image_RGB( p, d, dobj, func ) \
19 if( dynamic_cast< itk::Image< itk::RGBPixel< p >, d >* >( dobj ) != NULL ) \
20 this->func< itk::RGBPixel< p >, d >( )
22 // -------------------------------------------------------------------------
23 cpPlugins::Interface::Image::
26 m_VTKImageData( NULL )
30 // -------------------------------------------------------------------------
31 cpPlugins::Interface::Image::
36 // -------------------------------------------------------------------------
37 std::string cpPlugins::Interface::Image::
40 return( "cpPlugins::Interface::Image" );
43 // -------------------------------------------------------------------------
44 void cpPlugins::Interface::Image::
45 SetDataObject( itk::DataObject* dobj )
47 this->Superclass::SetDataObject( dobj );
49 // WARNING: Only 2 and 3 dimensions at this moment
50 cpPlugins_Interface_Image_Dimension( 2, dobj, _ConnectToVTK_0 );
51 else cpPlugins_Interface_Image_Dimension( 3, dobj, _ConnectToVTK_0 );
54 // -------------------------------------------------------------------------
55 vtkImageData* cpPlugins::Interface::Image::
56 GetVTKImageData( ) const
58 return( this->m_VTKImageData );
61 // -------------------------------------------------------------------------
62 template< unsigned int D >
63 void cpPlugins::Interface::Image::
66 itk::DataObject* dobj = this->Superclass::GetDataObject( );
68 cpPlugins_Interface_Image_Pixel( char, D, dobj, _ConnectToVTK_1 );
69 else cpPlugins_Interface_Image_Pixel( short, D, dobj, _ConnectToVTK_1 );
70 else cpPlugins_Interface_Image_Pixel( int, D, dobj, _ConnectToVTK_1 );
71 else cpPlugins_Interface_Image_Pixel( long, D, dobj, _ConnectToVTK_1 );
72 else cpPlugins_Interface_Image_Pixel( unsigned char, D, dobj, _ConnectToVTK_1 );
73 else cpPlugins_Interface_Image_Pixel( unsigned short, D, dobj, _ConnectToVTK_1 );
74 else cpPlugins_Interface_Image_Pixel( unsigned int, D, dobj, _ConnectToVTK_1 );
75 else cpPlugins_Interface_Image_Pixel( unsigned long, D, dobj, _ConnectToVTK_1 );
76 else cpPlugins_Interface_Image_Pixel( float, D, dobj, _ConnectToVTK_1 );
77 else cpPlugins_Interface_Image_Pixel( double, D, dobj, _ConnectToVTK_1 );
78 else cpPlugins_Interface_Image_RGB( char, D, dobj, _ConnectToVTK_1 );
79 else cpPlugins_Interface_Image_RGB( short, D, dobj, _ConnectToVTK_1 );
80 else cpPlugins_Interface_Image_RGB( int, D, dobj, _ConnectToVTK_1 );
81 else cpPlugins_Interface_Image_RGB( long, D, dobj, _ConnectToVTK_1 );
82 else cpPlugins_Interface_Image_RGB( unsigned char, D, dobj, _ConnectToVTK_1 );
83 else cpPlugins_Interface_Image_RGB( unsigned short, D, dobj, _ConnectToVTK_1 );
84 else cpPlugins_Interface_Image_RGB( unsigned int, D, dobj, _ConnectToVTK_1 );
85 else cpPlugins_Interface_Image_RGB( unsigned long, D, dobj, _ConnectToVTK_1 );
86 else cpPlugins_Interface_Image_RGB( float, D, dobj, _ConnectToVTK_1 );
87 else cpPlugins_Interface_Image_RGB( double, D, dobj, _ConnectToVTK_1 );
90 // -------------------------------------------------------------------------
91 template< class P, unsigned int D >
92 void cpPlugins::Interface::Image::
95 typedef itk::Image< P, D > _TImage;
96 typedef itk::ImageToVTKImageFilter< _TImage > _TFilter;
99 dynamic_cast< _TImage* >( this->Superclass::GetDataObject( ) );
100 typename _TFilter::Pointer filter = _TFilter::New( );
101 filter->SetInput( img );
103 this->m_VTKImageData = filter->GetOutput( );
104 this->m_Image2VTKImageData = filter;