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" );
50 this->m_Parameters->ConfigureAsString( "FileName" );
53 // -------------------------------------------------------------------------
54 cpPlugins::IO::ImageWriter::
59 // -------------------------------------------------------------------------
60 std::string cpPlugins::IO::ImageWriter::
63 // Thank you very much Microsoft !!! :-@
64 std::string r = this->_GD0_Image< 2 >( );
65 if( r != "" ) r = this->_GD0_Image< 3 >( );
66 if( r != "" ) r = this->_GD0_Image< 4 >( );
67 if( r != "" ) r = this->_GD0_VectorImage< 2 >( );
68 if( r != "" ) r = this->_GD0_VectorImage< 3 >( );
69 if( r != "" ) r = this->_GD0_VectorImage< 4 >( );
73 // -------------------------------------------------------------------------
74 template< unsigned int D >
75 std::string cpPlugins::IO::ImageWriter::
78 cpPlugins::Interface::Image* image =
79 this->GetInput< cpPlugins::Interface::Image >( "Input" );
81 return( "ImageWriter: No input image." );
83 itk::DataObject* itk_image = NULL;
85 cpPlugins_Image_Demangle_AllTypes( D, image, itk_image, r, _RealGD );
86 else r = "ImageWriter: Input image type not supported.";
91 // -------------------------------------------------------------------------
92 template< unsigned int D >
93 std::string cpPlugins::IO::ImageWriter::
96 cpPlugins::Interface::Image* image =
97 this->GetInput< 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->GetString( "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( ) ) );