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 this->m_DefaultParameters[ "FileName" ] =
41 TParameter( "string", "no_file_name" );
44 // -------------------------------------------------------------------------
45 cpPlugins::Plugins::ImageWriter::
50 // -------------------------------------------------------------------------
51 std::string cpPlugins::Plugins::ImageWriter::
54 itk::DataObject* o = this->_GetInput( 0 );
56 std::string r = "cpPlugins::Plugins::ImageWriter: itk::Image dimension not supported.";
57 cpPlugins_ImageWriter_Dimension( r, 1, o, _GD0 );
58 else cpPlugins_ImageWriter_Dimension( r, 2, o, _GD0 );
59 else cpPlugins_ImageWriter_Dimension( r, 3, o, _GD0 );
60 else cpPlugins_ImageWriter_Dimension( r, 4, o, _GD0 );
64 // -------------------------------------------------------------------------
65 template< unsigned int D >
66 std::string cpPlugins::Plugins::ImageWriter::
69 itk::ImageBase< D >* i =
70 dynamic_cast< itk::ImageBase< D >* >( this->_GetInput( 0 ) );
72 std::string r = "cpPlugins::Plugins::ImageWriter: itk::Image pixel type not supported";
73 cpPlugins_ImageWriter_Pixel( r, char, D, i, _GD1 );
74 else cpPlugins_ImageWriter_Pixel( r, short, D, i, _GD1 );
75 else cpPlugins_ImageWriter_Pixel( r, int, D, i, _GD1 );
76 else cpPlugins_ImageWriter_Pixel( r, long, D, i, _GD1 );
77 else cpPlugins_ImageWriter_Pixel( r, unsigned char, D, i, _GD1 );
78 else cpPlugins_ImageWriter_Pixel( r, unsigned short, D, i, _GD1 );
79 else cpPlugins_ImageWriter_Pixel( r, unsigned int, D, i, _GD1 );
80 else cpPlugins_ImageWriter_Pixel( r, unsigned long, D, i, _GD1 );
81 else cpPlugins_ImageWriter_Pixel( r, float, D, i, _GD1 );
82 else cpPlugins_ImageWriter_Pixel( r, double, D, i, _GD1 );
83 else cpPlugins_ImageWriter_RGB( r, char, D, i, _GD1 );
84 else cpPlugins_ImageWriter_RGB( r, short, D, i, _GD1 );
85 else cpPlugins_ImageWriter_RGB( r, int, D, i, _GD1 );
86 else cpPlugins_ImageWriter_RGB( r, long, D, i, _GD1 );
87 else cpPlugins_ImageWriter_RGB( r, unsigned char, D, i, _GD1 );
88 else cpPlugins_ImageWriter_RGB( r, unsigned short, D, i, _GD1 );
89 else cpPlugins_ImageWriter_RGB( r, unsigned int, D, i, _GD1 );
90 else cpPlugins_ImageWriter_RGB( r, unsigned long, D, i, _GD1 );
91 else cpPlugins_ImageWriter_RGB( r, float, D, i, _GD1 );
92 else cpPlugins_ImageWriter_RGB( r, double, D, i, _GD1 );
96 // -------------------------------------------------------------------------
97 template< class P, unsigned int D >
98 std::string cpPlugins::Plugins::ImageWriter::
101 typedef itk::Image< P, D > _TImage;
102 typedef itk::ImageFileWriter< _TImage > _TWriter;
104 TParameters::const_iterator fIt;
106 // Get image pixelType
107 fIt = this->m_Parameters.find( "FileName" );
108 if( fIt == this->m_Parameters.end( ) )
109 fIt = this->m_DefaultParameters.find( "FileName" );
112 dynamic_cast< _TWriter* >( this->m_RealProcessObject.GetPointer( ) );
115 this->m_RealProcessObject = _TWriter::New( );
117 dynamic_cast< _TWriter* >( this->m_RealProcessObject.GetPointer( ) );
120 writer->SetFileName( fIt->second.second );
121 writer->SetInput( dynamic_cast< _TImage* >( this->_GetInput( 0 ) ) );
126 catch( itk::ExceptionObject& err )
128 return( err.GetDescription( ) );