1 #include <cpPlugins/Plugins/ImageWriter.h>
3 #include <itkImageFileWriter.h>
5 #define ITK_MANUAL_INSTANTIATION
7 #include <itkRGBPixel.h>
9 // -------------------------------------------------------------------------
10 #define cpPlugins_ImageWriter_Dimension( r, d, o, f ) \
11 if( dynamic_cast< itk::ImageBase< d >* >( o ) != NULL ) \
14 // -------------------------------------------------------------------------
15 #define cpPlugins_ImageWriter_Pixel( r, p, d, o, f ) \
16 if( dynamic_cast< itk::Image< p, d >* >( o ) != NULL ) \
17 r = this->f< p, d >( )
19 // -------------------------------------------------------------------------
20 #define cpPlugins_ImageWriter_RGB( r, p, d, o, f ) \
22 dynamic_cast< itk::Image< itk::RGBPixel< p >, d >* >( o ) != NULL \
24 r = this->f< itk::RGBPixel< p >, d >( )
26 // -------------------------------------------------------------------------
27 std::string cpPlugins::Plugins::ImageWriter::
30 return( "cpPlugins::Plugins::ImageWriter" );
33 // -------------------------------------------------------------------------
34 cpPlugins::Plugins::ImageWriter::
38 this->SetNumberOfInputs( 1 );
40 using namespace cpPlugins::Interface;
41 this->m_DefaultParameters.Configure( Parameters::String, "FileName" );
42 this->m_Parameters = this->m_DefaultParameters;
45 // -------------------------------------------------------------------------
46 cpPlugins::Plugins::ImageWriter::
51 // -------------------------------------------------------------------------
52 std::string cpPlugins::Plugins::ImageWriter::
55 itk::DataObject* o = this->_GetInput( 0 );
57 std::string r = "cpPlugins::Plugins::ImageWriter: itk::Image dimension not supported.";
58 cpPlugins_ImageWriter_Dimension( r, 1, o, _GD0 );
59 else cpPlugins_ImageWriter_Dimension( r, 2, o, _GD0 );
60 else cpPlugins_ImageWriter_Dimension( r, 3, o, _GD0 );
61 else cpPlugins_ImageWriter_Dimension( r, 4, o, _GD0 );
65 // -------------------------------------------------------------------------
66 template< unsigned int D >
67 std::string cpPlugins::Plugins::ImageWriter::
70 itk::ImageBase< D >* i =
71 dynamic_cast< itk::ImageBase< D >* >( this->_GetInput( 0 ) );
73 std::string r = "cpPlugins::Plugins::ImageWriter: itk::Image pixel type not supported";
74 cpPlugins_ImageWriter_Pixel( r, char, D, i, _GD1 );
75 else cpPlugins_ImageWriter_Pixel( r, short, D, i, _GD1 );
76 else cpPlugins_ImageWriter_Pixel( r, int, D, i, _GD1 );
77 else cpPlugins_ImageWriter_Pixel( r, long, D, i, _GD1 );
78 else cpPlugins_ImageWriter_Pixel( r, unsigned char, D, i, _GD1 );
79 else cpPlugins_ImageWriter_Pixel( r, unsigned short, D, i, _GD1 );
80 else cpPlugins_ImageWriter_Pixel( r, unsigned int, D, i, _GD1 );
81 else cpPlugins_ImageWriter_Pixel( r, unsigned long, D, i, _GD1 );
82 else cpPlugins_ImageWriter_Pixel( r, float, D, i, _GD1 );
83 else cpPlugins_ImageWriter_Pixel( r, double, D, i, _GD1 );
84 else cpPlugins_ImageWriter_RGB( r, char, D, i, _GD1 );
85 else cpPlugins_ImageWriter_RGB( r, short, D, i, _GD1 );
86 else cpPlugins_ImageWriter_RGB( r, int, D, i, _GD1 );
87 else cpPlugins_ImageWriter_RGB( r, long, D, i, _GD1 );
88 else cpPlugins_ImageWriter_RGB( r, unsigned char, D, i, _GD1 );
89 else cpPlugins_ImageWriter_RGB( r, unsigned short, D, i, _GD1 );
90 else cpPlugins_ImageWriter_RGB( r, unsigned int, D, i, _GD1 );
91 else cpPlugins_ImageWriter_RGB( r, unsigned long, D, i, _GD1 );
92 else cpPlugins_ImageWriter_RGB( r, float, D, i, _GD1 );
93 else cpPlugins_ImageWriter_RGB( r, double, D, i, _GD1 );
97 // -------------------------------------------------------------------------
98 template< class P, unsigned int D >
99 std::string cpPlugins::Plugins::ImageWriter::
102 typedef itk::Image< P, D > _TImage;
103 typedef itk::ImageFileWriter< _TImage > _TWriter;
106 using namespace cpPlugins::Interface;
107 Parameters::TString fname =
108 this->m_Parameters.GetValueAsString( "FileName" );
111 dynamic_cast< _TWriter* >( this->m_RealProcessObject.GetPointer( ) );
114 this->m_RealProcessObject = _TWriter::New( );
116 dynamic_cast< _TWriter* >( this->m_RealProcessObject.GetPointer( ) );
119 writer->SetFileName( fname );
120 writer->SetInput( dynamic_cast< _TImage* >( this->_GetInput( 0 ) ) );
125 catch( itk::ExceptionObject& err )
127 return( err.GetDescription( ) );