]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/IO/ImageWriter.cxx
Widget integration (step 5/6): Interactive plugins now supported, widgets updates...
[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->SetNumberOfInputs( 1 );
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   cpPlugins::Interface::Image* image =
27     this->GetInput< cpPlugins::Interface::Image >( 0 );
28   if( image == NULL )
29     return( "ImageWriter: No input image." );
30
31   itk::DataObject* itk_image = NULL;
32   std::string r = "";
33   cpPlugins_Image_Demangle_AllTypes( 2, image, itk_image, r, _RealGD );
34   else cpPlugins_Image_Demangle_AllTypes( 3, image, itk_image, r, _RealGD );
35   else cpPlugins_Image_Demangle_AllTypes( 4, image, itk_image, r, _RealGD );
36   else cpPlugins_VectorImage_Demangle_AllTypes( 2, image, itk_image, r, _RealGD );
37   else cpPlugins_VectorImage_Demangle_AllTypes( 3, image, itk_image, r, _RealGD );
38   else cpPlugins_VectorImage_Demangle_AllTypes( 4, image, itk_image, r, _RealGD );
39   else r = "ImageWriter: Input image type not supported.";
40
41   return( r );
42 }
43
44 // -------------------------------------------------------------------------
45 template< class I >
46 std::string cpPlugins::IO::ImageWriter::
47 _RealGD( itk::DataObject* image )
48 {
49   // Get filename
50   std::string fname = this->m_Parameters->GetString( "FileName" );
51
52   typedef itk::ImageFileWriter< I > _W;
53   _W* writer = this->_CreateITK< _W >( );
54   writer->SetFileName( fname );
55   writer->SetInput( dynamic_cast< I* >( image ) );
56   try
57   {
58     writer->Update( );
59   }
60   catch( itk::ExceptionObject& err )
61   {
62     return( "ImageWriter: " + std::string( err.GetDescription( ) ) );
63
64   } // yrt
65   return( "" );
66 }
67
68 // eof - $RCSfile$