1 #include <cpPlugins/DataObjects/Image.h>
2 #include <cpPlugins/DataObjects/Image_Demanglers.h>
4 #include <itkImageToVTKImageFilter.h>
5 #include <itkVTKImageToImageFilter.h>
7 #include <itkImageToVTKImageFilter.hxx>
8 #include <itkVTKImageToImageFilter.hxx>
9 #include <itkVTKImageExport.hxx>
10 #include <itkVTKImageImport.hxx>
12 // -------------------------------------------------------------------------
13 void cpPlugins::DataObjects::Image::
14 SetITK( itk::LightObject* o )
16 this->Superclass::SetITK( o );
17 cpPlugins_Demangle_Image_VisualDims_1( o, _ITK_2_VTK_0 )
18 cpPlugins_Demangle_Image_DiffTensors3D_1( o, _ITK_2_VTK_1 )
21 this->m_ITKvVTK = NULL;
27 // -------------------------------------------------------------------------
28 void cpPlugins::DataObjects::Image::
29 SetVTK( vtkObjectBase* o )
31 vtkImageData* img = dynamic_cast< vtkImageData* >( o );
32 this->Superclass::SetVTK( img );
36 this->m_ITKvVTK = NULL;
43 auto stype = img->GetScalarType( );
44 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_char
45 if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< char >( img );
46 if( stype == VTK_UNSIGNED_CHAR ) success = this->_VTK_2_ITK_0< unsigned char >( img );
47 #endif // cpPlugins_CONFIG_INTEGER_TYPES_char
48 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_short
49 if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< short >( img );
50 if( stype == VTK_UNSIGNED_CHAR ) success = this->_VTK_2_ITK_0< unsigned short >( img );
51 #endif // cpPlugins_CONFIG_INTEGER_TYPES_short
52 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_int
53 if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< int >( img );
54 if( stype == VTK_UNSIGNED_CHAR ) success = this->_VTK_2_ITK_0< unsigned int >( img );
55 #endif // cpPlugins_CONFIG_INTEGER_TYPES_int
56 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_long
57 if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< long >( img );
58 if( stype == VTK_UNSIGNED_CHAR ) success = this->_VTK_2_ITK_0< unsigned long >( img );
59 #endif // cpPlugins_CONFIG_INTEGER_TYPES_long
60 #ifdef cpPlugins_CONFIG_REAL_TYPES_float
61 if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< float >( img );
62 #endif // cpPlugins_CONFIG_REAL_TYPES_float
63 #ifdef cpPlugins_CONFIG_REAL_TYPES_double
64 if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< double >( img );
65 #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
79 this->m_ITKvVTK = NULL;
85 // -------------------------------------------------------------------------
86 cpPlugins::DataObjects::Image::
92 // -------------------------------------------------------------------------
93 cpPlugins::DataObjects::Image::
98 // -------------------------------------------------------------------------
99 template< class _TImage >
100 void cpPlugins::DataObjects::Image::
101 _ITK_2_VTK_0( _TImage* image )
103 cpPlugins_Demangle_Image_ScalarPixels_1( image, _ITK_2_VTK_1, _TImage::ImageDimension )
104 cpPlugins_Demangle_Image_ColorPixels_1( image, _ITK_2_VTK_1, _TImage::ImageDimension )
105 cpPlugins_Demangle_Image_VectorPixels_1( image, _ITK_2_VTK_1, _TImage::ImageDimension )
108 this->m_ITKvVTK = NULL;
113 // -------------------------------------------------------------------------
114 template< class _TImage >
115 void cpPlugins::DataObjects::Image::
116 _ITK_2_VTK_1( _TImage* image )
118 typedef itk::ImageToVTKImageFilter< _TImage > _TFilter;
119 _TFilter* f = dynamic_cast< _TFilter* >( this->m_ITKvVTK.GetPointer( ) );
122 typename _TFilter::Pointer nf = _TFilter::New( );
123 this->m_ITKvVTK = nf;
124 f = nf.GetPointer( );
127 f->SetInput( image );
132 this->m_VTK = f->GetOutput( );
135 // -------------------------------------------------------------------------
136 template< class _TPixel >
137 bool cpPlugins::DataObjects::Image::
138 _VTK_2_ITK_0( vtkImageData* image )
140 bool success = false;
141 unsigned int dim = image->GetDataDimension( );
142 #ifdef cpPlugins_CONFIG_VISUAL_DIMENSIONS_2
143 if( dim == 2 ) success = this->_VTK_2_ITK_1< _TPixel, 2 >( image );
144 #endif // cpPlugins_CONFIG_VISUAL_DIMENSIONS_2
145 #ifdef cpPlugins_CONFIG_VISUAL_DIMENSIONS_3
146 if( dim == 3 ) success = this->_VTK_2_ITK_1< _TPixel, 3 >( image );
147 #endif // cpPlugins_CONFIG_VISUAL_DIMENSIONS_2
151 // -------------------------------------------------------------------------
152 template< class _TPixel, unsigned int _VDim >
153 bool cpPlugins::DataObjects::Image::
154 _VTK_2_ITK_1( vtkImageData* image )
156 typedef itk::Image< _TPixel, _VDim > _TImage;
157 typedef itk::VTKImageToImageFilter< _TImage > _TFilter;
158 _TFilter* f = dynamic_cast< _TFilter* >( this->m_ITKvVTK.GetPointer( ) );
161 typename _TFilter::Pointer nf = _TFilter::New( );
162 this->m_ITKvVTK = nf;
163 f = nf.GetPointer( );
166 f->SetInput( image );
171 this->m_ITK = f->GetOutput( );