]> Creatis software - cpPlugins.git/blobdiff - plugins/cpPluginsIO/ImageWriter.cxx
...
[cpPlugins.git] / plugins / cpPluginsIO / ImageWriter.cxx
index dfbd097a06f77f453e61979f99b2fbdfc64a3943..1855f2e989a01bedd260b9f68dbe2a1d4507744d 100644 (file)
@@ -23,54 +23,44 @@ cpPluginsIO::ImageWriter::
 }
 
 // -------------------------------------------------------------------------
-std::string cpPluginsIO::ImageWriter::
+void cpPluginsIO::ImageWriter::
 _GenerateData( )
 {
-  auto input = this->GetInputData( "Input" );
-  try
-  {
-    std::string   r = cpPlugin_Image_Demangle_Dim( _GD0, input, 3 );
-    if( r != "" ) r = cpPlugin_Image_Demangle_Dim( _GD0, input, 2 );
-    /* TODO
-       if( r != "" ) r = cpPlugin_Image_Demangle_Dim( _GD0, input, 4 );
-       if( r != "" ) r = cpPlugin_Image_Demangle_Dim( _GD0, input, 1 );
-    */
-    return( r );
-  }
-  catch( itk::ExceptionObject& err )
-  {
-    return( "IO::ImageWriter: " + std::string( err.GetDescription( ) ) );
-  }
+  auto image = this->GetInputData( "Input" )->GetITK< itk::DataObject >( );
+  cpPlugins_Image_Demangle_Dim     ( _GD0, image, 2 );
+  else cpPlugins_Image_Demangle_Dim( _GD0, image, 3 );
+  else this->_Error( "No valid input image dimension" );
 }
 
 // -------------------------------------------------------------------------
-template< class _TInput >
-std::string cpPluginsIO::ImageWriter::
-_GD0( _TInput* image )
+template< class _TImage >
+void cpPluginsIO::ImageWriter::
+_GD0( _TImage* image )
 {
-  static const unsigned int D = _TInput::ImageDimension;
-  if( image == NULL )
-    return( "IO::ImageWriter: Invalid image dimension." );
-
-  std::string   cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD1, image, D );
-  if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllColor( r, _GD1, image, D );
-  return( r );
+  static const unsigned int D = _TImage::ImageDimension;
+  cpPlugins_Image_Demangle_Pixel_AllScalars          ( _GD1, image, D );
+  else cpPlugins_Image_Demangle_ColorPixel_AllScalars( _GD1, image, RGB, D );
+  else cpPlugins_Image_Demangle_ColorPixel_AllScalars( _GD1, image, RGBA, D );
 }
 
 // -------------------------------------------------------------------------
-template< class _TInput >
-std::string cpPluginsIO::ImageWriter::
-_GD1( _TInput* image )
+template< class _TImage >
+void cpPluginsIO::ImageWriter::
+_GD1( _TImage* image )
 {
-  typedef itk::ImageFileWriter< _TInput > _TFilter;
-
-  if( image == NULL )
-    return( "IO::ImageWriter: Invalid pixel type." );
+  typedef itk::ImageFileWriter< _TImage > _TFilter;
   auto f = this->_CreateITK< _TFilter >( );
   f->SetFileName( this->m_Parameters.GetSaveFileName( "FileName" ) );
   f->SetInput( image );
-  f->Update( );
-  return( "" );
+  try
+  {
+    f->Update( );
+  }
+  catch( itk::ExceptionObject& err )
+  {
+    this->_Error( err.GetDescription( ) );
+
+  } // yrt
 }
 
 // eof - $RCSfile$