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