1 #include <cpInstances/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::Image::
12 SetITK( itk::LightObject* o )
14 this->Superclass::SetITK( o );
16 this->m_ITKvVTK = NULL;
20 // -------------------------------------------------------------------------
21 void cpInstances::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 // -------------------------------------------------------------------------
94 // -------------------------------------------------------------------------
100 // -------------------------------------------------------------------------
101 void cpInstances::Image::
104 // TODO: std::cout << "Create ITK representation." << std::endl;
107 // -------------------------------------------------------------------------
108 void cpInstances::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::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 #include <cpPlugins/BaseObjects/ProcessObject.h>
135 template< class _TImage >
136 void cpInstances::Image::
137 _ITK_2_VTK_1( _TImage* image ) const
139 typedef itk::ImageToVTKImageFilter< _TImage > _TFilter;
141 Self* self = const_cast< Self* >( this );
142 _TFilter* f = dynamic_cast< _TFilter* >( self->m_ITKvVTK.GetPointer( ) );
145 typename _TFilter::Pointer nf = _TFilter::New( );
146 self->m_ITKvVTK = nf;
147 f = nf.GetPointer( );
150 f->SetInput( image );
155 self->m_VTK = f->GetOutput( );
158 // -------------------------------------------------------------------------
159 template< class _TPixel >
160 bool cpInstances::Image::
161 _VTK_2_ITK_0( vtkImageData* image )
163 bool success = false;
164 unsigned int dim = image->GetDataDimension( );
165 #ifdef cpPlugins_CONFIG_VISUAL_DIMENSIONS_2
166 if( dim == 2 ) success = this->_VTK_2_ITK_1< _TPixel, 2 >( image );
167 #endif // cpPlugins_CONFIG_VISUAL_DIMENSIONS_2
168 #ifdef cpPlugins_CONFIG_VISUAL_DIMENSIONS_3
169 if( dim == 3 ) success = this->_VTK_2_ITK_1< _TPixel, 3 >( image );
170 #endif // cpPlugins_CONFIG_VISUAL_DIMENSIONS_2
174 // -------------------------------------------------------------------------
175 template< class _TPixel, unsigned int _VDim >
176 bool cpInstances::Image::
177 _VTK_2_ITK_1( vtkImageData* image )
179 typedef itk::Image< _TPixel, _VDim > _TImage;
180 typedef itk::VTKImageToImageFilter< _TImage > _TFilter;
181 _TFilter* f = dynamic_cast< _TFilter* >( this->m_ITKvVTK.GetPointer( ) );
184 typename _TFilter::Pointer nf = _TFilter::New( );
185 this->m_ITKvVTK = nf;
186 f = nf.GetPointer( );
189 f->SetInput( image );
194 this->m_ITK = f->GetOutput( );