]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/ImageWriter.cxx
176e9f663ee9197aaabb01bfdd5423a936f6fd3f
[cpPlugins.git] / lib / cpPlugins / Plugins / ImageWriter.cxx
1 #include <cpPlugins/Plugins/ImageWriter.h>
2
3 #include <complex>
4
5 #define ITK_MANUAL_INSTANTIATION
6 #include <itkImage.h>
7
8 #include <itkCovariantVector.h>
9 #include <itkDiffusionTensor3D.h>
10 #include <itkPoint.h>
11 #include <itkRGBPixel.h>
12 #include <itkRGBAPixel.h>
13 #include <itkSymmetricSecondRankTensor.h>
14 #include <itkVector.h>
15
16 #undef ITK_MANUAL_INSTANTIATION
17 #include <itkImageFileWriter.h>
18
19 // -------------------------------------------------------------------------
20 cpPlugins::Plugins::ImageWriter::
21 ImageWriter( )
22   : Superclass( )
23 {
24   this->m_ClassName = "cpPlugins::ImageWriter";
25   this->m_ClassCategory = "ImageWriter";
26   this->SetNumberOfInputs( 1 );
27
28   using namespace cpPlugins::Interface;
29   this->m_DefaultParameters.Configure( Parameters::String, "FileName" );
30   this->m_Parameters = this->m_DefaultParameters;
31 }
32
33 // -------------------------------------------------------------------------
34 cpPlugins::Plugins::ImageWriter::
35 ~ImageWriter( )
36 {
37 }
38
39 // -------------------------------------------------------------------------
40 std::string cpPlugins::Plugins::ImageWriter::
41 _GenerateData( )
42 {
43   itk::DataObject* i = this->m_Inputs[ 0 ]->GetITKDataObject( );
44   return( this->_DemangleImageDimension( i ) );
45 }
46
47 // -------------------------------------------------------------------------
48 namespace cpPlugins
49 {
50   namespace Plugins
51   {
52     cpPlugins_Image_Demangle_Methods_Code( ImageWriter, _RealGD );
53   }
54 }
55
56 // -------------------------------------------------------------------------
57 template< class I >
58 std::string cpPlugins::Plugins::ImageWriter::
59 _RealGD( itk::DataObject* image )
60 {
61   typedef itk::ImageFileWriter< I > _W;
62
63   // Get filename
64   using namespace cpPlugins::Interface;
65   Parameters::TString fname =
66     this->m_Parameters.GetValueAsString( "FileName" );
67
68   _W* writer = dynamic_cast< _W* >( this->m_RealProcessObject.GetPointer( ) );
69   if( writer == NULL )
70   {
71     this->m_RealProcessObject = _W::New( );
72     writer = dynamic_cast< _W* >( this->m_RealProcessObject.GetPointer( ) );
73
74   } // fi
75   writer->SetFileName( fname );
76   writer->SetInput( dynamic_cast< I* >( image ) );
77   try
78   {
79     writer->Update( );
80   }
81   catch( itk::ExceptionObject& err )
82   {
83     return( "ImageWriter: " + std::string( err.GetDescription( ) ) );
84
85   } // yrt
86   return( "" );
87 }
88
89 // eof - $RCSfile$