1 #include "ImageWriter.h"
2 #include <cpPlugins/Interface/Image.h>
4 #include <itkImageFileWriter.h>
6 // -------------------------------------------------------------------------
7 cpPlugins::IO::ImageWriter::
11 this->_AddInput( "Input" );
12 this->m_Parameters->ConfigureAsSaveFileName( "FileName" );
13 this->m_Parameters->SetAcceptedFileExtensions(
15 "Image files (*.bmp *.png *.jpg *.jpeg *.dcm *.mhd *.nhdr *.nrrd *.tiff)"
19 // -------------------------------------------------------------------------
20 cpPlugins::IO::ImageWriter::
25 // -------------------------------------------------------------------------
26 std::string cpPlugins::IO::ImageWriter::
29 // Thank you very much Microsoft !!! :-@
30 std::string r = this->_GD0_Image< 2 >( );
31 if( r != "" ) r = this->_GD0_Image< 3 >( );
32 if( r != "" ) r = this->_GD0_Image< 4 >( );
33 if( r != "" ) r = this->_GD0_VectorImage< 2 >( );
34 if( r != "" ) r = this->_GD0_VectorImage< 3 >( );
35 if( r != "" ) r = this->_GD0_VectorImage< 4 >( );
39 // -------------------------------------------------------------------------
40 template< unsigned int D >
41 std::string cpPlugins::IO::ImageWriter::
44 auto image = this->GetInputData< cpPlugins::Interface::Image >( "Input" );
45 itk::DataObject* itk_image = NULL;
47 cpPlugins_Image_Demangle_AllTypes( D, image, itk_image, r, _RealGD );
48 else r = "ImageWriter: Input image type not supported.";
52 // -------------------------------------------------------------------------
53 template< unsigned int D >
54 std::string cpPlugins::IO::ImageWriter::
57 auto image = this->GetInputData< cpPlugins::Interface::Image >( "Input" );
58 itk::DataObject* itk_image = NULL;
60 cpPlugins_VectorImage_Demangle_AllTypes( D, image, itk_image, r, _RealGD );
61 else r = "ImageWriter: Input image type not supported.";
65 // -------------------------------------------------------------------------
67 std::string cpPlugins::IO::ImageWriter::
68 _RealGD( itk::DataObject* image )
70 typedef itk::ImageFileWriter< I > _W;
71 _W* writer = this->_CreateITK< _W >( );
72 writer->SetFileName( this->m_Parameters->GetSaveFileName( "FileName" ) );
73 writer->SetInput( dynamic_cast< I* >( image ) );
78 catch( itk::ExceptionObject& err )
80 return( "ImageWriter: " + std::string( err.GetDescription( ) ) );