]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/Image.cxx
d8a47c81cb27eb46688d74918d3c04f90fc5a441
[cpPlugins.git] / lib / cpPlugins / Interface / Image.cxx
1 #include <cpPlugins/Interface/Image.h>
2
3 #include <itkImage.h>
4 #include <itkRGBPixel.h>
5 #include <itkImageToVTKImageFilter.h>
6
7 // -------------------------------------------------------------------------
8 #define cpPlugins_Interface_Image_Dimension( d, dobj, func )            \
9   if( dynamic_cast< itk::ImageBase< d >* >( dobj ) != NULL )            \
10     this->func< d >( )
11
12 // -------------------------------------------------------------------------
13 #define cpPlugins_Interface_Image_Pixel( p, d, dobj, func )             \
14   if( dynamic_cast< itk::Image< p, d >* >( dobj ) != NULL )             \
15     this->func< p, d >( )
16
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 >( )
21
22 // -------------------------------------------------------------------------
23 cpPlugins::Interface::Image::
24 Image( )
25   : Superclass( ),
26     m_VTKImageData( NULL )
27 {
28 }
29
30 // -------------------------------------------------------------------------
31 cpPlugins::Interface::Image::
32 ~Image( )
33 {
34 }
35
36 // -------------------------------------------------------------------------
37 std::string cpPlugins::Interface::Image::
38 GetClassName( ) const
39 {
40   return( "cpPlugins::Interface::Image" );
41 }
42
43 // -------------------------------------------------------------------------
44 void cpPlugins::Interface::Image::
45 SetDataObject( itk::DataObject* dobj )
46 {
47   this->Superclass::SetDataObject( dobj );
48   
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 );
52 }
53
54 // -------------------------------------------------------------------------
55 vtkImageData* cpPlugins::Interface::Image::
56 GetVTKImageData( ) const
57 {
58   return( this->m_VTKImageData );
59 }
60
61 // -------------------------------------------------------------------------
62 template< unsigned int D >
63 void cpPlugins::Interface::Image::
64 _ConnectToVTK_0( )
65 {
66   itk::DataObject* dobj = this->Superclass::GetDataObject( );
67
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 );
88 }
89
90 // -------------------------------------------------------------------------
91 template< class P, unsigned int D >
92 void cpPlugins::Interface::Image::
93 _ConnectToVTK_1( )
94 {
95   typedef itk::Image< P, D > _TImage;
96   typedef itk::ImageToVTKImageFilter< _TImage > _TFilter;
97
98   _TImage* img =
99     dynamic_cast< _TImage* >( this->Superclass::GetDataObject( ) );
100   typename _TFilter::Pointer filter = _TFilter::New( );
101   filter->SetInput( img );
102   filter->Update( );
103   this->m_VTKImageData = filter->GetOutput( );
104   this->m_Image2VTKImageData = filter;
105 }
106
107 // eof - $RCSfile$