1 #include "ImageWriter.h"
2 #include <cpPlugins/Interface/Image.h>
4 #include <itkImageFileWriter.h>
7 #ifdef cpPlugins_Interface_QT4
9 #endif // cpPlugins_Interface_QT4
11 // -------------------------------------------------------------------------
12 cpPlugins::IO::ImageWriter::
13 DialogResult cpPlugins::IO::ImageWriter::
14 ExecConfigurationDialog( QWidget* parent )
16 DialogResult r = Self::DialogResult_Cancel;
18 #ifdef cpPlugins_Interface_QT4
20 std::string name = this->m_Parameters->GetString( "FileName" );
24 // Show dialog and check if it was accepted
26 QFileDialog::getSaveFileName(
28 QFileDialog::tr( "Save File" ),
29 QFileDialog::tr( name.c_str( ) ),
30 QFileDialog::tr( "Image files (*.bmp *.png *.jpg *.jpeg *.dcm *.mhd *.nhdr *.nrrd *.tiff);;Any file (*)")
32 name = qname.toStdString( );
35 this->m_Parameters->SetString( "FileName", name );
36 r = Self::DialogResult_NoModal;
40 #endif // cpPlugins_Interface_QT4
46 // -------------------------------------------------------------------------
47 cpPlugins::IO::ImageWriter::
51 this->_AddInput( "Input" );
52 this->m_Parameters->ConfigureAsSaveFileName( "FileName" );
55 // -------------------------------------------------------------------------
56 cpPlugins::IO::ImageWriter::
61 // -------------------------------------------------------------------------
62 std::string cpPlugins::IO::ImageWriter::
65 // Thank you very much Microsoft !!! :-@
66 std::string r = this->_GD0_Image< 2 >( );
67 if( r != "" ) r = this->_GD0_Image< 3 >( );
68 if( r != "" ) r = this->_GD0_Image< 4 >( );
69 if( r != "" ) r = this->_GD0_VectorImage< 2 >( );
70 if( r != "" ) r = this->_GD0_VectorImage< 3 >( );
71 if( r != "" ) r = this->_GD0_VectorImage< 4 >( );
75 // -------------------------------------------------------------------------
76 template< unsigned int D >
77 std::string cpPlugins::IO::ImageWriter::
80 auto image = this->GetInputData< cpPlugins::Interface::Image >( "Input" );
82 return( "ImageWriter: No input image." );
84 itk::DataObject* itk_image = NULL;
86 cpPlugins_Image_Demangle_AllTypes( D, image, itk_image, r, _RealGD );
87 else r = "ImageWriter: Input image type not supported.";
92 // -------------------------------------------------------------------------
93 template< unsigned int D >
94 std::string cpPlugins::IO::ImageWriter::
97 auto image = this->GetInputData< cpPlugins::Interface::Image >( "Input" );
99 return( "ImageWriter: No input image." );
101 itk::DataObject* itk_image = NULL;
103 cpPlugins_VectorImage_Demangle_AllTypes( D, image, itk_image, r, _RealGD );
104 else r = "ImageWriter: Input image type not supported.";
109 // -------------------------------------------------------------------------
111 std::string cpPlugins::IO::ImageWriter::
112 _RealGD( itk::DataObject* image )
115 std::string fname = this->m_Parameters->GetSaveFileName( "FileName" );
117 typedef itk::ImageFileWriter< I > _W;
118 _W* writer = this->_CreateITK< _W >( );
119 writer->SetFileName( fname );
120 writer->SetInput( dynamic_cast< I* >( image ) );
125 catch( itk::ExceptionObject& err )
127 return( "ImageWriter: " + std::string( err.GetDescription( ) ) );