]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/ImageWriter.cxx
...
[cpPlugins.git] / lib / cpPlugins / Plugins / ImageWriter.cxx
1 #include <cpPlugins/Plugins/ImageWriter.h>
2 #include <cpPlugins/Interface/Image.h>
3
4 #include <itkImageFileWriter.h>
5
6 // -------------------------------------------------------------------------
7 cpPlugins::Plugins::ImageWriter::
8 ImageWriter( )
9   : Superclass( )
10 {
11   this->m_ClassName = "cpPlugins::ImageWriter";
12   this->m_ClassCategory = "ImageWriter";
13   this->SetNumberOfInputs( 1 );
14
15   using namespace cpPlugins::Interface;
16   this->m_DefaultParameters.Configure( Parameters::String, "FileName" );
17   this->m_Parameters = this->m_DefaultParameters;
18 }
19
20 // -------------------------------------------------------------------------
21 cpPlugins::Plugins::ImageWriter::
22 ~ImageWriter( )
23 {
24 }
25
26 // -------------------------------------------------------------------------
27 std::string cpPlugins::Plugins::ImageWriter::
28 _GenerateData( )
29 {
30   cpPlugins::Interface::Image* image =
31     this->_Input< cpPlugins::Interface::Image >( 0 );
32   if( image == NULL )
33     return( "ImageWriter: No input image." );
34
35   itk::DataObject* itk_image = NULL;
36   std::string r = "";
37   cpPlugins_Image_Input_Demangle_Dimension_AllTypes(
38     2, image, itk_image, r, _RealGD
39     );
40   else cpPlugins_Image_Input_Demangle_Dimension_AllTypes(
41     3, image, itk_image, r, _RealGD
42     );
43   else cpPlugins_Image_Input_Demangle_Dimension_AllTypes(
44     4, image, itk_image, r, _RealGD
45     );
46 #ifndef _WIN32 // win32: Nested loops error ????
47   else cpPlugins_Image_Input_Demangle(
48     itk::DiffusionTensor3D< float >, 3, image, itk_image, r, _RealGD
49     );
50   else cpPlugins_Image_Input_Demangle(
51     itk::DiffusionTensor3D< double >, 3, image, itk_image, r, _RealGD
52     );
53 #endif // _WIN32
54   else r = "ImageWriter: Input image type not supported.";
55
56   return( r );
57 }
58
59 // -------------------------------------------------------------------------
60 template< class I >
61 std::string cpPlugins::Plugins::ImageWriter::
62 _RealGD( itk::DataObject* image )
63 {
64   typedef itk::ImageFileWriter< I > _W;
65   
66   // Get filename
67   std::string fname = this->m_Parameters.GetValueAsString( "FileName" );
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$