]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/IO/ImageWriter.cxx
Widget integration (step 4/6)... Testing on windows.
[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->m_ClassName = "cpPlugins::IO::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::IO::ImageWriter::
22 ~ImageWriter( )
23 {
24 }
25
26 // -------------------------------------------------------------------------
27 std::string cpPlugins::IO::ImageWriter::
28 _GenerateData( )
29 {
30   cpPlugins::Interface::Image* image =
31     this->GetInput< 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_Demangle_AllTypes( 2, image, itk_image, r, _RealGD );
38   else cpPlugins_Image_Demangle_AllTypes( 3, image, itk_image, r, _RealGD );
39   else cpPlugins_Image_Demangle_AllTypes( 4, image, itk_image, r, _RealGD );
40   else cpPlugins_VectorImage_Demangle_AllTypes( 2, image, itk_image, r, _RealGD );
41   else cpPlugins_VectorImage_Demangle_AllTypes( 3, image, itk_image, r, _RealGD );
42   else cpPlugins_VectorImage_Demangle_AllTypes( 4, image, itk_image, r, _RealGD );
43   else r = "ImageWriter: Input image type not supported.";
44
45   return( r );
46 }
47
48 // -------------------------------------------------------------------------
49 template< class I >
50 std::string cpPlugins::IO::ImageWriter::
51 _RealGD( itk::DataObject* image )
52 {
53   // Get filename
54   std::string fname = this->m_Parameters.GetValueAsString( "FileName" );
55
56   typedef itk::ImageFileWriter< I > _W;
57   _W* writer = this->_CreateITK< _W >( );
58   writer->SetFileName( fname );
59   writer->SetInput( dynamic_cast< I* >( image ) );
60   try
61   {
62     writer->Update( );
63   }
64   catch( itk::ExceptionObject& err )
65   {
66     return( "ImageWriter: " + std::string( err.GetDescription( ) ) );
67
68   } // yrt
69   return( "" );
70 }
71
72 // eof - $RCSfile$