]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Plugins/ImageReader.cxx
Basic IO architecture within itk-based pipelines
[cpPlugins.git] / lib / cpPlugins / Plugins / ImageReader.cxx
index 5bc182ed530bb2f0e4fbf2c71e586d2ed0cb06e6..feca19b52bb063cb79c3f5a23164b41d40e39385 100644 (file)
@@ -10,6 +10,8 @@ cpPlugins::Plugins::ImageReader::
 ImageReader( )
   : Superclass( )
 {
+  this->SetNumberOfOutputs( 1 );
+
   this->m_DefaultParameters[ "FileName" ] =
     TParameter( "string", "no_file_name" );
   this->m_DefaultParameters[ "PixelType" ] = TParameter( "type", "uchar" );
@@ -31,8 +33,8 @@ GetClassName( ) const
 }
 
 // -------------------------------------------------------------------------
-bool cpPlugins::Plugins::ImageReader::
-Update( )
+std::string cpPlugins::Plugins::ImageReader::
+_GenerateData( )
 {
   TParameters::const_iterator dIt;
 
@@ -41,19 +43,19 @@ Update( )
   if( dIt == this->m_Parameters.end( ) )
     dIt = this->m_DefaultParameters.find( "ImageDimension" );
 
-  bool ret = false;
-  if     ( dIt->second.second == "1" ) ret = this->_Update0< 1 >( );
-  else if( dIt->second.second == "2" ) ret = this->_Update0< 2 >( );
-  else if( dIt->second.second == "3" ) ret = this->_Update0< 3 >( );
-  else if( dIt->second.second == "4" ) ret = this->_Update0< 4 >( );
+  std::string ret = "itk::Image dimension not supported.";
+  if     ( dIt->second.second == "1" ) ret = this->_GenerateData0< 1 >( );
+  else if( dIt->second.second == "2" ) ret = this->_GenerateData0< 2 >( );
+  else if( dIt->second.second == "3" ) ret = this->_GenerateData0< 3 >( );
+  else if( dIt->second.second == "4" ) ret = this->_GenerateData0< 4 >( );
 
   return( ret );
 }
 
 // -------------------------------------------------------------------------
 template< unsigned int D >
-bool cpPlugins::Plugins::ImageReader::
-_Update0( )
+std::string cpPlugins::Plugins::ImageReader::
+_GenerateData0( )
 {
   TParameters::const_iterator tIt, cIt;
 
@@ -65,60 +67,60 @@ _Update0( )
   if( cIt == this->m_Parameters.end( ) )
     cIt = this->m_DefaultParameters.find( "IsColorImage" );
 
-  bool ret = false;
+  std::string ret = "itk::Image pixel type not supported";
   if( cIt->second.second == "0" )
   {
     if( tIt->second.second == "char" )
-      ret = this->_Update1< char, D >( );
+      ret = this->_GenerateData1< char, D >( );
     else if( tIt->second.second == "short" )
-      ret = this->_Update1< short, D >( );
+      ret = this->_GenerateData1< short, D >( );
     else if( tIt->second.second == "int" )
-      ret = this->_Update1< int, D >( );
+      ret = this->_GenerateData1< int, D >( );
     else if( tIt->second.second == "long" )
-      ret = this->_Update1< long, D >( );
+      ret = this->_GenerateData1< long, D >( );
     else if( tIt->second.second == "uchar" )
-      ret = this->_Update1< unsigned char, D >( );
+      ret = this->_GenerateData1< unsigned char, D >( );
     else if( tIt->second.second == "ushort" )
-      ret = this->_Update1< unsigned short, D >( );
+      ret = this->_GenerateData1< unsigned short, D >( );
     else if( tIt->second.second == "uint" )
-      ret = this->_Update1< unsigned int, D >( );
+      ret = this->_GenerateData1< unsigned int, D >( );
     else if( tIt->second.second == "ulong" )
-      ret = this->_Update1< unsigned long, D >( );
+      ret = this->_GenerateData1< unsigned long, D >( );
     else if( tIt->second.second == "float" )
-      ret = this->_Update1< float, D >( );
+      ret = this->_GenerateData1< float, D >( );
     else if( tIt->second.second == "double" )
-      ret = this->_Update1< double, D >( );
+      ret = this->_GenerateData1< double, D >( );
   }
   else if( cIt->second.second == "1" )
   {
     if( tIt->second.second == "char" )
-      ret = this->_Update1< itk::RGBPixel< char >, D >( );
+      ret = this->_GenerateData1< itk::RGBPixel< char >, D >( );
     else if( tIt->second.second == "short" )
-      ret = this->_Update1< itk::RGBPixel< short >, D >( );
+      ret = this->_GenerateData1< itk::RGBPixel< short >, D >( );
     else if( tIt->second.second == "int" )
-      ret = this->_Update1< itk::RGBPixel< int >, D >( );
+      ret = this->_GenerateData1< itk::RGBPixel< int >, D >( );
     else if( tIt->second.second == "long" )
-      ret = this->_Update1< itk::RGBPixel< long >, D >( );
+      ret = this->_GenerateData1< itk::RGBPixel< long >, D >( );
     else if( tIt->second.second == "uchar" )
-      ret = this->_Update1< itk::RGBPixel< unsigned char >, D >( );
+      ret = this->_GenerateData1< itk::RGBPixel< unsigned char >, D >( );
     else if( tIt->second.second == "ushort" )
-      ret = this->_Update1< itk::RGBPixel< unsigned short >, D >( );
+      ret = this->_GenerateData1< itk::RGBPixel< unsigned short >, D >( );
     else if( tIt->second.second == "uint" )
-      ret = this->_Update1< itk::RGBPixel< unsigned int >, D >( );
+      ret = this->_GenerateData1< itk::RGBPixel< unsigned int >, D >( );
     else if( tIt->second.second == "ulong" )
-      ret = this->_Update1< itk::RGBPixel< unsigned long >, D >( );
+      ret = this->_GenerateData1< itk::RGBPixel< unsigned long >, D >( );
     else if( tIt->second.second == "float" )
-      ret = this->_Update1< itk::RGBPixel< float >, D >( );
+      ret = this->_GenerateData1< itk::RGBPixel< float >, D >( );
     else if( tIt->second.second == "double" )
-      ret = this->_Update1< itk::RGBPixel< double >, D >( );
+      ret = this->_GenerateData1< itk::RGBPixel< double >, D >( );
   } // fi
   return( ret );
 }
 
 // -------------------------------------------------------------------------
 template< class P, unsigned int D >
-bool cpPlugins::Plugins::ImageReader::
-_Update1( )
+std::string cpPlugins::Plugins::ImageReader::
+_GenerateData1( )
 {
   TParameters::const_iterator fIt;
 
@@ -145,10 +147,11 @@ _Update1( )
   }
   catch( itk::ExceptionObject& err )
   {
-    return( false );
+    return( err.GetDescription( ) );
 
   } // yrt
-  return( true );
+  this->_SetOutput( 0, reader->GetOutput( ) );
+  return( "" );
 }
 
 // eof - $RCSfile$