]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/IO/ImageWriter.cxx
Widget integration (step 6/6): Interactive architecture finished. Needs to be tested...
[cpPlugins.git] / lib / cpPlugins / Plugins / IO / ImageWriter.cxx
1 #include "ImageWriter.h"
2 #include <cpPlugins/Interface/Image.h>
3
4 #include <itkImageFileWriter.h>
5
6 // -------------------------------------------------------------------------
7 cpPlugins::IO::ImageWriter::
8 ImageWriter( )
9   : Superclass( )
10 {
11   this->_AddInput( "Input" );
12
13   this->m_Parameters->ConfigureAsString( "FileName", "" );
14 }
15
16 // -------------------------------------------------------------------------
17 cpPlugins::IO::ImageWriter::
18 ~ImageWriter( )
19 {
20 }
21
22 // -------------------------------------------------------------------------
23 std::string cpPlugins::IO::ImageWriter::
24 _GenerateData( )
25 {
26   // Thank you very much Microsoft !!! :-@
27   std::string   r = this->_GD0_Image< 2 >( );
28   if( r != "" ) r = this->_GD0_Image< 3 >( );
29   if( r != "" ) r = this->_GD0_Image< 4 >( );
30   if( r != "" ) r = this->_GD0_VectorImage< 2 >( );
31   if( r != "" ) r = this->_GD0_VectorImage< 3 >( );
32   if( r != "" ) r = this->_GD0_VectorImage< 4 >( );
33   return( r );
34 }
35
36 // -------------------------------------------------------------------------
37 template< unsigned int D >
38 std::string cpPlugins::IO::ImageWriter::
39 _GD0_Image( )
40 {
41   cpPlugins::Interface::Image* image =
42     this->GetInput< cpPlugins::Interface::Image >( "Input" );
43   if( image == NULL )
44     return( "ImageWriter: No input image." );
45
46   itk::DataObject* itk_image = NULL;
47   std::string r = "";
48   cpPlugins_Image_Demangle_AllTypes( D, image, itk_image, r, _RealGD );
49   else r = "ImageWriter: Input image type not supported.";
50
51   return( r );
52 }
53
54 // -------------------------------------------------------------------------
55 template< unsigned int D >
56 std::string cpPlugins::IO::ImageWriter::
57 _GD0_VectorImage( )
58 {
59   cpPlugins::Interface::Image* image =
60     this->GetInput< cpPlugins::Interface::Image >( "Input" );
61   if( image == NULL )
62     return( "ImageWriter: No input image." );
63
64   itk::DataObject* itk_image = NULL;
65   std::string r = "";
66   cpPlugins_VectorImage_Demangle_AllTypes( D, image, itk_image, r, _RealGD );
67   else r = "ImageWriter: Input image type not supported.";
68
69   return( r );
70 }
71
72 // -------------------------------------------------------------------------
73 template< class I >
74 std::string cpPlugins::IO::ImageWriter::
75 _RealGD( itk::DataObject* image )
76 {
77   // Get filename
78   std::string fname = this->m_Parameters->GetString( "FileName" );
79
80   typedef itk::ImageFileWriter< I > _W;
81   _W* writer = this->_CreateITK< _W >( );
82   writer->SetFileName( fname );
83   writer->SetInput( dynamic_cast< I* >( image ) );
84   try
85   {
86     writer->Update( );
87   }
88   catch( itk::ExceptionObject& err )
89   {
90     return( "ImageWriter: " + std::string( err.GetDescription( ) ) );
91
92   } // yrt
93   return( "" );
94 }
95
96 // eof - $RCSfile$