1 #include <cpPlugins/DataObjects/Image.h>
2 #include <cpPlugins/DataObjects/Image_Demanglers.h>
3 #include <cpInstances_BaseObjects.h>
4 #include <cpInstances_SimpleImages.h>
6 #include <itkImageToVTKImageFilter.h>
7 #include <itkVTKImageToImageFilter.h>
9 #include <itkImageToVTKImageFilter.hxx>
10 #include <itkVTKImageToImageFilter.hxx>
11 #include <itkVTKImageExport.hxx>
12 #include <itkVTKImageImport.hxx>
14 // -------------------------------------------------------------------------
15 void cpPlugins::DataObjects::Image::
16 SetITK( itk::LightObject* o )
18 this->Superclass::SetITK( o );
19 cpPlugins_Demangle_Image_VisualDims_1( o, _ITK_2_VTK_0 )
20 cpPlugins_Demangle_Image_DiffTensors3D_1( o, _ITK_2_VTK_1 )
23 this->m_ITKvVTK = NULL;
29 // -------------------------------------------------------------------------
30 void cpPlugins::DataObjects::Image::
31 SetVTK( vtkObjectBase* o )
33 vtkImageData* img = dynamic_cast< vtkImageData* >( o );
34 this->Superclass::SetVTK( img );
38 this->m_ITKvVTK = NULL;
45 auto stype = img->GetScalarType( );
46 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_char
47 if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< char >( img );
48 if( stype == VTK_UNSIGNED_CHAR ) success = this->_VTK_2_ITK_0< unsigned char >( img );
49 #endif // cpPlugins_CONFIG_INTEGER_TYPES_char
50 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_short
51 if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< short >( img );
52 if( stype == VTK_UNSIGNED_CHAR ) success = this->_VTK_2_ITK_0< unsigned short >( img );
53 #endif // cpPlugins_CONFIG_INTEGER_TYPES_short
54 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_int
55 if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< int >( img );
56 if( stype == VTK_UNSIGNED_CHAR ) success = this->_VTK_2_ITK_0< unsigned int >( img );
57 #endif // cpPlugins_CONFIG_INTEGER_TYPES_int
58 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_long
59 if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< long >( img );
60 if( stype == VTK_UNSIGNED_CHAR ) success = this->_VTK_2_ITK_0< unsigned long >( img );
61 #endif // cpPlugins_CONFIG_INTEGER_TYPES_long
62 #ifdef cpPlugins_CONFIG_REAL_TYPES_float
63 if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< float >( img );
64 #endif // cpPlugins_CONFIG_REAL_TYPES_float
65 #ifdef cpPlugins_CONFIG_REAL_TYPES_double
66 if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< double >( img );
67 #endif // cpPlugins_CONFIG_REAL_TYPES_double
69 #define cpPlugins_CONFIG_COLOR_PIXELS_RGBPixel
70 #define cpPlugins_CONFIG_COLOR_PIXELS_RGBAPixel
71 #define cpPlugins_CONFIG_VECTORS_CovariantVector
72 #define cpPlugins_CONFIG_VECTORS_Point
73 #define cpPlugins_CONFIG_VECTORS_SymmetricSecondRankTensor
74 #define cpPlugins_CONFIG_VECTORS_Vector
75 #define cpPlugins_CONFIG_DIFFUSIONTENSORS_DiffusionTensor3D
76 #define cpPlugins_CONFIG_MATRICES_Matrix
81 this->m_ITKvVTK = NULL;
87 // -------------------------------------------------------------------------
88 cpPlugins::DataObjects::Image::
94 // -------------------------------------------------------------------------
95 cpPlugins::DataObjects::Image::
100 // -------------------------------------------------------------------------
101 template< class _TImage >
102 void cpPlugins::DataObjects::Image::
103 _ITK_2_VTK_0( _TImage* image )
105 cpPlugins_Demangle_Image_ScalarPixels_1( image, _ITK_2_VTK_1, _TImage::ImageDimension )
106 cpPlugins_Demangle_Image_ColorPixels_1( image, _ITK_2_VTK_1, _TImage::ImageDimension )
107 cpPlugins_Demangle_Image_VectorPixels_1( image, _ITK_2_VTK_1, _TImage::ImageDimension )
110 this->m_ITKvVTK = NULL;
115 // -------------------------------------------------------------------------
116 template< class _TImage >
117 void cpPlugins::DataObjects::Image::
118 _ITK_2_VTK_1( _TImage* image )
120 typedef itk::ImageToVTKImageFilter< _TImage > _TFilter;
121 _TFilter* f = dynamic_cast< _TFilter* >( this->m_ITKvVTK.GetPointer( ) );
124 typename _TFilter::Pointer nf = _TFilter::New( );
125 this->m_ITKvVTK = nf;
126 f = nf.GetPointer( );
129 f->SetInput( image );
134 this->m_VTK = f->GetOutput( );
137 // -------------------------------------------------------------------------
138 template< class _TPixel >
139 bool cpPlugins::DataObjects::Image::
140 _VTK_2_ITK_0( vtkImageData* image )
142 bool success = false;
143 unsigned int dim = image->GetDataDimension( );
144 #ifdef cpPlugins_CONFIG_VISUAL_DIMENSIONS_2
145 if( dim == 2 ) success = this->_VTK_2_ITK_1< _TPixel, 2 >( image );
146 #endif // cpPlugins_CONFIG_VISUAL_DIMENSIONS_2
147 #ifdef cpPlugins_CONFIG_VISUAL_DIMENSIONS_3
148 if( dim == 3 ) success = this->_VTK_2_ITK_1< _TPixel, 3 >( image );
149 #endif // cpPlugins_CONFIG_VISUAL_DIMENSIONS_2
153 // -------------------------------------------------------------------------
154 template< class _TPixel, unsigned int _VDim >
155 bool cpPlugins::DataObjects::Image::
156 _VTK_2_ITK_1( vtkImageData* image )
158 typedef itk::Image< _TPixel, _VDim > _TImage;
159 typedef itk::VTKImageToImageFilter< _TImage > _TFilter;
160 _TFilter* f = dynamic_cast< _TFilter* >( this->m_ITKvVTK.GetPointer( ) );
163 typename _TFilter::Pointer nf = _TFilter::New( );
164 this->m_ITKvVTK = nf;
165 f = nf.GetPointer( );
168 f->SetInput( image );
173 this->m_ITK = f->GetOutput( );