]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Plugins/IO/ImageWriter.cxx
...
[cpPlugins.git] / lib / cpPlugins / Plugins / IO / ImageWriter.cxx
index 6a0de2ed09dc730cdeab376e3c7ce3c9684e7b43..76ffd845a4c53d23151406bd44740a3b87dc1c80 100644 (file)
@@ -3,18 +3,53 @@
 
 #include <itkImageFileWriter.h>
 
+/* TODO
+   #ifdef cpPlugins_Interface_QT4
+   #include <QFileDialog>
+   #endif // cpPlugins_Interface_QT4
+
+   // -------------------------------------------------------------------------
+   cpPlugins::IO::ImageWriter::
+   DialogResult cpPlugins::IO::ImageWriter::
+   ExecConfigurationDialog( QWidget* parent )
+   {
+   DialogResult r = Self::DialogResult_Cancel;
+
+   #ifdef cpPlugins_Interface_QT4
+
+   std::string name = this->m_Parameters->GetString( "FileName" );
+   if( name == "" )
+   name = "save.mhd";
+
+   // Show dialog and check if it was accepted
+   QString qname =
+   QFileDialog::getSaveFileName(
+   parent,
+   QFileDialog::tr( "Save File" ),
+   QFileDialog::tr( name.c_str( ) ),
+   QFileDialog::tr( "Image files (*.bmp *.png *.jpg *.jpeg *.dcm *.mhd *.nhdr *.nrrd *.tiff);;Any file (*)")
+   );
+   name = qname.toStdString( );
+   if( name != "" )
+   {
+   this->m_Parameters->SetString( "FileName", name );
+   r = Self::DialogResult_NoModal;
+
+   } // fi
+
+   #endif // cpPlugins_Interface_QT4
+
+   return( r );
+   }
+*/
+
 // -------------------------------------------------------------------------
 cpPlugins::IO::ImageWriter::
 ImageWriter( )
   : Superclass( )
 {
-  this->m_ClassName = "cpPlugins::IO::ImageWriter";
-  this->m_ClassCategory = "ImageWriter";
-  this->SetNumberOfInputs( 1 );
-
-  using namespace cpPlugins::Interface;
-  this->m_DefaultParameters.Configure( Parameters::String, "FileName" );
-  this->m_Parameters = this->m_DefaultParameters;
+  this->_AddInput( "Input" );
+  this->m_Parameters->ConfigureAsFileName( "FileName" );
 }
 
 // -------------------------------------------------------------------------
@@ -26,31 +61,48 @@ cpPlugins::IO::ImageWriter::
 // -------------------------------------------------------------------------
 std::string cpPlugins::IO::ImageWriter::
 _GenerateData( )
+{
+  // Thank you very much Microsoft !!! :-@
+  std::string   r = this->_GD0_Image< 2 >( );
+  if( r != "" ) r = this->_GD0_Image< 3 >( );
+  if( r != "" ) r = this->_GD0_Image< 4 >( );
+  if( r != "" ) r = this->_GD0_VectorImage< 2 >( );
+  if( r != "" ) r = this->_GD0_VectorImage< 3 >( );
+  if( r != "" ) r = this->_GD0_VectorImage< 4 >( );
+  return( r );
+}
+
+// -------------------------------------------------------------------------
+template< unsigned int D >
+std::string cpPlugins::IO::ImageWriter::
+_GD0_Image( )
+{
+  cpPlugins::Interface::Image* image =
+    this->GetInput< cpPlugins::Interface::Image >( "Input" );
+  if( image == NULL )
+    return( "ImageWriter: No input image." );
+
+  itk::DataObject* itk_image = NULL;
+  std::string r = "";
+  cpPlugins_Image_Demangle_AllTypes( D, image, itk_image, r, _RealGD );
+  else r = "ImageWriter: Input image type not supported.";
+
+  return( r );
+}
+
+// -------------------------------------------------------------------------
+template< unsigned int D >
+std::string cpPlugins::IO::ImageWriter::
+_GD0_VectorImage( )
 {
   cpPlugins::Interface::Image* image =
-    this->GetInput< cpPlugins::Interface::Image >( 0 );
+    this->GetInput< cpPlugins::Interface::Image >( "Input" );
   if( image == NULL )
     return( "ImageWriter: No input image." );
 
   itk::DataObject* itk_image = NULL;
   std::string r = "";
-  cpPlugins_Image_Input_Demangle_Dimension_AllTypes(
-    2, image, itk_image, r, _RealGD
-    );
-  else cpPlugins_Image_Input_Demangle_Dimension_AllTypes(
-    3, image, itk_image, r, _RealGD
-    );
-  else cpPlugins_Image_Input_Demangle_Dimension_AllTypes(
-    4, image, itk_image, r, _RealGD
-    );
-#ifndef _WIN32 // win32: Nested loops error ????
-  else cpPlugins_Image_Input_Demangle(
-    itk::DiffusionTensor3D< float >, 3, image, itk_image, r, _RealGD
-    );
-  else cpPlugins_Image_Input_Demangle(
-    itk::DiffusionTensor3D< double >, 3, image, itk_image, r, _RealGD
-    );
-#endif // _WIN32
+  cpPlugins_VectorImage_Demangle_AllTypes( D, image, itk_image, r, _RealGD );
   else r = "ImageWriter: Input image type not supported.";
 
   return( r );
@@ -61,17 +113,11 @@ template< class I >
 std::string cpPlugins::IO::ImageWriter::
 _RealGD( itk::DataObject* image )
 {
-  typedef itk::ImageFileWriter< I > _W;
-  
   // Get filename
-  std::string fname = this->m_Parameters.GetValueAsString( "FileName" );
-  _W* writer = dynamic_cast< _W* >( this->m_RealProcessObject.GetPointer( ) );
-  if( writer == NULL )
-  {
-    this->m_RealProcessObject = _W::New( );
-    writer = dynamic_cast< _W* >( this->m_RealProcessObject.GetPointer( ) );
+  std::string fname = this->m_Parameters->GetFileName( "FileName" );
 
-  } // fi
+  typedef itk::ImageFileWriter< I > _W;
+  _W* writer = this->_CreateITK< _W >( );
   writer->SetFileName( fname );
   writer->SetInput( dynamic_cast< I* >( image ) );
   try