X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FImage.cxx;h=8ddd9ccb5abd185cb9578eb041b0d563396b95de;hb=6df7b3a0946edcecfe55509d0b77d757d76a35ab;hp=c72663d5dbda9f65cb3cc2eddf021e64b4796fa3;hpb=e561a2fa4dcaee2c544e58385e1ff7d56ba8b051;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/Image.cxx b/lib/cpPlugins/Interface/Image.cxx index c72663d..8ddd9cc 100644 --- a/lib/cpPlugins/Interface/Image.cxx +++ b/lib/cpPlugins/Interface/Image.cxx @@ -1,67 +1,204 @@ #include +#include +#include + #define ITK_MANUAL_INSTANTIATION #include -#include #include -// ------------------------------------------------------------------------- -#define cpPlugins_Image_Dimension( d, o, f ) \ - if( dynamic_cast< itk::ImageBase< d >* >( o ) != NULL ) \ - this->f< d >( ) - -// ------------------------------------------------------------------------- -#define cpPlugins_Image_Pixel( p, d, o, f ) \ - if( dynamic_cast< itk::Image< p, d >* >( o ) != NULL ) \ - this->f< p, d >( ) - -// ------------------------------------------------------------------------- -#define cpPlugins_Image_RGB( p, d, o, f ) \ - if( \ - dynamic_cast< itk::Image< itk::RGBPixel< p >, d >* >( o ) != NULL \ - ) \ - this->f< itk::RGBPixel< p >, d >( ) +#include +#include +#include +#include +#include +#include +#include // ------------------------------------------------------------------------- -std::string cpPlugins::Interface::Image:: -GetClassName( ) const +void cpPlugins::Interface::Image:: +SetITKDataObject( itk::DataObject* o ) { - return( "cpPlugins::Interface::Image" ); + bool r; + if( dynamic_cast< itk::ImageBase< 1 >* >( o ) != NULL ) + { + cpPlugins_Image_Array_Demangle( + itk::Vector, float, 1, 1, o, _Type, r + ); + else cpPlugins_Image_Array_Demangle( + itk::Vector, double, 1, 1, o, _Type, r + ); + else cpPlugins_Image_Array_Demangle( + itk::Point, float, 1, 1, o, _Type, r + ); + else cpPlugins_Image_Array_Demangle( + itk::Point, double, 1, 1, o, _Type, r + ); + else cpPlugins_Image_Array_Demangle( + itk::CovariantVector, float, 1, 1, o, _Type, r + ); + else cpPlugins_Image_Array_Demangle( + itk::CovariantVector, double, 1, 1, o, _Type, r + ); + else cpPlugins_Image_Array_Demangle( + itk::SymmetricSecondRankTensor, float, 1, 1, o, _Type, r + ); + else cpPlugins_Image_Array_Demangle( + itk::SymmetricSecondRankTensor, double, 1, 1, o, _Type, r + ); + else r = this->_Dim< 1 >( o ); + } + else if( dynamic_cast< itk::ImageBase< 2 >* >( o ) != NULL ) + { + cpPlugins_Image_Demangle( + itk::RGBPixel< char >, 2, o, _Type, r + ); + else cpPlugins_Image_Demangle( + itk::RGBPixel< short >, 2, o, _Type, r + ); + else cpPlugins_Image_Demangle( + itk::RGBPixel< unsigned char >, 2, o, _Type, r + ); + else cpPlugins_Image_Demangle( + itk::RGBPixel< unsigned short >, 2, o, _Type, r + ); + else cpPlugins_Image_Demangle( + itk::RGBAPixel< char >, 2, o, _Type, r + ); + else cpPlugins_Image_Demangle( + itk::RGBAPixel< short >, 2, o, _Type, r + ); + else cpPlugins_Image_Demangle( + itk::RGBAPixel< unsigned char >, 2, o, _Type, r + ); + else cpPlugins_Image_Demangle( + itk::RGBAPixel< unsigned short >, 2, o, _Type, r + ); + else cpPlugins_Image_Array_Demangle( + itk::Vector, float, 2, 2, o, _Type, r + ); + else cpPlugins_Image_Array_Demangle( + itk::Vector, double, 2, 2, o, _Type, r + ); + else cpPlugins_Image_Array_Demangle( + itk::Point, float, 2, 2, o, _Type, r + ); + else cpPlugins_Image_Array_Demangle( + itk::Point, double, 2, 2, o, _Type, r + ); + else cpPlugins_Image_Array_Demangle( + itk::CovariantVector, float, 2, 2, o, _Type, r + ); + else cpPlugins_Image_Array_Demangle( + itk::CovariantVector, double, 2, 2, o, _Type, r + ); + else cpPlugins_Image_Array_Demangle( + itk::SymmetricSecondRankTensor, float, 2, 2, o, _Type, r + ); + else cpPlugins_Image_Array_Demangle( + itk::SymmetricSecondRankTensor, double, 2, 2, o, _Type, r + ); + else r = this->_Dim< 2 >( o ); + } + else if( dynamic_cast< itk::ImageBase< 3 >* >( o ) != NULL ) + { + cpPlugins_Image_Demangle( + itk::RGBPixel< char >, 3, o, _Type, r + ); + else cpPlugins_Image_Demangle( + itk::RGBPixel< short >, 3, o, _Type, r + ); + else cpPlugins_Image_Demangle( + itk::RGBPixel< unsigned char >, 3, o, _Type, r + ); + else cpPlugins_Image_Demangle( + itk::RGBPixel< unsigned short >, 3, o, _Type, r + ); + else cpPlugins_Image_Demangle( + itk::RGBAPixel< char >, 3, o, _Type, r + ); + else cpPlugins_Image_Demangle( + itk::RGBAPixel< short >, 3, o, _Type, r + ); + else cpPlugins_Image_Demangle( + itk::RGBAPixel< unsigned char >, 3, o, _Type, r + ); + else cpPlugins_Image_Demangle( + itk::RGBAPixel< unsigned short >, 3, o, _Type, r + ); + else cpPlugins_Image_Array_Demangle( + itk::Vector, float, 3, 3, o, _Type, r + ); + else cpPlugins_Image_Array_Demangle( + itk::Vector, double, 3, 3, o, _Type, r + ); + else cpPlugins_Image_Array_Demangle( + itk::Point, float, 3, 3, o, _Type, r + ); + else cpPlugins_Image_Array_Demangle( + itk::Point, double, 3, 3, o, _Type, r + ); + else cpPlugins_Image_Array_Demangle( + itk::CovariantVector, float, 3, 3, o, _Type, r + ); + else cpPlugins_Image_Array_Demangle( + itk::CovariantVector, double, 3, 3, o, _Type, r + ); + else cpPlugins_Image_Array_Demangle( + itk::SymmetricSecondRankTensor, float, 3, 3, o, _Type, r + ); + else cpPlugins_Image_Array_Demangle( + itk::SymmetricSecondRankTensor, double, 3, 3, o, _Type, r + ); + else cpPlugins_Image_Demangle( + itk::DiffusionTensor3D< float >, 3, o, _Type, r + ); + else cpPlugins_Image_Demangle( + itk::DiffusionTensor3D< double >, 3, o, _Type, r + ); + else r = this->_Dim< 3 >( o ); + } + else if( dynamic_cast< itk::ImageBase< 4 >* >( o ) != NULL ) + { + this->m_ITKObject = o; + this->m_VTKObject = NULL; + this->m_ITKvVTKConnection = NULL; + + } // fi } // ------------------------------------------------------------------------- void cpPlugins::Interface::Image:: -SetRealDataObject( itk::DataObject* dobj ) +SetVTKDataObject( vtkDataObject* o ) { - this->Superclass::SetRealDataObject( dobj ); - - // NOTE: Only 2 and 3 dimensions at this moment to connect with VTK - cpPlugins_Image_Dimension( 2, dobj, _VTK_0 ); - else cpPlugins_Image_Dimension( 3, dobj, _VTK_0 ); + // this->m_VTKObject = o; + std::cerr << "Image: TODO this!!!!" << std::endl; + std::exit( 1 ); } // ------------------------------------------------------------------------- vtkImageData* cpPlugins::Interface::Image:: -GetVTKImageData( ) const +GetVTKImageData( ) { - return( this->m_VTKImageData ); + return( dynamic_cast< vtkImageData* >( this->GetVTKDataObject( ) ) ); } // ------------------------------------------------------------------------- -void cpPlugins::Interface::Image:: -UpdateVTKImageData( ) +const vtkImageData* cpPlugins::Interface::Image:: +GetVTKImageData( ) const { - this->m_Image2VTKImageData->Modified( ); - this->m_Image2VTKImageData->Update( ); - this->m_VTKImageData->Modified( ); + return( + dynamic_cast< const vtkImageData* >( this->GetVTKDataObject( ) ) + ); } // ------------------------------------------------------------------------- cpPlugins::Interface::Image:: Image( ) - : Superclass( ), - m_VTKImageData( NULL ) + : Superclass( ) { + this->m_ClassName = "cpPlugins::Interface::Image"; + this->m_ClassCategory = "BasicObject"; } // ------------------------------------------------------------------------- @@ -72,48 +209,66 @@ cpPlugins::Interface::Image:: // ------------------------------------------------------------------------- template< unsigned int D > -void cpPlugins::Interface::Image:: -_VTK_0( ) +bool cpPlugins::Interface::Image:: +_Dim( itk::DataObject* o ) { - itk::DataObject* dobj = this->Superclass::GetRealDataObject( ); - - cpPlugins_Image_Pixel( char, D, dobj, _VTK_1 ); - else cpPlugins_Image_Pixel( short, D, dobj, _VTK_1 ); - else cpPlugins_Image_Pixel( int, D, dobj, _VTK_1 ); - else cpPlugins_Image_Pixel( long, D, dobj, _VTK_1 ); - else cpPlugins_Image_Pixel( unsigned char, D, dobj, _VTK_1 ); - else cpPlugins_Image_Pixel( unsigned short, D, dobj, _VTK_1 ); - else cpPlugins_Image_Pixel( unsigned int, D, dobj, _VTK_1 ); - else cpPlugins_Image_Pixel( unsigned long, D, dobj, _VTK_1 ); - else cpPlugins_Image_Pixel( float, D, dobj, _VTK_1 ); - else cpPlugins_Image_Pixel( double, D, dobj, _VTK_1 ); - else cpPlugins_Image_RGB( char, D, dobj, _VTK_1 ); - else cpPlugins_Image_RGB( short, D, dobj, _VTK_1 ); - else cpPlugins_Image_RGB( int, D, dobj, _VTK_1 ); - else cpPlugins_Image_RGB( long, D, dobj, _VTK_1 ); - else cpPlugins_Image_RGB( unsigned char, D, dobj, _VTK_1 ); - else cpPlugins_Image_RGB( unsigned short, D, dobj, _VTK_1 ); - else cpPlugins_Image_RGB( unsigned int, D, dobj, _VTK_1 ); - else cpPlugins_Image_RGB( unsigned long, D, dobj, _VTK_1 ); - else cpPlugins_Image_RGB( float, D, dobj, _VTK_1 ); - else cpPlugins_Image_RGB( double, D, dobj, _VTK_1 ); + bool r; + cpPlugins_Image_Demangle( + char, D, o, _Type, r + ); + else cpPlugins_Image_Demangle( + short, D, o, _Type, r + ); + else cpPlugins_Image_Demangle( + int, D, o, _Type, r + ); + else cpPlugins_Image_Demangle( + long, D, o, _Type, r + ); + else cpPlugins_Image_Demangle( + unsigned char, D, o, _Type, r + ); + else cpPlugins_Image_Demangle( + unsigned short, D, o, _Type, r + ); + else cpPlugins_Image_Demangle( + unsigned int, D, o, _Type, r + ); + else cpPlugins_Image_Demangle( + unsigned long, D, o, _Type, r + ); + else cpPlugins_Image_Demangle( + float, D, o, _Type, r + ); + else cpPlugins_Image_Demangle( + double, D, o, _Type, r + ); + else + { + this->m_ITKObject = o; + this->m_VTKObject = NULL; + this->m_ITKvVTKConnection = NULL; + + } // fi + return( true ); } // ------------------------------------------------------------------------- -template< class P, unsigned int D > -void cpPlugins::Interface::Image:: -_VTK_1( ) +template< class I > +bool cpPlugins::Interface::Image:: +_Type( itk::DataObject* o ) { - typedef itk::Image< P, D > _TImage; - typedef itk::ImageToVTKImageFilter< _TImage > _TFilter; - - _TImage* img = - dynamic_cast< _TImage* >( this->Superclass::GetRealDataObject( ) ); - typename _TFilter::Pointer filter = _TFilter::New( ); - filter->SetInput( img ); - filter->Update( ); - this->m_VTKImageData = filter->GetOutput( ); - this->m_Image2VTKImageData = filter; + typedef itk::ImageToVTKImageFilter< I > _F; + + typename _F::Pointer f = _F::New( ); + f->SetInput( dynamic_cast< I* >( o ) ); + f->Update( ); + + this->m_ITKObject = o; + this->m_VTKObject = f->GetOutput( ); + this->m_ITKvVTKConnection = f; + + return( true ); } // eof - $RCSfile$