1 #ifndef __CPPLUGINS__INTERFACE__IMAGE__HXX__
2 #define __CPPLUGINS__INTERFACE__IMAGE__HXX__
4 #include <cpPlugins/Interface/Macros.h>
7 #include <itkImageToVTKImageFilter.h>
9 #include <itkCovariantVector.h>
10 #include <itkDiffusionTensor3D.h>
12 #include <itkRGBPixel.h>
13 #include <itkRGBAPixel.h>
14 #include <itkSymmetricSecondRankTensor.h>
15 #include <itkVector.h>
17 // -------------------------------------------------------------------------
18 #define cpPlugins_Image_Demangle( TI, T, D, o ) \
19 if( typeid( typename TI::PixelType ) == typeid( T ) ) \
20 this->_ITK_2_VTK< T, D >( o )
22 // -------------------------------------------------------------------------
23 #define cpPlugins_ImageArray_Demangle( TI, T, P, DP, DI, o ) \
24 if( typeid( typename TI::PixelType ) == typeid( T< P, DP > ) ) \
25 this->_ITK_2_VTK< T< P, DP >, DI >( o )
27 // -------------------------------------------------------------------------
28 #define cpPlugins_Image_Demangle_Dimension( TI, D, o ) \
29 cpPlugins_Image_Demangle( TI, char, D, o ); \
30 else cpPlugins_Image_Demangle( TI, short, D, o ); \
31 else cpPlugins_Image_Demangle( TI, int, D, o ); \
32 else cpPlugins_Image_Demangle( TI, long, D, o ); \
33 else cpPlugins_Image_Demangle( TI, float, D, o ); \
34 else cpPlugins_Image_Demangle( TI, double, D, o ); \
35 else cpPlugins_Image_Demangle( TI, unsigned char, D, o ); \
36 else cpPlugins_Image_Demangle( TI, unsigned short, D, o ); \
37 else cpPlugins_Image_Demangle( TI, unsigned int, D, o ); \
38 else cpPlugins_Image_Demangle( TI, unsigned long, D, o ); \
39 else cpPlugins_Image_Demangle( TI, itk::RGBPixel< char >, D, o ); \
40 else cpPlugins_Image_Demangle( TI, itk::RGBPixel< short >, D, o ); \
41 else cpPlugins_Image_Demangle( \
42 TI, itk::RGBPixel< unsigned char >, D, o \
44 else cpPlugins_Image_Demangle( \
45 TI, itk::RGBPixel< unsigned short >, D, o \
47 else cpPlugins_Image_Demangle( TI, itk::RGBAPixel< char >, D, o ); \
48 else cpPlugins_Image_Demangle( TI, itk::RGBAPixel< short >, D, o ); \
49 else cpPlugins_Image_Demangle( \
50 TI, itk::RGBAPixel< unsigned char >, D, o \
52 else cpPlugins_Image_Demangle( \
53 TI, itk::RGBAPixel< unsigned short >, D, o \
55 else cpPlugins_ImageArray_Demangle( \
56 TI, itk::Vector, float, D, D, o \
58 else cpPlugins_ImageArray_Demangle( \
59 TI, itk::Vector, double, D, D, o \
61 else cpPlugins_ImageArray_Demangle( \
62 TI, itk::CovariantVector, float, D, D, o \
64 else cpPlugins_ImageArray_Demangle( \
65 TI, itk::CovariantVector, double, D, D, o \
67 else cpPlugins_ImageArray_Demangle( TI, itk::Point, float, D, D, o ); \
68 else cpPlugins_ImageArray_Demangle( \
69 TI, itk::Point, double, D, D, o \
71 else cpPlugins_ImageArray_Demangle( \
72 TI, itk::SymmetricSecondRankTensor, float, D, D, o \
74 else cpPlugins_ImageArray_Demangle( \
75 TI, itk::SymmetricSecondRankTensor, double, D, D, o \
78 // -------------------------------------------------------------------------
79 #define cpPlugins_Image_Import( T, D ) \
80 cpPlugins_TEMPLATE_IMPORT( \
81 2(class cpPlugins_Interface_EXPORT itk::Image< T, D >) \
84 // -------------------------------------------------------------------------
85 #define cpPlugins_VTKImage_Import( T, D ) \
86 cpPlugins_TEMPLATE_IMPORT( \
88 class cpPlugins_Interface_EXPORT \
89 itk::ImageToVTKImageFilter< itk::Image< T, D > > \
93 // -------------------------------------------------------------------------
94 #define cpPlugins_ImageArray_Import( A, T, DA, DI ) \
95 cpPlugins_TEMPLATE_IMPORT( \
97 class cpPlugins_Interface_EXPORT \
98 itk::Image< itk::A< T, DA >, DI > \
102 // -------------------------------------------------------------------------
103 #define cpPlugins_VTKImageArray_Import( A, T, DA, DI ) \
104 cpPlugins_TEMPLATE_IMPORT( \
106 class cpPlugins_Interface_EXPORT \
107 itk::ImageToVTKImageFilter< itk::Image< itk::A< T, DA >, DI > > \
111 // -------------------------------------------------------------------------
112 #define cpPlugins_Image_Import_AllDimensions( T ) \
113 cpPlugins_Image_Import( T, 2 ); \
114 cpPlugins_Image_Import( T, 3 ); \
115 cpPlugins_Image_Import( T, 4 )
117 // -------------------------------------------------------------------------
118 #define cpPlugins_VTKImage_Import_AllDimensions( T ) \
119 cpPlugins_VTKImage_Import( T, 2 ); \
120 cpPlugins_VTKImage_Import( T, 3 )
122 // -------------------------------------------------------------------------
123 #define cpPlugins_ImageArray_Import_AllDimensions( A, T ) \
124 cpPlugins_ImageArray_Import( A, T, 2, 2 ); \
125 cpPlugins_ImageArray_Import( A, T, 3, 3 ); \
126 cpPlugins_ImageArray_Import( A, T, 4, 4 )
128 // -------------------------------------------------------------------------
129 #define cpPlugins_VTKImageArray_Import_AllDimensions( A, T ) \
130 cpPlugins_VTKImageArray_Import( A, T, 2, 2 ); \
131 cpPlugins_VTKImageArray_Import( A, T, 3, 3 )
133 // -------------------------------------------------------------------------
135 cpPlugins_Image_Import_AllDimensions( char );
136 cpPlugins_Image_Import_AllDimensions( short );
137 cpPlugins_Image_Import_AllDimensions( int );
138 cpPlugins_Image_Import_AllDimensions( long );
139 cpPlugins_Image_Import_AllDimensions( unsigned char );
140 cpPlugins_Image_Import_AllDimensions( unsigned short );
141 cpPlugins_Image_Import_AllDimensions( unsigned int );
142 cpPlugins_Image_Import_AllDimensions( unsigned long );
143 cpPlugins_Image_Import_AllDimensions( float );
144 cpPlugins_Image_Import_AllDimensions( double );
146 cpPlugins_Image_Import_AllDimensions( std::complex< float > );
147 cpPlugins_Image_Import_AllDimensions( std::complex< double > );
149 cpPlugins_Image_Import_AllDimensions( itk::RGBPixel< char > );
150 cpPlugins_Image_Import_AllDimensions( itk::RGBPixel< short > );
151 cpPlugins_Image_Import_AllDimensions( itk::RGBPixel< int > );
152 cpPlugins_Image_Import_AllDimensions( itk::RGBPixel< long > );
153 cpPlugins_Image_Import_AllDimensions( itk::RGBPixel< unsigned char > );
154 cpPlugins_Image_Import_AllDimensions( itk::RGBPixel< unsigned short > );
155 cpPlugins_Image_Import_AllDimensions( itk::RGBPixel< unsigned int > );
156 cpPlugins_Image_Import_AllDimensions( itk::RGBPixel< unsigned long > );
158 cpPlugins_Image_Import_AllDimensions( itk::RGBAPixel< char > );
159 cpPlugins_Image_Import_AllDimensions( itk::RGBAPixel< short > );
160 cpPlugins_Image_Import_AllDimensions( itk::RGBAPixel< int > );
161 cpPlugins_Image_Import_AllDimensions( itk::RGBAPixel< long > );
162 cpPlugins_Image_Import_AllDimensions( itk::RGBAPixel< unsigned char > );
163 cpPlugins_Image_Import_AllDimensions( itk::RGBAPixel< unsigned short > );
164 cpPlugins_Image_Import_AllDimensions( itk::RGBAPixel< unsigned int > );
165 cpPlugins_Image_Import_AllDimensions( itk::RGBAPixel< unsigned long > );
167 cpPlugins_ImageArray_Import_AllDimensions( Vector, float );
168 cpPlugins_ImageArray_Import_AllDimensions( Vector, double );
170 cpPlugins_ImageArray_Import_AllDimensions( CovariantVector, float );
171 cpPlugins_ImageArray_Import_AllDimensions( CovariantVector, double );
173 cpPlugins_ImageArray_Import_AllDimensions( Point, float );
174 cpPlugins_ImageArray_Import_AllDimensions( Point, double );
176 cpPlugins_ImageArray_Import_AllDimensions(
177 SymmetricSecondRankTensor, float
179 cpPlugins_ImageArray_Import_AllDimensions(
180 SymmetricSecondRankTensor, double
183 cpPlugins_Image_Import( itk::DiffusionTensor3D< float >, 3 );
184 cpPlugins_Image_Import( itk::DiffusionTensor3D< double >, 3 );
185 cpPlugins_Image_Import( itk::Offset< 2 >, 2 );
186 cpPlugins_Image_Import( itk::Offset< 3 >, 3 );
187 cpPlugins_Image_Import( itk::Offset< 4 >, 4 );
189 // -------------------------------------------------------------------------
190 // ITK<->VTK base clases
191 cpPlugins_VTKImage_Import_AllDimensions( char );
192 cpPlugins_VTKImage_Import_AllDimensions( short );
193 cpPlugins_VTKImage_Import_AllDimensions( int );
194 cpPlugins_VTKImage_Import_AllDimensions( long );
195 cpPlugins_VTKImage_Import_AllDimensions( unsigned char );
196 cpPlugins_VTKImage_Import_AllDimensions( unsigned short );
197 cpPlugins_VTKImage_Import_AllDimensions( unsigned int );
198 cpPlugins_VTKImage_Import_AllDimensions( unsigned long );
199 cpPlugins_VTKImage_Import_AllDimensions( float );
200 cpPlugins_VTKImage_Import_AllDimensions( double );
202 cpPlugins_VTKImage_Import_AllDimensions( itk::RGBPixel< char > );
203 cpPlugins_VTKImage_Import_AllDimensions( itk::RGBPixel< short > );
204 cpPlugins_VTKImage_Import_AllDimensions( itk::RGBPixel< int > );
205 cpPlugins_VTKImage_Import_AllDimensions( itk::RGBPixel< long > );
206 cpPlugins_VTKImage_Import_AllDimensions( itk::RGBPixel< unsigned char > );
207 cpPlugins_VTKImage_Import_AllDimensions( itk::RGBPixel< unsigned short > );
208 cpPlugins_VTKImage_Import_AllDimensions( itk::RGBPixel< unsigned int > );
209 cpPlugins_VTKImage_Import_AllDimensions( itk::RGBPixel< unsigned long > );
211 cpPlugins_VTKImage_Import_AllDimensions( itk::RGBAPixel< char > );
212 cpPlugins_VTKImage_Import_AllDimensions( itk::RGBAPixel< short > );
213 cpPlugins_VTKImage_Import_AllDimensions( itk::RGBAPixel< int > );
214 cpPlugins_VTKImage_Import_AllDimensions( itk::RGBAPixel< long > );
215 cpPlugins_VTKImage_Import_AllDimensions( itk::RGBAPixel< unsigned char > );
216 cpPlugins_VTKImage_Import_AllDimensions( itk::RGBAPixel< unsigned short > );
217 cpPlugins_VTKImage_Import_AllDimensions( itk::RGBAPixel< unsigned int > );
218 cpPlugins_VTKImage_Import_AllDimensions( itk::RGBAPixel< unsigned long > );
220 cpPlugins_VTKImageArray_Import_AllDimensions( Vector, float );
221 cpPlugins_VTKImageArray_Import_AllDimensions( Vector, double );
223 cpPlugins_VTKImageArray_Import_AllDimensions( CovariantVector, float );
224 cpPlugins_VTKImageArray_Import_AllDimensions( CovariantVector, double );
226 cpPlugins_VTKImageArray_Import_AllDimensions( Point, float );
227 cpPlugins_VTKImageArray_Import_AllDimensions( Point, double );
229 cpPlugins_VTKImageArray_Import_AllDimensions(
230 SymmetricSecondRankTensor, float
232 cpPlugins_VTKImageArray_Import_AllDimensions(
233 SymmetricSecondRankTensor, double
236 cpPlugins_VTKImage_Import( itk::DiffusionTensor3D< float >, 3 );
237 cpPlugins_VTKImage_Import( itk::DiffusionTensor3D< double >, 3 );
239 // -------------------------------------------------------------------------
241 void cpPlugins::Interface::Image::
242 SetITKImage( itk::DataObject* object )
244 // Check if input object has the desired type
245 I* image = dynamic_cast< I* >( object );
248 this->m_ITKObject = NULL;
249 this->m_VTKObject = NULL;
250 this->m_ITKvVTKConnection = NULL;
256 if( I::ImageDimension == 2 )
258 cpPlugins_Image_Demangle_Dimension( I, 2, object );
261 this->m_VTKObject = NULL;
262 this->m_ITKvVTKConnection = NULL;
266 else if( I::ImageDimension == 3 )
268 cpPlugins_Image_Demangle_Dimension( I, 3, object );
269 else cpPlugins_Image_Demangle(
270 I, itk::DiffusionTensor3D< float >, 3, object
272 else cpPlugins_Image_Demangle(
273 I, itk::DiffusionTensor3D< double >, 3, object
277 this->m_VTKObject = NULL;
278 this->m_ITKvVTKConnection = NULL;
284 this->m_VTKObject = NULL;
285 this->m_ITKvVTKConnection = NULL;
290 this->m_ITKObject = object;
294 // -------------------------------------------------------------------------
296 I* cpPlugins::Interface::Image::
299 return( dynamic_cast< I* >( this->m_ITKObject.GetPointer( ) ) );
302 // -------------------------------------------------------------------------
304 const I* cpPlugins::Interface::Image::
307 return( dynamic_cast< const I* >( this->m_ITKObject.GetPointer( ) ) );
310 // -------------------------------------------------------------------------
311 template< class P, unsigned int D >
312 void cpPlugins::Interface::Image::
313 _ITK_2_VTK( itk::DataObject* object )
315 typedef itk::Image< P, D > _I;
317 // Check if input object has the desired type
318 _I* image = dynamic_cast< _I* >( object );
323 typename itk::ImageToVTKImageFilter< _I >::Pointer f =
324 itk::ImageToVTKImageFilter< _I >::New( );
325 f->SetInput( image );
329 this->m_VTKObject = f->GetOutput( );
330 this->m_ITKvVTKConnection = f;
333 #endif // __CPPLUGINS__INTERFACE__IMAGE__HXX__