X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FImage.hxx;h=1bb8b77be545eb3c5af9add91d94aab9cb6db618;hb=7e29f3aec097ba1bff1894fed6eb1094276c5b72;hp=ab2c5ea00c9b6399ce0afa635dd1bba997b50805;hpb=dea0e89b762a27b1e4088f3d03b5169ca63a227f;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/Image.hxx b/lib/cpPlugins/Interface/Image.hxx index ab2c5ea..1bb8b77 100644 --- a/lib/cpPlugins/Interface/Image.hxx +++ b/lib/cpPlugins/Interface/Image.hxx @@ -16,129 +16,109 @@ #include // ------------------------------------------------------------------------- -#define cpPlugins_VTKImage_Demangle( TI, T, D, o ) \ - if( typeid( TI ) == typeid( itk::Image< T, D > ) ) \ - this->_ITK_2_VTK< T, D >( o ) - -// ------------------------------------------------------------------------- -#define cpPlugins_VTKImageArray_Demangle( TI, T, P, DP, DI, o ) \ - if( typeid( TI ) == typeid( itk::Image< T< P, DP >, DI > ) ) \ - this->_ITK_2_VTK< T< P, DP >, DI >( o ) - -// ------------------------------------------------------------------------- -#define cpPlugins_VTKImage_Demangle_AllDims( TI, T, o ) \ - cpPlugins_VTKImage_Demangle( TI, T, 2, o ); \ - else cpPlugins_VTKImage_Demangle( TI, T, 3, o ) - -// ------------------------------------------------------------------------- -#define cpPlugins_VTKImageArray_Demangle_AllDims( TI, T, P, o ) \ - cpPlugins_VTKImageArray_Demangle( TI, T, P, 2, 2, o ); \ - else cpPlugins_VTKImageArray_Demangle( TI, T, P, 3, 3, o ) - -// ------------------------------------------------------------------------- -template< class I > +template< unsigned int D > void cpPlugins::Interface::Image:: -SetITK( itk::Object* object ) +_ITK_2_VTK_0( itk::LightObject* o ) { - // Check if input object has the desired type - I* image = dynamic_cast< I* >( object ); - if( image == NULL ) + if( dynamic_cast< itk::ImageBase< D >* >( o ) != NULL ) + { + this->_ITK_2_VTK_1< char, D >( o ); + this->_ITK_2_VTK_1< short, D >( o ); + this->_ITK_2_VTK_1< int, D >( o ); + this->_ITK_2_VTK_1< long, D >( o ); + this->_ITK_2_VTK_1< unsigned char, D >( o ); + this->_ITK_2_VTK_1< unsigned short, D >( o ); + this->_ITK_2_VTK_1< unsigned int, D >( o ); + this->_ITK_2_VTK_1< unsigned long, D >( o ); + this->_ITK_2_VTK_1< float, D >( o ); + this->_ITK_2_VTK_1< double, D >( o ); + this->_ITK_2_VTK_1< itk::RGBPixel< char >, D >( o ); + this->_ITK_2_VTK_1< itk::RGBPixel< short >, D >( o ); + this->_ITK_2_VTK_1< itk::RGBPixel< int >, D >( o ); + this->_ITK_2_VTK_1< itk::RGBPixel< long >, D >( o ); + this->_ITK_2_VTK_1< itk::RGBPixel< unsigned char >, D >( o ); + this->_ITK_2_VTK_1< itk::RGBPixel< unsigned short >, D >( o ); + this->_ITK_2_VTK_1< itk::RGBPixel< unsigned int >, D >( o ); + this->_ITK_2_VTK_1< itk::RGBPixel< unsigned long >, D >( o ); + this->_ITK_2_VTK_1< itk::RGBPixel< float >, D >( o ); + this->_ITK_2_VTK_1< itk::RGBPixel< double >, D >( o ); + this->_ITK_2_VTK_1< itk::RGBAPixel< char >, D >( o ); + this->_ITK_2_VTK_1< itk::RGBAPixel< short >, D >( o ); + this->_ITK_2_VTK_1< itk::RGBAPixel< int >, D >( o ); + this->_ITK_2_VTK_1< itk::RGBAPixel< long >, D >( o ); + this->_ITK_2_VTK_1< itk::RGBAPixel< unsigned char >, D >( o ); + this->_ITK_2_VTK_1< itk::RGBAPixel< unsigned short >, D >( o ); + this->_ITK_2_VTK_1< itk::RGBAPixel< unsigned int >, D >( o ); + this->_ITK_2_VTK_1< itk::RGBAPixel< unsigned long >, D >( o ); + this->_ITK_2_VTK_1< itk::RGBAPixel< float >, D >( o ); + this->_ITK_2_VTK_1< itk::RGBAPixel< double >, D >( o ); + this->_ITK_2_VTK_1< itk::DiffusionTensor3D< float >, D >( o ); + this->_ITK_2_VTK_1< itk::DiffusionTensor3D< double >, D >( o ); + this->_ITK_2_VTK_1< itk::Vector< float, D >, D >( o ); + this->_ITK_2_VTK_1< itk::Vector< double, D >, D >( o ); + this->_ITK_2_VTK_1< itk::CovariantVector< float, D >, D >( o ); + this->_ITK_2_VTK_1< itk::CovariantVector< double, D >, D >( o ); + this->_ITK_2_VTK_1< itk::Point< float, D >, D >( o ); + this->_ITK_2_VTK_1< itk::Point< double, D >, D >( o ); + this->_ITK_2_VTK_1< itk::SymmetricSecondRankTensor< float, D >, D >( o ); + this->_ITK_2_VTK_1< itk::SymmetricSecondRankTensor< double, D >, D >( o ); + } + else { - this->m_ITKObject = NULL; this->m_VTKObject = NULL; - this->m_ITKvVTKConnection = NULL; + this->m_ITKvVTK = NULL; this->Modified( ); - return; } // fi +} - // --------- TODO --------------- - typename I::DirectionType norm_dir; - norm_dir.SetIdentity( ); - image->SetDirection( norm_dir ); - // --------- TODO --------------- - - // Connect it to VTK - cpPlugins_VTKImage_Demangle_AllDims( I, char, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, short, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, int, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, long, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, unsigned char, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, unsigned short, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, unsigned int, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, unsigned long, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, float, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, double, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBPixel< char >, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBPixel< short >, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBPixel< int >, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBPixel< long >, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBPixel< unsigned char >, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBPixel< unsigned short >, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBPixel< unsigned int >, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBPixel< unsigned long >, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBPixel< float >, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBPixel< double >, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBAPixel< char >, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBAPixel< short >, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBAPixel< int >, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBAPixel< long >, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBAPixel< unsigned char >, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBAPixel< unsigned short >, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBAPixel< unsigned int >, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBAPixel< unsigned long >, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBAPixel< float >, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, itk::RGBAPixel< double >, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, itk::DiffusionTensor3D< float >, image ); - else cpPlugins_VTKImage_Demangle_AllDims( I, itk::DiffusionTensor3D< double >, image ); - else cpPlugins_VTKImageArray_Demangle_AllDims( I, itk::Vector, float, image ); - else cpPlugins_VTKImageArray_Demangle_AllDims( I, itk::Vector, double, image ); - else cpPlugins_VTKImageArray_Demangle_AllDims( I, itk::CovariantVector, float, image ); - else cpPlugins_VTKImageArray_Demangle_AllDims( I, itk::CovariantVector, double, image ); - else cpPlugins_VTKImageArray_Demangle_AllDims( I, itk::Point, float, image ); - else cpPlugins_VTKImageArray_Demangle_AllDims( I, itk::Point, double, image ); - else cpPlugins_VTKImageArray_Demangle_AllDims( I, itk::SymmetricSecondRankTensor, float, image ); - else cpPlugins_VTKImageArray_Demangle_AllDims( I, itk::SymmetricSecondRankTensor, double, image ); - else +// ------------------------------------------------------------------------- +template< class P, unsigned int D > +void cpPlugins::Interface::Image:: +_ITK_2_VTK_1( itk::LightObject* o ) +{ + if( dynamic_cast< itk::Image< P, D >* >( o ) == NULL ) { this->m_VTKObject = NULL; - this->m_ITKvVTKConnection = NULL; - - } // fi - - // Keep objects - this->m_ITKObject = object; - this->Modified( ); + this->m_ITKvVTK = NULL; + this->Modified( ); + } + else + this->_ITK_2_VTK_2< itk::Image< P, D > >( o ); } // ------------------------------------------------------------------------- -template< class P, unsigned int D > +template< class I > void cpPlugins::Interface::Image:: -_ITK_2_VTK( itk::Object* object ) +_ITK_2_VTK_2( itk::LightObject* o ) { - typedef itk::Image< P, D > _I; - typedef itk::ImageToVTKImageFilter< _I > _I2Vtk; - - // Check (yes, again!!!) if input object has the desired type - _I* image = dynamic_cast< _I* >( object ); - if( image == NULL ) - return; - - // Connect it to VTK - _I2Vtk* f = - dynamic_cast< _I2Vtk* >( this->m_ITKvVTKConnection.GetPointer( ) ); - if( f == NULL ) + typedef itk::ImageToVTKImageFilter< I > _I2V; + + I* image = dynamic_cast< I* >( o ); + if( image != NULL ) + { + _I2V* f = dynamic_cast< _I2V* >( this->m_ITKvVTK.GetPointer( ) ); + if( f == NULL ) + { + typename _I2V::Pointer nf = _I2V::New( ); + this->m_ITKvVTK = nf; + f = nf.GetPointer( ); + + } // fi + f->SetInput( image ); + f->Update( ); + + // Keep object track + this->m_ITKObject = o; + this->m_VTKObject = f->GetOutput( ); + } + else { - typename _I2Vtk::Pointer nf = _I2Vtk::New( ); - this->m_ITKvVTKConnection = nf; - f = nf.GetPointer( ); + this->m_VTKObject = NULL; + this->m_ITKvVTK = NULL; } // fi - f->SetInput( image ); - f->Update( ); - - // Keep object track - this->m_VTKObject = f->GetOutput( ); + this->Modified( ); } #ifndef cpPlugins_Interface_EXPORTS