]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/ImageWriter.cxx
2a7154edae944bff1a017fa3cb0a2650a9480600
[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   else cpPlugins_Image_Input_Demangle(
47     itk::DiffusionTensor3D< float >, 3, image, itk_image, r, _RealGD
48     );
49   else cpPlugins_Image_Input_Demangle(
50     itk::DiffusionTensor3D< double >, 3, image, itk_image, r, _RealGD
51     );
52   else r = "ImageWriter: Input image type not supported.";
53
54   return( r );
55 }
56
57 // -------------------------------------------------------------------------
58 template< class I >
59 std::string cpPlugins::Plugins::ImageWriter::
60 _RealGD( itk::DataObject* image )
61 {
62   typedef itk::ImageFileWriter< I > _W;
63   
64   // Get filename
65   std::string fname = this->m_Parameters.GetValueAsString( "FileName" );
66   _W* writer = dynamic_cast< _W* >( this->m_RealProcessObject.GetPointer( ) );
67   if( writer == NULL )
68   {
69     this->m_RealProcessObject = _W::New( );
70     writer = dynamic_cast< _W* >( this->m_RealProcessObject.GetPointer( ) );
71
72   } // fi
73   writer->SetFileName( fname );
74   writer->SetInput( dynamic_cast< I* >( image ) );
75   try
76   {
77     writer->Update( );
78   }
79   catch( itk::ExceptionObject& err )
80   {
81     return( "ImageWriter: " + std::string( err.GetDescription( ) ) );
82
83   } // yrt
84   return( "" );
85 }
86
87 // eof - $RCSfile$