X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FPlugins%2FImageWriter.cxx;h=41fdb301f0f67dc4375ef714d805e5794ab38bdf;hb=2d96cce7bcab0bdcd9e93e44ed413c47388151d9;hp=3dd319afef43ec75ef6d6476aa57ce70db4c23fc;hpb=8c23766af88a29c3e830299dffc4b95d9fe61df9;p=cpPlugins.git diff --git a/lib/cpPlugins/Plugins/ImageWriter.cxx b/lib/cpPlugins/Plugins/ImageWriter.cxx index 3dd319a..41fdb30 100644 --- a/lib/cpPlugins/Plugins/ImageWriter.cxx +++ b/lib/cpPlugins/Plugins/ImageWriter.cxx @@ -1,10 +1,37 @@ #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->SetNumberOfInputs( 1 ); + + this->m_DefaultParameters[ "FileName" ] = + TParameter( "string", "no_file_name" ); } // ------------------------------------------------------------------------- @@ -21,10 +48,86 @@ GetClassName( ) const } // ------------------------------------------------------------------------- -bool cpPlugins::Plugins::ImageWriter:: -Update( ) +std::string cpPlugins::Plugins::ImageWriter:: +_GenerateData( ) { - return( false ); + itk::DataObject* o = this->_GetInput( 0 ); + + 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 > +std::string cpPlugins::Plugins::ImageWriter:: +_GD0( ) +{ + 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( ) ); + if( writer == NULL ) + { + this->m_Writer = _TImageWriter::New( ); + writer = dynamic_cast< _TImageWriter* >( this->m_Writer.GetPointer( ) ); + + } // fi + writer->SetFileName( fIt->second.second ); + writer->SetInput( dynamic_cast< _TImage* >( this->_GetInput( 0 ) ) ); + try + { + writer->Update( ); + } + catch( itk::ExceptionObject& err ) + { + return( err.GetDescription( ) ); + + } // yrt + return( "" ); } // eof - $RCSfile$