#include <cpPlugins/DataObjects/Image.h>
-#include <cpPlugins/DataObjects/Image.hxx>
+#include <cpPlugins/DataObjects/Image_Demanglers.h>
+#include <cpInstances_BaseObjects.h>
+#include <cpInstances_SimpleImages.h>
+
+#include <itkImageToVTKImageFilter.h>
+#include <itkVTKImageToImageFilter.h>
+
+#include <itkImageToVTKImageFilter.hxx>
+#include <itkVTKImageToImageFilter.hxx>
+#include <itkVTKImageExport.hxx>
+#include <itkVTKImageImport.hxx>
// -------------------------------------------------------------------------
void cpPlugins::DataObjects::Image::
SetITK( itk::LightObject* o )
{
this->Superclass::SetITK( o );
- cpPlugins_Demangle_ImageVisualDims( o, _ITK_2_VTK_0 );
- else cpPlugins_Demangle_ImageDiffusionTensors3D( o, _ITK_2_VTK_1 );
- else
+ cpPlugins_Demangle_Image_VisualDims( o, _ITK_2_VTK_0, );
+ cpPlugins_Demangle_Image_DiffTensors3D( o, _ITK_2_VTK_1, );
{
this->m_VTK = NULL;
this->m_ITKvVTK = NULL;
} // fi
- // Connect both worlds
- this->_VTK_2_ITK_0< unsigned char >( img );
+ bool success = false;
+ auto stype = img->GetScalarType( );
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_char
+ if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< char >( img );
+ if( stype == VTK_UNSIGNED_CHAR ) success = this->_VTK_2_ITK_0< unsigned char >( img );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_char
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_short
+ if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< short >( img );
+ if( stype == VTK_UNSIGNED_CHAR ) success = this->_VTK_2_ITK_0< unsigned short >( img );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_short
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_int
+ if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< int >( img );
+ if( stype == VTK_UNSIGNED_CHAR ) success = this->_VTK_2_ITK_0< unsigned int >( img );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_int
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_long
+ if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< long >( img );
+ if( stype == VTK_UNSIGNED_CHAR ) success = this->_VTK_2_ITK_0< unsigned long >( img );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_long
+#ifdef cpPlugins_CONFIG_REAL_TYPES_float
+ if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< float >( img );
+#endif // cpPlugins_CONFIG_REAL_TYPES_float
+#ifdef cpPlugins_CONFIG_REAL_TYPES_double
+ if( stype == VTK_CHAR ) success = this->_VTK_2_ITK_0< double >( img );
+#endif // cpPlugins_CONFIG_REAL_TYPES_double
/* TODO
- switch( img->GetScalarType( ) )
- {
- case VTK_CHAR: this->_VTK_2_ITK_0< char >( img ); break;
- case VTK_SHORT: this->_VTK_2_ITK_0< short >( img ); break;
- case VTK_INT: this->_VTK_2_ITK_0< int >( img ); break;
- case VTK_LONG: this->_VTK_2_ITK_0< long >( img ); break;
- case VTK_UNSIGNED_CHAR: this->_VTK_2_ITK_0< unsigned char >( img ); break;
- case VTK_UNSIGNED_SHORT: this->_VTK_2_ITK_0< unsigned short >( img ); break;
- case VTK_UNSIGNED_INT: this->_VTK_2_ITK_0< unsigned int >( img ); break;
- case VTK_UNSIGNED_LONG: this->_VTK_2_ITK_0< unsigned long >( img ); break;
- case VTK_FLOAT: this->_VTK_2_ITK_0< float >( img ); break;
- case VTK_DOUBLE: this->_VTK_2_ITK_0< double >( img ); break;
- default:
- {
- this->m_ITK = NULL;
- this->m_ITKvVTK = NULL;
-
- }
- } // hctiws
+ #define cpPlugins_CONFIG_COLOR_PIXELS_RGBPixel
+ #define cpPlugins_CONFIG_COLOR_PIXELS_RGBAPixel
+ #define cpPlugins_CONFIG_VECTORS_CovariantVector
+ #define cpPlugins_CONFIG_VECTORS_Point
+ #define cpPlugins_CONFIG_VECTORS_SymmetricSecondRankTensor
+ #define cpPlugins_CONFIG_VECTORS_Vector
+ #define cpPlugins_CONFIG_DIFFUSIONTENSORS_DiffusionTensor3D
+ #define cpPlugins_CONFIG_MATRICES_Matrix
*/
+ if( !success )
+ {
+ this->m_ITK = NULL;
+ this->m_ITKvVTK = NULL;
+
+ } // fi
this->Modified( );
}
{
}
+// -------------------------------------------------------------------------
+template< class _TImage >
+void cpPlugins::DataObjects::Image::
+_ITK_2_VTK_0( _TImage* image )
+{
+ cpPlugins_Demangle_Image_ScalarPixels( image, _ITK_2_VTK_1, _TImage::ImageDimension, );
+ cpPlugins_Demangle_Image_ColorPixels( image, _ITK_2_VTK_1, _TImage::ImageDimension, );
+ cpPlugins_Demangle_Image_VectorPixels( image, _ITK_2_VTK_1, _TImage::ImageDimension, );
+ {
+ this->m_VTK = NULL;
+ this->m_ITKvVTK = NULL;
+
+ } // fi
+}
+
+// -------------------------------------------------------------------------
+template< class _TImage >
+void cpPlugins::DataObjects::Image::
+_ITK_2_VTK_1( _TImage* image )
+{
+ typedef itk::ImageToVTKImageFilter< _TImage > _TFilter;
+ _TFilter* f = dynamic_cast< _TFilter* >( this->m_ITKvVTK.GetPointer( ) );
+ if( f == NULL )
+ {
+ typename _TFilter::Pointer nf = _TFilter::New( );
+ this->m_ITKvVTK = nf;
+ f = nf.GetPointer( );
+
+ } // fi
+ f->SetInput( image );
+ f->Update( );
+
+ // Keep object track
+ this->m_ITK = image;
+ this->m_VTK = f->GetOutput( );
+}
+
+// -------------------------------------------------------------------------
+template< class _TPixel >
+bool cpPlugins::DataObjects::Image::
+_VTK_2_ITK_0( vtkImageData* image )
+{
+ bool success = false;
+ unsigned int dim = image->GetDataDimension( );
+#ifdef cpPlugins_CONFIG_VISUAL_DIMENSIONS_2
+ if( dim == 2 ) success = this->_VTK_2_ITK_1< _TPixel, 2 >( image );
+#endif // cpPlugins_CONFIG_VISUAL_DIMENSIONS_2
+#ifdef cpPlugins_CONFIG_VISUAL_DIMENSIONS_3
+ if( dim == 3 ) success = this->_VTK_2_ITK_1< _TPixel, 3 >( image );
+#endif // cpPlugins_CONFIG_VISUAL_DIMENSIONS_2
+ return( success );
+}
+
+// -------------------------------------------------------------------------
+template< class _TPixel, unsigned int _VDim >
+bool cpPlugins::DataObjects::Image::
+_VTK_2_ITK_1( vtkImageData* image )
+{
+ typedef itk::Image< _TPixel, _VDim > _TImage;
+ typedef itk::VTKImageToImageFilter< _TImage > _TFilter;
+ _TFilter* f = dynamic_cast< _TFilter* >( this->m_ITKvVTK.GetPointer( ) );
+ if( f == NULL )
+ {
+ typename _TFilter::Pointer nf = _TFilter::New( );
+ this->m_ITKvVTK = nf;
+ f = nf.GetPointer( );
+
+ } // fi
+ f->SetInput( image );
+ f->Update( );
+
+ // Keep object track
+ this->m_VTK = image;
+ this->m_ITK = f->GetOutput( );
+ return( true );
+}
+
// eof - $RCSfile$