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 cpPlugins::Interface::Image* image =
81 this->GetInput< cpPlugins::Interface::Image >( "Input" );
83 return( "ImageWriter: No input image." );
85 itk::DataObject* itk_image = NULL;
87 cpPlugins_Image_Demangle_AllTypes( D, image, itk_image, r, _RealGD );
88 else r = "ImageWriter: Input image type not supported.";
93 // -------------------------------------------------------------------------
94 template< unsigned int D >
95 std::string cpPlugins::IO::ImageWriter::
98 cpPlugins::Interface::Image* image =
99 this->GetInput< cpPlugins::Interface::Image >( "Input" );
101 return( "ImageWriter: No input image." );
103 itk::DataObject* itk_image = NULL;
105 cpPlugins_VectorImage_Demangle_AllTypes( D, image, itk_image, r, _RealGD );
106 else r = "ImageWriter: Input image type not supported.";
111 // -------------------------------------------------------------------------
113 std::string cpPlugins::IO::ImageWriter::
114 _RealGD( itk::DataObject* image )
117 std::string fname = this->m_Parameters->GetSaveFileName( "FileName" );
119 typedef itk::ImageFileWriter< I > _W;
120 _W* writer = this->_CreateITK< _W >( );
121 writer->SetFileName( fname );
122 writer->SetInput( dynamic_cast< I* >( image ) );
127 catch( itk::ExceptionObject& err )
129 return( "ImageWriter: " + std::string( err.GetDescription( ) ) );