]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/IO/ImageWriter.cxx
...
[cpPlugins.git] / lib / cpPlugins / Plugins / IO / ImageWriter.cxx
1 #include "ImageWriter.h"
2 #include <cpPlugins/Interface/Image.h>
3
4 #include <itkImageFileWriter.h>
5
6 /* TODO
7    #ifdef cpPlugins_Interface_QT4
8    #include <QFileDialog>
9    #endif // cpPlugins_Interface_QT4
10
11    // -------------------------------------------------------------------------
12    cpPlugins::IO::ImageWriter::
13    DialogResult cpPlugins::IO::ImageWriter::
14    ExecConfigurationDialog( QWidget* parent )
15    {
16    DialogResult r = Self::DialogResult_Cancel;
17
18    #ifdef cpPlugins_Interface_QT4
19
20    std::string name = this->m_Parameters->GetString( "FileName" );
21    if( name == "" )
22    name = "save.mhd";
23
24    // Show dialog and check if it was accepted
25    QString qname =
26    QFileDialog::getSaveFileName(
27    parent,
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 (*)")
31    );
32    name = qname.toStdString( );
33    if( name != "" )
34    {
35    this->m_Parameters->SetString( "FileName", name );
36    r = Self::DialogResult_NoModal;
37
38    } // fi
39
40    #endif // cpPlugins_Interface_QT4
41
42    return( r );
43    }
44 */
45
46 // -------------------------------------------------------------------------
47 cpPlugins::IO::ImageWriter::
48 ImageWriter( )
49   : Superclass( )
50 {
51   this->_AddInput( "Input" );
52   this->m_Parameters->ConfigureAsFileName( "FileName" );
53 }
54
55 // -------------------------------------------------------------------------
56 cpPlugins::IO::ImageWriter::
57 ~ImageWriter( )
58 {
59 }
60
61 // -------------------------------------------------------------------------
62 std::string cpPlugins::IO::ImageWriter::
63 _GenerateData( )
64 {
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 >( );
72   return( r );
73 }
74
75 // -------------------------------------------------------------------------
76 template< unsigned int D >
77 std::string cpPlugins::IO::ImageWriter::
78 _GD0_Image( )
79 {
80   cpPlugins::Interface::Image* image =
81     this->GetInput< cpPlugins::Interface::Image >( "Input" );
82   if( image == NULL )
83     return( "ImageWriter: No input image." );
84
85   itk::DataObject* itk_image = NULL;
86   std::string r = "";
87   cpPlugins_Image_Demangle_AllTypes( D, image, itk_image, r, _RealGD );
88   else r = "ImageWriter: Input image type not supported.";
89
90   return( r );
91 }
92
93 // -------------------------------------------------------------------------
94 template< unsigned int D >
95 std::string cpPlugins::IO::ImageWriter::
96 _GD0_VectorImage( )
97 {
98   cpPlugins::Interface::Image* image =
99     this->GetInput< cpPlugins::Interface::Image >( "Input" );
100   if( image == NULL )
101     return( "ImageWriter: No input image." );
102
103   itk::DataObject* itk_image = NULL;
104   std::string r = "";
105   cpPlugins_VectorImage_Demangle_AllTypes( D, image, itk_image, r, _RealGD );
106   else r = "ImageWriter: Input image type not supported.";
107
108   return( r );
109 }
110
111 // -------------------------------------------------------------------------
112 template< class I >
113 std::string cpPlugins::IO::ImageWriter::
114 _RealGD( itk::DataObject* image )
115 {
116   // Get filename
117   std::string fname = this->m_Parameters->GetFileName( "FileName" );
118
119   typedef itk::ImageFileWriter< I > _W;
120   _W* writer = this->_CreateITK< _W >( );
121   writer->SetFileName( fname );
122   writer->SetInput( dynamic_cast< I* >( image ) );
123   try
124   {
125     writer->Update( );
126   }
127   catch( itk::ExceptionObject& err )
128   {
129     return( "ImageWriter: " + std::string( err.GetDescription( ) ) );
130
131   } // yrt
132   return( "" );
133 }
134
135 // eof - $RCSfile$