1 #include "ImageWriter.h"
2 #include <cpPlugins/Interface/Image.h>
4 #include <itkImageFileWriter.h>
6 #ifdef cpPlugins_Interface_QT4
8 #endif // cpPlugins_Interface_QT4
10 // -------------------------------------------------------------------------
11 cpPlugins::IO::ImageWriter::
12 DialogResult cpPlugins::IO::ImageWriter::
13 ExecConfigurationDialog( QWidget* parent )
15 DialogResult r = Self::DialogResult_Cancel;
17 #ifdef cpPlugins_Interface_QT4
19 std::string name = this->m_Parameters->GetString( "FileName" );
23 // Show dialog and check if it was accepted
25 QFileDialog::getSaveFileName(
27 QFileDialog::tr( "Save File" ),
28 QFileDialog::tr( name.c_str( ) ),
29 QFileDialog::tr( "Image files (*.bmp *.png *.jpg *.jpeg *.dcm *.mhd *.nhdr *.nrrd *.tiff);;Any file (*)")
31 name = qname.toStdString( );
34 this->m_Parameters->SetString( "FileName", name );
35 r = Self::DialogResult_NoModal;
39 #endif // cpPlugins_Interface_QT4
44 // -------------------------------------------------------------------------
45 cpPlugins::IO::ImageWriter::
49 this->_AddInput( "Input" );
51 this->m_Parameters->ConfigureAsString( "FileName", "" );
54 // -------------------------------------------------------------------------
55 cpPlugins::IO::ImageWriter::
60 // -------------------------------------------------------------------------
61 std::string cpPlugins::IO::ImageWriter::
64 // Thank you very much Microsoft !!! :-@
65 std::string r = this->_GD0_Image< 2 >( );
66 if( r != "" ) r = this->_GD0_Image< 3 >( );
67 if( r != "" ) r = this->_GD0_Image< 4 >( );
68 if( r != "" ) r = this->_GD0_VectorImage< 2 >( );
69 if( r != "" ) r = this->_GD0_VectorImage< 3 >( );
70 if( r != "" ) r = this->_GD0_VectorImage< 4 >( );
74 // -------------------------------------------------------------------------
75 template< unsigned int D >
76 std::string cpPlugins::IO::ImageWriter::
79 cpPlugins::Interface::Image* image =
80 this->GetInput< 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 cpPlugins::Interface::Image* image =
98 this->GetInput< cpPlugins::Interface::Image >( "Input" );
100 return( "ImageWriter: No input image." );
102 itk::DataObject* itk_image = NULL;
104 cpPlugins_VectorImage_Demangle_AllTypes( D, image, itk_image, r, _RealGD );
105 else r = "ImageWriter: Input image type not supported.";
110 // -------------------------------------------------------------------------
112 std::string cpPlugins::IO::ImageWriter::
113 _RealGD( itk::DataObject* image )
116 std::string fname = this->m_Parameters->GetString( "FileName" );
118 typedef itk::ImageFileWriter< I > _W;
119 _W* writer = this->_CreateITK< _W >( );
120 writer->SetFileName( fname );
121 writer->SetInput( dynamic_cast< I* >( image ) );
126 catch( itk::ExceptionObject& err )
128 return( "ImageWriter: " + std::string( err.GetDescription( ) ) );