1 #include <cpInstances/DataObjects/Image.h>
3 #include <itkImageToVTKImageFilter.h>
4 #include <itkVTKImageToImageFilter.h>
5 #include <vtkImageData.h>
6 #include <itkDiffusionTensor3D.h>
7 #include <itkRGBPixel.h>
8 #include <itkRGBAPixel.h>
10 // -------------------------------------------------------------------------
11 void cpInstances::DataObjects::Image::
12 SetITK( itk::LightObject* o )
14 this->Superclass::SetITK( o );
16 this->m_ITKvVTK = NULL;
20 // -------------------------------------------------------------------------
21 void cpInstances::DataObjects::Image::
22 SetVTK( vtkObjectBase* o )
24 this->Superclass::SetVTK( o );
26 this->m_ITKvVTK = NULL;
30 vtkImageData* img = dynamic_cast< vtkImageData* >( o );
31 this->Superclass::SetVTK( img );
35 this->m_ITKvVTK = NULL;
42 auto stype = img->GetScalarType( );
43 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_char
44 if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< char >( img );
45 if( stype == VTK_UNSIGNED_CHAR ) success = this->_VTK_2_ITK_0< unsigned char >( img );
46 #endif // cpPlugins_CONFIG_INTEGER_TYPES_char
47 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_short
48 if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< short >( img );
49 if( stype == VTK_UNSIGNED_CHAR ) success = this->_VTK_2_ITK_0< unsigned short >( img );
50 #endif // cpPlugins_CONFIG_INTEGER_TYPES_short
51 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_int
52 if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< int >( img );
53 if( stype == VTK_UNSIGNED_CHAR ) success = this->_VTK_2_ITK_0< unsigned int >( img );
54 #endif // cpPlugins_CONFIG_INTEGER_TYPES_int
55 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_long
56 if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< long >( img );
57 if( stype == VTK_UNSIGNED_CHAR ) success = this->_VTK_2_ITK_0< unsigned long >( img );
58 #endif // cpPlugins_CONFIG_INTEGER_TYPES_long
59 #ifdef cpPlugins_CONFIG_REAL_TYPES_float
60 if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< float >( img );
61 #endif // cpPlugins_CONFIG_REAL_TYPES_float
62 #ifdef cpPlugins_CONFIG_REAL_TYPES_double
63 if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< double >( img );
64 #endif // cpPlugins_CONFIG_REAL_TYPES_double
67 #define cpPlugins_CONFIG_COLOR_PIXELS_RGBPixel
68 #define cpPlugins_CONFIG_COLOR_PIXELS_RGBAPixel
69 #define cpPlugins_CONFIG_VECTORS_CovariantVector
70 #define cpPlugins_CONFIG_VECTORS_Point
71 #define cpPlugins_CONFIG_VECTORS_SymmetricSecondRankTensor
72 #define cpPlugins_CONFIG_VECTORS_Vector
73 #define cpPlugins_CONFIG_DIFFUSIONTENSORS_DiffusionTensor3D
74 #define cpPlugins_CONFIG_MATRICES_Matrix
80 this->m_ITKvVTK = NULL;
87 // -------------------------------------------------------------------------
88 cpInstances::DataObjects::Image::
94 // -------------------------------------------------------------------------
95 cpInstances::DataObjects::Image::
100 // -------------------------------------------------------------------------
101 void cpInstances::DataObjects::Image::
104 // TODO: std::cout << "Create ITK representation." << std::endl;
107 // -------------------------------------------------------------------------
108 void cpInstances::DataObjects::Image::
111 auto i = const_cast< itk::LightObject* >( this->m_ITK.GetPointer( ) );
112 auto v = const_cast< vtkObjectBase* >( this->m_VTK.GetPointer( ) );
113 if( i != NULL && v == NULL )
115 cpPlugins_Demangle_Image_VisualDims_1( i, _ITK_2_VTK_0 )
116 cpPlugins_Demangle_Image_DiffTensors3D_1( i, _ITK_2_VTK_1 );
121 // -------------------------------------------------------------------------
122 template< class _TImage >
123 void cpInstances::DataObjects::Image::
124 _ITK_2_VTK_0( _TImage* image ) const
126 static const unsigned int d = _TImage::ImageDimension;
127 cpPlugins_Demangle_Image_ScalarPixels_1( image, _ITK_2_VTK_1, d )
128 cpPlugins_Demangle_Image_ColorPixels_1( image, _ITK_2_VTK_1, d )
129 cpPlugins_Demangle_Image_VectorPixels_1( image, _ITK_2_VTK_1, d );
132 // -------------------------------------------------------------------------
133 template< class _TImage >
134 void cpInstances::DataObjects::Image::
135 _ITK_2_VTK_1( _TImage* image ) const
137 typedef itk::ImageToVTKImageFilter< _TImage > _TFilter;
139 Self* self = const_cast< Self* >( this );
140 _TFilter* f = dynamic_cast< _TFilter* >( self->m_ITKvVTK.GetPointer( ) );
143 typename _TFilter::Pointer nf = _TFilter::New( );
144 self->m_ITKvVTK = nf;
145 f = nf.GetPointer( );
148 f->SetInput( image );
153 self->m_VTK = f->GetOutput( );
156 // -------------------------------------------------------------------------
157 template< class _TPixel >
158 bool cpInstances::DataObjects::Image::
159 _VTK_2_ITK_0( vtkImageData* image )
161 bool success = false;
162 unsigned int dim = image->GetDataDimension( );
163 #ifdef cpPlugins_CONFIG_VISUAL_DIMENSIONS_2
164 if( dim == 2 ) success = this->_VTK_2_ITK_1< _TPixel, 2 >( image );
165 #endif // cpPlugins_CONFIG_VISUAL_DIMENSIONS_2
166 #ifdef cpPlugins_CONFIG_VISUAL_DIMENSIONS_3
167 if( dim == 3 ) success = this->_VTK_2_ITK_1< _TPixel, 3 >( image );
168 #endif // cpPlugins_CONFIG_VISUAL_DIMENSIONS_2
172 // -------------------------------------------------------------------------
173 template< class _TPixel, unsigned int _VDim >
174 bool cpInstances::DataObjects::Image::
175 _VTK_2_ITK_1( vtkImageData* image )
177 typedef itk::Image< _TPixel, _VDim > _TImage;
178 typedef itk::VTKImageToImageFilter< _TImage > _TFilter;
179 _TFilter* f = dynamic_cast< _TFilter* >( this->m_ITKvVTK.GetPointer( ) );
182 typename _TFilter::Pointer nf = _TFilter::New( );
183 this->m_ITKvVTK = nf;
184 f = nf.GetPointer( );
187 f->SetInput( image );
192 this->m_ITK = f->GetOutput( );