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