]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/Image.hxx
Widget integration (step 3/6). WARNING: IT DOES NOT COMPILE YET
[cpPlugins.git] / lib / cpPlugins / Interface / Image.hxx
1 #ifndef __CPPLUGINS__INTERFACE__IMAGE__HXX__
2 #define __CPPLUGINS__INTERFACE__IMAGE__HXX__
3
4 #include <cpPlugins/Interface/Macros.h>
5
6 #include <complex>
7
8 #include <itkImage.h>
9 #include <itkVectorImage.h>
10 #include <itkImageToVTKImageFilter.h>
11
12 #include <itkCovariantVector.h>
13 #include <itkDiffusionTensor3D.h>
14 #include <itkPoint.h>
15 #include <itkRGBPixel.h>
16 #include <itkRGBAPixel.h>
17 #include <itkSymmetricSecondRankTensor.h>
18 #include <itkVector.h>
19
20 // -------------------------------------------------------------------------
21 #define cpPlugins_VTKImage_Demangle( TI, T, D, o )              \
22   if( typeid( TI ) == typeid( itk::Image< T, D > ) )            \
23     this->_ITK_2_VTK< T, D >( o )
24
25 // -------------------------------------------------------------------------
26 #define cpPlugins_VTKImageArray_Demangle( TI, T, P, DP, DI, o )      \
27   if( typeid( TI ) == typeid( itk::Image< T< P, DP >, DI > ) )       \
28     this->_ITK_2_VTK< T< P, DP >, DI >( o )
29
30 // -------------------------------------------------------------------------
31 #define cpPlugins_VTKImage_Demangle_AllDims( TI, T, o )         \
32   cpPlugins_VTKImage_Demangle( TI, T, 2, o );                   \
33   else cpPlugins_VTKImage_Demangle( TI, T, 3, o )
34
35 // -------------------------------------------------------------------------
36 #define cpPlugins_VTKImageArray_Demangle_AllDims( TI, T, P, o )      \
37   cpPlugins_VTKImageArray_Demangle( TI, T, P, 2, 2, o );             \
38   else cpPlugins_VTKImageArray_Demangle( TI, T, P, 3, 3, o )
39
40 // -------------------------------------------------------------------------
41 template< class I >
42 void cpPlugins::Interface::Image::
43 SetITK( itk::Object* object )
44 {
45   // Check if input object has the desired type
46   I* image = dynamic_cast< I* >( object );
47   if( image == NULL )
48   {
49     this->m_ITKObject = NULL;
50     this->m_VTKObject = NULL;
51     this->m_ITKvVTKConnection = NULL;
52     this->Modified( );
53
54   } // fi
55
56   // Connect it to VTK
57   cpPlugins_VTKImage_Demangle_AllDims( I, char, image );
58   else cpPlugins_VTKImage_Demangle_AllDims( I, short, image );
59   else cpPlugins_VTKImage_Demangle_AllDims( I, int, image );
60   else cpPlugins_VTKImage_Demangle_AllDims( I, long, image );
61   else cpPlugins_VTKImage_Demangle_AllDims( I, unsigned char, image );
62   else cpPlugins_VTKImage_Demangle_AllDims( I, unsigned short, image );
63   else cpPlugins_VTKImage_Demangle_AllDims( I, unsigned int, image );
64   else cpPlugins_VTKImage_Demangle_AllDims( I, unsigned long, image );
65   else cpPlugins_VTKImage_Demangle_AllDims( I, float, image );
66   else cpPlugins_VTKImage_Demangle_AllDims( I, double, image );
67   else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBPixel< char >, image );
68   else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBPixel< short >, image );
69   else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBPixel< int >, image );
70   else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBPixel< long >, image );
71   else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBPixel< unsigned char >, image );
72   else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBPixel< unsigned short >, image );
73   else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBPixel< unsigned int >, image );
74   else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBPixel< unsigned long >, image );
75   else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBPixel< float >, image );
76   else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBPixel< double >, image );
77   else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBAPixel< char >, image );
78   else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBAPixel< short >, image );
79   else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBAPixel< int >, image );
80   else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBAPixel< long >, image );
81   else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBAPixel< unsigned char >, image );
82   else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBAPixel< unsigned short >, image );
83   else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBAPixel< unsigned int >, image );
84   else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBAPixel< unsigned long >, image );
85   else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBAPixel< float >, image );
86   else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBAPixel< double >, image );
87   else cpPlugins_VTKImage_Demangle_AllDims( I, itk::DiffusionTensor3D< float >, image );
88   else cpPlugins_VTKImage_Demangle_AllDims( I, itk::DiffusionTensor3D< double >, image );
89   else cpPlugins_VTKImageArray_Demangle_AllDims( I, itk::Vector, float, image );
90   else cpPlugins_VTKImageArray_Demangle_AllDims( I, itk::Vector, double, image );
91   else cpPlugins_VTKImageArray_Demangle_AllDims( I, itk::CovariantVector, float, image );
92   else cpPlugins_VTKImageArray_Demangle_AllDims( I, itk::CovariantVector, double, image );
93   else cpPlugins_VTKImageArray_Demangle_AllDims( I, itk::Point, float, image );
94   else cpPlugins_VTKImageArray_Demangle_AllDims( I, itk::Point, double, image );
95   else cpPlugins_VTKImageArray_Demangle_AllDims( I, itk::SymmetricSecondRankTensor, float, image );
96   else cpPlugins_VTKImageArray_Demangle_AllDims( I, itk::SymmetricSecondRankTensor, double, image );
97   else
98   {
99     this->m_VTKObject = NULL;
100     this->m_ITKvVTKConnection = NULL;
101
102   } // fi
103
104   // Keep objects
105   this->m_ITKObject = object;
106   this->Modified( );
107 }
108
109 // -------------------------------------------------------------------------
110 template< class P, unsigned int D >
111 void cpPlugins::Interface::Image::
112 _ITK_2_VTK( itk::Object* object )
113 {
114   typedef itk::Image< P, D > _I;
115
116   // Check if input object has the desired type
117   _I* image = dynamic_cast< _I* >( object );
118   if( image == NULL )
119     return;
120
121   // Connect it to VTK
122   typename itk::ImageToVTKImageFilter< _I >::Pointer f =
123     itk::ImageToVTKImageFilter< _I >::New( );
124   f->SetInput( image );
125   f->Update( );
126
127   // Keep objects
128   this->m_VTKObject = f->GetOutput( );
129   this->m_ITKvVTKConnection = f;
130 }
131
132 #ifndef cpPlugins_Interface_EXPORTS
133
134 // =========================================================================
135 // ==========           Declare import itk::Image types           ==========
136 // =========================================================================
137
138 // -------------------------------------------------------------------------
139 #define cpPlugins_ITKImage_Import( T, D )                       \
140   cpPlugins_TEMPLATE_IMPORT(                                    \
141     2(class cpPlugins_Interface_EXPORT itk::Image< T, D >)      \
142     )
143
144 // -------------------------------------------------------------------------
145 #define cpPlugins_ITKArrayImage_Import( A, T, DA, DI )                  \
146   cpPlugins_TEMPLATE_IMPORT(                                            \
147     3(class cpPlugins_Interface_EXPORT itk::Image< A< T, DA >, DI >)    \
148     )
149
150 // -------------------------------------------------------------------------
151 #define cpPlugins_ITKImage_AllDims_Import( T )  \
152   cpPlugins_ITKImage_Import( T, 2 );            \
153   cpPlugins_ITKImage_Import( T, 3 );            \
154   cpPlugins_ITKImage_Import( T, 4 )
155
156 // -------------------------------------------------------------------------
157 #define cpPlugins_ITKArrayImage_AllDims_Import( A, T )  \
158   cpPlugins_ITKArrayImage_Import( A, T, 2, 2 );         \
159   cpPlugins_ITKArrayImage_Import( A, T, 3, 3 );         \
160   cpPlugins_ITKArrayImage_Import( A, T, 4, 4 )
161
162 // -------------------------------------------------------------------------
163 #define cpPlugins_VTKImage_Import( T, D )               \
164   cpPlugins_TEMPLATE_IMPORT(                            \
165     2(                                                  \
166       class cpPlugins_Interface_EXPORT                  \
167       itk::ImageToVTKImageFilter< itk::Image< T, D > >  \
168       )                                                 \
169     )
170
171 // -------------------------------------------------------------------------
172 #define cpPlugins_VTKArrayImage_Import( A, T, DA, DI )                  \
173   cpPlugins_TEMPLATE_IMPORT(                                            \
174     3(class                                                             \
175       cpPlugins_Interface_EXPORT                                        \
176       itk::ImageToVTKImageFilter< itk::Image< A< T, DA >, DI > >)       \
177     )
178
179 // -------------------------------------------------------------------------
180 #define cpPlugins_VTKImage_AllDims_Import( T )  \
181   cpPlugins_VTKImage_Import( T, 2 );            \
182   cpPlugins_VTKImage_Import( T, 3 )
183
184 // -------------------------------------------------------------------------
185 #define cpPlugins_VTKArrayImage_AllDims_Import( A, T )  \
186   cpPlugins_VTKArrayImage_Import( A, T, 2, 2 );         \
187   cpPlugins_VTKArrayImage_Import( A, T, 3, 3 )
188
189 // -------------------------------------------------------------------------
190 #define cpPlugins_Image_Import( T, D )          \
191   cpPlugins_ITKImage_Import( T, D );            \
192   cpPlugins_VTKImage_Import( T, D )             \
193   
194 // -------------------------------------------------------------------------
195 #define cpPlugins_Image_AllDims_Import( T )     \
196   cpPlugins_ITKImage_AllDims_Import( T );       \
197   cpPlugins_VTKImage_AllDims_Import( T )        \
198   
199 // -------------------------------------------------------------------------
200 #define cpPlugins_ArrayImage_AllDims_Import( A, T )     \
201   cpPlugins_ITKArrayImage_AllDims_Import( A, T );       \
202   cpPlugins_VTKArrayImage_AllDims_Import( A, T )        \
203   
204 // -------------------------------------------------------------------------
205 // ITK-VTK base clases
206 // -------------------------------------------------------------------------
207
208 cpPlugins_Image_AllDims_Import( char );
209 cpPlugins_Image_AllDims_Import( short );
210 cpPlugins_Image_AllDims_Import( int );
211 cpPlugins_Image_AllDims_Import( long );
212 cpPlugins_Image_AllDims_Import( unsigned char );
213 cpPlugins_Image_AllDims_Import( unsigned short );
214 cpPlugins_Image_AllDims_Import( unsigned int );
215 cpPlugins_Image_AllDims_Import( unsigned long );
216 cpPlugins_Image_AllDims_Import( float );
217 cpPlugins_Image_AllDims_Import( double );
218
219 cpPlugins_Image_AllDims_Import( itk::RGBPixel< char > );
220 cpPlugins_Image_AllDims_Import( itk::RGBPixel< short > );
221 cpPlugins_Image_AllDims_Import( itk::RGBPixel< int > );
222 cpPlugins_Image_AllDims_Import( itk::RGBPixel< long > );
223 cpPlugins_Image_AllDims_Import( itk::RGBPixel< unsigned char > );
224 cpPlugins_Image_AllDims_Import( itk::RGBPixel< unsigned short > );
225 cpPlugins_Image_AllDims_Import( itk::RGBPixel< unsigned int > );
226 cpPlugins_Image_AllDims_Import( itk::RGBPixel< unsigned long > );
227 cpPlugins_Image_AllDims_Import( itk::RGBPixel< float > );
228 cpPlugins_Image_AllDims_Import( itk::RGBPixel< double > );
229
230 cpPlugins_Image_AllDims_Import( itk::RGBAPixel< char > );
231 cpPlugins_Image_AllDims_Import( itk::RGBAPixel< short > );
232 cpPlugins_Image_AllDims_Import( itk::RGBAPixel< int > );
233 cpPlugins_Image_AllDims_Import( itk::RGBAPixel< long > );
234 cpPlugins_Image_AllDims_Import( itk::RGBAPixel< unsigned char > );
235 cpPlugins_Image_AllDims_Import( itk::RGBAPixel< unsigned short > );
236 cpPlugins_Image_AllDims_Import( itk::RGBAPixel< unsigned int > );
237 cpPlugins_Image_AllDims_Import( itk::RGBAPixel< unsigned long > );
238 cpPlugins_Image_AllDims_Import( itk::RGBAPixel< float > );
239 cpPlugins_Image_AllDims_Import( itk::RGBAPixel< double > );
240
241 cpPlugins_Image_AllDims_Import( itk::DiffusionTensor3D< float > );
242 cpPlugins_Image_AllDims_Import( itk::DiffusionTensor3D< double > );
243
244 cpPlugins_ArrayImage_AllDims_Import( itk::Vector, float );
245 cpPlugins_ArrayImage_AllDims_Import( itk::Vector, double );
246
247 cpPlugins_ArrayImage_AllDims_Import( itk::CovariantVector, float );
248 cpPlugins_ArrayImage_AllDims_Import( itk::CovariantVector, double );
249
250 cpPlugins_ArrayImage_AllDims_Import( itk::Point, float );
251 cpPlugins_ArrayImage_AllDims_Import( itk::Point, double );
252
253 cpPlugins_ArrayImage_AllDims_Import( itk::SymmetricSecondRankTensor, float );
254 cpPlugins_ArrayImage_AllDims_Import( itk::SymmetricSecondRankTensor, double );
255
256 // -------------------------------------------------------------------------
257 // ITK-only base clases
258 // -------------------------------------------------------------------------
259
260 cpPlugins_ITKImage_AllDims_Import( std::complex< float > );
261 cpPlugins_ITKImage_AllDims_Import( std::complex< double > );
262
263 cpPlugins_ITKImage_Import( itk::Offset< 2 >, 2 );
264 cpPlugins_ITKImage_Import( itk::Offset< 3 >, 3 );
265 cpPlugins_ITKImage_Import( itk::Offset< 4 >, 4 );
266
267 // =========================================================================
268 // ==========        Declare import itk::VectorImage types        ==========
269 // =========================================================================
270
271 // -------------------------------------------------------------------------
272 #define cpPlugins_VectorImage_Import( T, D )                            \
273   cpPlugins_TEMPLATE_IMPORT(                                            \
274     2(class cpPlugins_Interface_EXPORT itk::VectorImage< T, D >)        \
275     )
276
277 // -------------------------------------------------------------------------
278 #define cpPlugins_ArrayVectorImage_Import( A, T, DA, DI )               \
279   cpPlugins_TEMPLATE_IMPORT(                                            \
280     3(class                                                             \
281       cpPlugins_Interface_EXPORT                                        \
282       itk::VectorImage< A< T, DA >, DI >)                               \
283     )
284
285 // -------------------------------------------------------------------------
286 #define cpPlugins_VectorImage_AllDims_Import( T )  \
287   cpPlugins_VectorImage_Import( T, 2 );            \
288   cpPlugins_VectorImage_Import( T, 3 );            \
289   cpPlugins_VectorImage_Import( T, 4 )
290
291 // -------------------------------------------------------------------------
292 #define cpPlugins_ArrayVectorImage_AllDims_Import( A, T )     \
293   cpPlugins_ArrayVectorImage_Import( A, T, 2, 2 );            \
294   cpPlugins_ArrayVectorImage_Import( A, T, 3, 3 );            \
295   cpPlugins_ArrayVectorImage_Import( A, T, 4, 4 )
296
297 // -------------------------------------------------------------------------
298 // ITK-VTK base clases
299 // -------------------------------------------------------------------------
300
301 cpPlugins_VectorImage_AllDims_Import( char );
302 cpPlugins_VectorImage_AllDims_Import( short );
303 cpPlugins_VectorImage_AllDims_Import( int );
304 cpPlugins_VectorImage_AllDims_Import( long );
305 cpPlugins_VectorImage_AllDims_Import( unsigned char );
306 cpPlugins_VectorImage_AllDims_Import( unsigned short );
307 cpPlugins_VectorImage_AllDims_Import( unsigned int );
308 cpPlugins_VectorImage_AllDims_Import( unsigned long );
309 cpPlugins_VectorImage_AllDims_Import( float );
310 cpPlugins_VectorImage_AllDims_Import( double );
311
312 cpPlugins_VectorImage_AllDims_Import( std::complex< float > );
313 cpPlugins_VectorImage_AllDims_Import( std::complex< double > );
314
315 cpPlugins_VectorImage_Import( itk::Offset< 2 >, 2 );
316 cpPlugins_VectorImage_Import( itk::Offset< 3 >, 3 );
317 cpPlugins_VectorImage_Import( itk::Offset< 4 >, 4 );
318
319 cpPlugins_VectorImage_AllDims_Import( itk::RGBPixel< char > );
320 cpPlugins_VectorImage_AllDims_Import( itk::RGBPixel< short > );
321 cpPlugins_VectorImage_AllDims_Import( itk::RGBPixel< int > );
322 cpPlugins_VectorImage_AllDims_Import( itk::RGBPixel< long > );
323 cpPlugins_VectorImage_AllDims_Import( itk::RGBPixel< unsigned char > );
324 cpPlugins_VectorImage_AllDims_Import( itk::RGBPixel< unsigned short > );
325 cpPlugins_VectorImage_AllDims_Import( itk::RGBPixel< unsigned int > );
326 cpPlugins_VectorImage_AllDims_Import( itk::RGBPixel< unsigned long > );
327 cpPlugins_VectorImage_AllDims_Import( itk::RGBPixel< float > );
328 cpPlugins_VectorImage_AllDims_Import( itk::RGBPixel< double > );
329
330 cpPlugins_VectorImage_AllDims_Import( itk::RGBAPixel< char > );
331 cpPlugins_VectorImage_AllDims_Import( itk::RGBAPixel< short > );
332 cpPlugins_VectorImage_AllDims_Import( itk::RGBAPixel< int > );
333 cpPlugins_VectorImage_AllDims_Import( itk::RGBAPixel< long > );
334 cpPlugins_VectorImage_AllDims_Import( itk::RGBAPixel< unsigned char > );
335 cpPlugins_VectorImage_AllDims_Import( itk::RGBAPixel< unsigned short > );
336 cpPlugins_VectorImage_AllDims_Import( itk::RGBAPixel< unsigned int > );
337 cpPlugins_VectorImage_AllDims_Import( itk::RGBAPixel< unsigned long > );
338 cpPlugins_VectorImage_AllDims_Import( itk::RGBAPixel< float > );
339 cpPlugins_VectorImage_AllDims_Import( itk::RGBAPixel< double > );
340
341 cpPlugins_VectorImage_AllDims_Import( itk::DiffusionTensor3D< float > );
342 cpPlugins_VectorImage_AllDims_Import( itk::DiffusionTensor3D< double > );
343
344 cpPlugins_ArrayVectorImage_AllDims_Import( itk::Vector, float );
345 cpPlugins_ArrayVectorImage_AllDims_Import( itk::Vector, double );
346
347 cpPlugins_ArrayVectorImage_AllDims_Import( itk::CovariantVector, float );
348 cpPlugins_ArrayVectorImage_AllDims_Import( itk::CovariantVector, double );
349
350 cpPlugins_ArrayVectorImage_AllDims_Import( itk::Point, float );
351 cpPlugins_ArrayVectorImage_AllDims_Import( itk::Point, double );
352
353 cpPlugins_ArrayVectorImage_AllDims_Import(
354   itk::SymmetricSecondRankTensor, float
355   );
356 cpPlugins_ArrayVectorImage_AllDims_Import(
357   itk::SymmetricSecondRankTensor, double
358   );
359
360 #endif // cpPlugins_Interface_EXPORTS
361
362 #endif // __CPPLUGINS__INTERFACE__IMAGE__HXX__
363
364 // eof - $RCSfile$