1 #include <cpPlugins/Plugins/ImageWriter.h>
3 #undef ITK_MANUAL_INSTANTIATION
5 #include <itkRGBPixel.h>
6 #include <itkImageFileWriter.h>
8 // -------------------------------------------------------------------------
9 #define cpPlugins_ImageWriter_Dimension( r, d, i, f ) \
10 if( dynamic_cast< itk::ImageBase< d >* >( i ) != NULL ) \
13 // -------------------------------------------------------------------------
14 #define cpPlugins_ImageWriter_Pixel( r, p, d, i, f ) \
15 if( dynamic_cast< itk::Image< p, d >* >( i ) != NULL ) \
16 r = this->f< p, d >( i )
18 // -------------------------------------------------------------------------
19 #define cpPlugins_ImageWriter_RGB( r, p, d, i, f ) \
21 dynamic_cast< itk::Image< itk::RGBPixel< p >, d >* >( i ) != NULL \
23 r = this->f< itk::RGBPixel< p >, d >( i )
25 // -------------------------------------------------------------------------
26 cpPlugins::Plugins::ImageWriter::
30 this->m_ClassName = "cpPlugins::ImageWriter";
31 this->m_ClassCategory = "ImageWriter";
32 this->SetNumberOfInputs( 1 );
34 using namespace cpPlugins::Interface;
35 this->m_DefaultParameters.Configure( Parameters::String, "FileName" );
36 this->m_Parameters = this->m_DefaultParameters;
39 // -------------------------------------------------------------------------
40 cpPlugins::Plugins::ImageWriter::
45 // -------------------------------------------------------------------------
46 std::string cpPlugins::Plugins::ImageWriter::
49 itk::DataObject* i = this->m_Inputs[ 0 ]->GetITKDataObject( );
51 std::string r = "ImageWriter: Image dimension not supported.";
52 cpPlugins_ImageWriter_Dimension ( r, 1, i, _GD0 );
53 else cpPlugins_ImageWriter_Dimension( r, 2, i, _GD0 );
54 else cpPlugins_ImageWriter_Dimension( r, 3, i, _GD0 );
58 // -------------------------------------------------------------------------
59 template< unsigned int D >
60 std::string cpPlugins::Plugins::ImageWriter::
61 _GD0( itk::DataObject* i )
63 std::string r = "ImageWriter: Image pixel type not supported";
64 cpPlugins_ImageWriter_Pixel ( r, char , D, i, _GD1 );
65 else cpPlugins_ImageWriter_Pixel( r, short , D, i, _GD1 );
66 else cpPlugins_ImageWriter_Pixel( r, int , D, i, _GD1 );
67 else cpPlugins_ImageWriter_Pixel( r, long , D, i, _GD1 );
68 else cpPlugins_ImageWriter_Pixel( r, unsigned char , D, i, _GD1 );
69 else cpPlugins_ImageWriter_Pixel( r, unsigned short, D, i, _GD1 );
70 else cpPlugins_ImageWriter_Pixel( r, unsigned int , D, i, _GD1 );
71 else cpPlugins_ImageWriter_Pixel( r, unsigned long , D, i, _GD1 );
72 else cpPlugins_ImageWriter_Pixel( r, float , D, i, _GD1 );
73 else cpPlugins_ImageWriter_Pixel( r, double , D, i, _GD1 );
74 else cpPlugins_ImageWriter_RGB ( r, char , D, i, _GD1 );
75 else cpPlugins_ImageWriter_RGB ( r, short , D, i, _GD1 );
76 else cpPlugins_ImageWriter_RGB ( r, int , D, i, _GD1 );
77 else cpPlugins_ImageWriter_RGB ( r, long , D, i, _GD1 );
78 else cpPlugins_ImageWriter_RGB ( r, unsigned char , D, i, _GD1 );
79 else cpPlugins_ImageWriter_RGB ( r, unsigned short, D, i, _GD1 );
80 else cpPlugins_ImageWriter_RGB ( r, unsigned int , D, i, _GD1 );
81 else cpPlugins_ImageWriter_RGB ( r, unsigned long , D, i, _GD1 );
82 else cpPlugins_ImageWriter_RGB ( r, float , D, i, _GD1 );
83 else cpPlugins_ImageWriter_RGB ( r, double , D, i, _GD1 );
87 // -------------------------------------------------------------------------
88 template< class P, unsigned int D >
89 std::string cpPlugins::Plugins::ImageWriter::
90 _GD1( itk::DataObject* i )
92 typedef itk::Image< P, D > _I;
93 typedef itk::ImageFileWriter< _I > _W;
96 using namespace cpPlugins::Interface;
97 Parameters::TString fname =
98 this->m_Parameters.GetValueAsString( "FileName" );
100 _W* writer = dynamic_cast< _W* >( this->m_RealProcessObject.GetPointer( ) );
103 this->m_RealProcessObject = _W::New( );
104 writer = dynamic_cast< _W* >( this->m_RealProcessObject.GetPointer( ) );
107 writer->SetFileName( fname );
108 writer->SetInput( dynamic_cast< _I* >( i ) );
113 catch( itk::ExceptionObject& err )
115 return( "ImageWriter: " + std::string( err.GetDescription( ) ) );