X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FPlugins%2FImageWriter.cxx;h=2a7154edae944bff1a017fa3cb0a2650a9480600;hb=54e12e973942f6ddfe6c606acf2fd93480ca6165;hp=41fdb301f0f67dc4375ef714d805e5794ab38bdf;hpb=61e052afc5b659224bbc85b7d15b93402ea7d5a7;p=cpPlugins.git diff --git a/lib/cpPlugins/Plugins/ImageWriter.cxx b/lib/cpPlugins/Plugins/ImageWriter.cxx index 41fdb30..2a7154e 100644 --- a/lib/cpPlugins/Plugins/ImageWriter.cxx +++ b/lib/cpPlugins/Plugins/ImageWriter.cxx @@ -1,37 +1,20 @@ #include +#include #include -#define ITK_MANUAL_INSTANTIATION -#include -#include - -// ------------------------------------------------------------------------- -#define cpPlugins_ImageWriter_Dimension( r, d, o, f ) \ - if( dynamic_cast< itk::ImageBase< d >* >( o ) != NULL ) \ - r = this->f< d >( ) - -// ------------------------------------------------------------------------- -#define cpPlugins_ImageWriter_Pixel( r, p, d, o, f ) \ - if( dynamic_cast< itk::Image< p, d >* >( o ) != NULL ) \ - r = this->f< p, d >( ) - -// ------------------------------------------------------------------------- -#define cpPlugins_ImageWriter_RGB( r, p, d, o, f ) \ - if( \ - dynamic_cast< itk::Image< itk::RGBPixel< p >, d >* >( o ) != NULL \ - ) \ - r = this->f< itk::RGBPixel< p >, d >( ) - // ------------------------------------------------------------------------- cpPlugins::Plugins::ImageWriter:: ImageWriter( ) : Superclass( ) { + this->m_ClassName = "cpPlugins::ImageWriter"; + this->m_ClassCategory = "ImageWriter"; this->SetNumberOfInputs( 1 ); - this->m_DefaultParameters[ "FileName" ] = - TParameter( "string", "no_file_name" ); + using namespace cpPlugins::Interface; + this->m_DefaultParameters.Configure( Parameters::String, "FileName" ); + this->m_Parameters = this->m_DefaultParameters; } // ------------------------------------------------------------------------- @@ -40,91 +23,62 @@ cpPlugins::Plugins::ImageWriter:: { } -// ------------------------------------------------------------------------- -std::string cpPlugins::Plugins::ImageWriter:: -GetClassName( ) const -{ - return( "cpPlugins::Plugins::ImageWriter" ); -} - // ------------------------------------------------------------------------- std::string cpPlugins::Plugins::ImageWriter:: _GenerateData( ) { - itk::DataObject* o = this->_GetInput( 0 ); + cpPlugins::Interface::Image* image = + this->_Input< cpPlugins::Interface::Image >( 0 ); + if( image == NULL ) + return( "ImageWriter: No input image." ); + + itk::DataObject* itk_image = NULL; + std::string r = ""; + cpPlugins_Image_Input_Demangle_Dimension_AllTypes( + 2, image, itk_image, r, _RealGD + ); + else cpPlugins_Image_Input_Demangle_Dimension_AllTypes( + 3, image, itk_image, r, _RealGD + ); + else cpPlugins_Image_Input_Demangle_Dimension_AllTypes( + 4, image, itk_image, r, _RealGD + ); + else cpPlugins_Image_Input_Demangle( + itk::DiffusionTensor3D< float >, 3, image, itk_image, r, _RealGD + ); + else cpPlugins_Image_Input_Demangle( + itk::DiffusionTensor3D< double >, 3, image, itk_image, r, _RealGD + ); + else r = "ImageWriter: Input image type not supported."; - std::string r = "cpPlugins::Plugins::ImageWriter: itk::Image dimension not supported."; - cpPlugins_ImageWriter_Dimension( r, 1, o, _GD0 ); - else cpPlugins_ImageWriter_Dimension( r, 2, o, _GD0 ); - else cpPlugins_ImageWriter_Dimension( r, 3, o, _GD0 ); - else cpPlugins_ImageWriter_Dimension( r, 4, o, _GD0 ); return( r ); } // ------------------------------------------------------------------------- -template< unsigned int D > +template< class I > std::string cpPlugins::Plugins::ImageWriter:: -_GD0( ) +_RealGD( itk::DataObject* image ) { - itk::ImageBase< D >* i = - dynamic_cast< itk::ImageBase< D >* >( this->_GetInput( 0 ) ); - - std::string r = "cpPlugins::Plugins::ImageWriter: itk::Image pixel type not supported"; - cpPlugins_ImageWriter_Pixel( r, char, D, i, _GD1 ); - else cpPlugins_ImageWriter_Pixel( r, short, D, i, _GD1 ); - else cpPlugins_ImageWriter_Pixel( r, int, D, i, _GD1 ); - else cpPlugins_ImageWriter_Pixel( r, long, D, i, _GD1 ); - else cpPlugins_ImageWriter_Pixel( r, unsigned char, D, i, _GD1 ); - else cpPlugins_ImageWriter_Pixel( r, unsigned short, D, i, _GD1 ); - else cpPlugins_ImageWriter_Pixel( r, unsigned int, D, i, _GD1 ); - else cpPlugins_ImageWriter_Pixel( r, unsigned long, D, i, _GD1 ); - else cpPlugins_ImageWriter_Pixel( r, float, D, i, _GD1 ); - else cpPlugins_ImageWriter_Pixel( r, double, D, i, _GD1 ); - else cpPlugins_ImageWriter_RGB( r, char, D, i, _GD1 ); - else cpPlugins_ImageWriter_RGB( r, short, D, i, _GD1 ); - else cpPlugins_ImageWriter_RGB( r, int, D, i, _GD1 ); - else cpPlugins_ImageWriter_RGB( r, long, D, i, _GD1 ); - else cpPlugins_ImageWriter_RGB( r, unsigned char, D, i, _GD1 ); - else cpPlugins_ImageWriter_RGB( r, unsigned short, D, i, _GD1 ); - else cpPlugins_ImageWriter_RGB( r, unsigned int, D, i, _GD1 ); - else cpPlugins_ImageWriter_RGB( r, unsigned long, D, i, _GD1 ); - else cpPlugins_ImageWriter_RGB( r, float, D, i, _GD1 ); - else cpPlugins_ImageWriter_RGB( r, double, D, i, _GD1 ); - return( r ); -} - -// ------------------------------------------------------------------------- -template< class P, unsigned int D > -std::string cpPlugins::Plugins::ImageWriter:: -_GD1( ) -{ - typedef itk::Image< P, D > _TImage; - typedef itk::ImageFileWriter< _TImage > _TImageWriter; - - TParameters::const_iterator fIt; - - // Get image pixelType - fIt = this->m_Parameters.find( "FileName" ); - if( fIt == this->m_Parameters.end( ) ) - fIt = this->m_DefaultParameters.find( "FileName" ); - - _TImageWriter* writer = - dynamic_cast< _TImageWriter* >( this->m_Writer.GetPointer( ) ); + typedef itk::ImageFileWriter< I > _W; + + // Get filename + std::string fname = this->m_Parameters.GetValueAsString( "FileName" ); + _W* writer = dynamic_cast< _W* >( this->m_RealProcessObject.GetPointer( ) ); if( writer == NULL ) { - this->m_Writer = _TImageWriter::New( ); - writer = dynamic_cast< _TImageWriter* >( this->m_Writer.GetPointer( ) ); + this->m_RealProcessObject = _W::New( ); + writer = dynamic_cast< _W* >( this->m_RealProcessObject.GetPointer( ) ); } // fi - writer->SetFileName( fIt->second.second ); - writer->SetInput( dynamic_cast< _TImage* >( this->_GetInput( 0 ) ) ); + writer->SetFileName( fname ); + writer->SetInput( dynamic_cast< I* >( image ) ); try { writer->Update( ); } catch( itk::ExceptionObject& err ) { - return( err.GetDescription( ) ); + return( "ImageWriter: " + std::string( err.GetDescription( ) ) ); } // yrt return( "" );