]> Creatis software - cpPlugins.git/blobdiff - plugins/IO/ImageReader.cxx
...
[cpPlugins.git] / plugins / IO / ImageReader.cxx
index 5897bdb01abb560ee700b7fb663e4881c8449945..f4639a15678c0466e0b564fa19c8a894b77ed9fa 100644 (file)
@@ -1,7 +1,9 @@
-#include <plugins/IO/ImageReader.h>
-#include <plugins/IO/ImageReaderQDialog.h>
-#include <cpPlugins/Image.h>
-#include <cpPlugins_Instances_ImageReaders.h>
+#include <IO/ImageReader.h>
+#include <IO/ImageReaderQDialog.h>
+#include <cpPlugins/DataObjects/Image.h>
+
+#include <itkImageFileReader.h>
+#include <itkImageSeriesReader.h>
 #include <itkImageIOFactory.h>
 
 #ifdef cpPlugins_QT4
@@ -29,7 +31,7 @@ cpPluginsIO::ImageReaderQDialog::
 
 // -------------------------------------------------------------------------
 void cpPluginsIO::ImageReaderQDialog::
-setProcessObject( cpPlugins::ProcessObject* obj )
+setProcessObject( cpPlugins::BaseObjects::ProcessObject* obj )
 {
   if( obj == NULL )
     return;
@@ -93,7 +95,7 @@ cpPluginsIO::ImageReader::
 ImageReader( )
   : Superclass( )
 {
-  this->_AddOutput< cpPlugins::Image >( "Output" );
+  this->_ConfigureOutput< cpPlugins::DataObjects::Image >( "Output" );
   this->m_Parameters.Clear( );
   this->m_Parameters.ConfigureAsOpenFileNameList( "FileNames" );
   this->m_Parameters.SetAcceptedFileExtensions(
@@ -128,16 +130,22 @@ _GenerateData( )
       io->ReadImageInformation( );
       if( fnames.size( ) >= 1 )
       {
-        switch( io->GetNumberOfDimensions( ) )
-        {
-        case 1: this->_GD0< 1 >( io ); break;
-        case 2: this->_GD0< 2 >( io ); break;
-        case 3: this->_GD0< 3 >( io ); break;
-        case 4: this->_GD0< 4 >( io ); break;
-        default:
+        bool success = false;
+        unsigned int dim = io->GetNumberOfDimensions( );
+#ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_1
+        if( dim == 1 ) success = this->_GD0< 1 >( io );
+#endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_1
+#ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_2
+        if( dim == 2 ) success = this->_GD0< 2 >( io );
+#endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_2
+#ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_3
+        if( dim == 3 ) success = this->_GD0< 3 >( io );
+#endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_3
+#ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_4
+        if( dim == 4 ) success = this->_GD0< 4 >( io );
+#endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_4
+        if( !success )
           this->_Error( "Image dimension not supported." );
-          break;
-        } // hctiws
 
       } // fi
     }
@@ -154,7 +162,7 @@ _GenerateData( )
 
 // -------------------------------------------------------------------------
 template< unsigned int _Dim >
-void cpPluginsIO::ImageReader::
+bool cpPluginsIO::ImageReader::
 _GD0( itk::ImageIOBase* io )
 {
   typedef unsigned char  uchar;
@@ -165,134 +173,125 @@ _GD0( itk::ImageIOBase* io )
   itk::ImageIOBase::IOComponentType ct = io->GetComponentType( );
   itk::ImageIOBase::IOPixelType pt = io->GetPixelType( );
 
+  bool success = false;
   if( pt == itk::ImageIOBase::SCALAR )
   {
-    switch( ct )
-    {
-    case itk::ImageIOBase::CHAR   : this->_GD1<   char, _Dim >( io ); break;
-    case itk::ImageIOBase::SHORT  : this->_GD1<  short, _Dim >( io ); break;
-    case itk::ImageIOBase::INT    : this->_GD1<    int, _Dim >( io ); break;
-    case itk::ImageIOBase::LONG   : this->_GD1<   long, _Dim >( io ); break;
-    case itk::ImageIOBase::FLOAT  : this->_GD1<  float, _Dim >( io ); break;
-    case itk::ImageIOBase::DOUBLE : this->_GD1< double, _Dim >( io ); break;
-    case itk::ImageIOBase::UCHAR  : this->_GD1<  uchar, _Dim >( io ); break;
-    case itk::ImageIOBase::USHORT : this->_GD1< ushort, _Dim >( io ); break;
-    case itk::ImageIOBase::UINT   : this->_GD1<   uint, _Dim >( io ); break;
-    case itk::ImageIOBase::ULONG  : this->_GD1<  ulong, _Dim >( io ); break;
-    default: this->_Error( "Scalar pixel type not supported." ); break;
-    } // hctiws
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_char
+    if( ct == itk::ImageIOBase::CHAR ) success = this->_GD1< char, _Dim >( io );
+    if( ct == itk::ImageIOBase::UCHAR ) success = this->_GD1< uchar, _Dim >( io );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_char
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_short
+    if( ct == itk::ImageIOBase::SHORT ) success = this->_GD1< short, _Dim >( io );
+    if( ct == itk::ImageIOBase::USHORT ) success = this->_GD1< ushort, _Dim >( io );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_short
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_int
+    if( ct == itk::ImageIOBase::INT ) success = this->_GD1< int, _Dim >( io );
+    if( ct == itk::ImageIOBase::UINT ) success = this->_GD1< uint, _Dim >( io );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_int
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_long
+    if( ct == itk::ImageIOBase::LONG ) success = this->_GD1< long, _Dim >( io );
+    if( ct == itk::ImageIOBase::ULONG ) success = this->_GD1< ulong, _Dim >( io );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_long
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_float
+    if( ct == itk::ImageIOBase::FLOAT ) success = this->_GD1< float, _Dim >( io );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_float
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_double
+    if( ct == itk::ImageIOBase::DOUBLE ) success = this->_GD1< double, _Dim >( io );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_double
   }
   else if( pt == itk::ImageIOBase::RGB )
   {
-    switch( ct )
-    {
-    case itk::ImageIOBase::CHAR   : this->_GD1< itk::RGBPixel<   char >, _Dim >( io ); break;
-    case itk::ImageIOBase::SHORT  : this->_GD1< itk::RGBPixel<  short >, _Dim >( io ); break;
-    case itk::ImageIOBase::INT    : this->_GD1< itk::RGBPixel<    int >, _Dim >( io ); break;
-    case itk::ImageIOBase::LONG   : this->_GD1< itk::RGBPixel<   long >, _Dim >( io ); break;
-    case itk::ImageIOBase::FLOAT  : this->_GD1< itk::RGBPixel<  float >, _Dim >( io ); break;
-    case itk::ImageIOBase::DOUBLE : this->_GD1< itk::RGBPixel< double >, _Dim >( io ); break;
-    case itk::ImageIOBase::UCHAR  : this->_GD1< itk::RGBPixel<  uchar >, _Dim >( io ); break;
-    case itk::ImageIOBase::USHORT : this->_GD1< itk::RGBPixel< ushort >, _Dim >( io ); break;
-    case itk::ImageIOBase::UINT   : this->_GD1< itk::RGBPixel<   uint >, _Dim >( io ); break;
-    case itk::ImageIOBase::ULONG  : this->_GD1< itk::RGBPixel<  ulong >, _Dim >( io ); break;
-    default: this->_Error( "RGB pixel type not supported." ); break;
-    } // hctiws
+#ifdef cpPlugins_CONFIG_COLOR_PIXELS_RGBPixel
+#  ifdef cpPlugins_CONFIG_INTEGER_TYPES_char
+    if( ct == itk::ImageIOBase::CHAR ) success = this->_GD1< itk::RGBPixel< char >, _Dim >( io );
+    if( ct == itk::ImageIOBase::UCHAR ) success = this->_GD1< itk::RGBPixel< uchar >, _Dim >( io );
+#  endif // cpPlugins_CONFIG_INTEGER_TYPES_char
+#  ifdef cpPlugins_CONFIG_INTEGER_TYPES_short
+    if( ct == itk::ImageIOBase::SHORT ) success = this->_GD1< itk::RGBPixel< short >, _Dim >( io );
+    if( ct == itk::ImageIOBase::USHORT ) success = this->_GD1< itk::RGBPixel< ushort >, _Dim >( io );
+#  endif // cpPlugins_CONFIG_INTEGER_TYPES_short
+#  ifdef cpPlugins_CONFIG_INTEGER_TYPES_int
+    if( ct == itk::ImageIOBase::INT ) success = this->_GD1< itk::RGBPixel< int >, _Dim >( io );
+    if( ct == itk::ImageIOBase::UINT ) success = this->_GD1< itk::RGBPixel< uint >, _Dim >( io );
+#  endif // cpPlugins_CONFIG_INTEGER_TYPES_int
+#  ifdef cpPlugins_CONFIG_INTEGER_TYPES_long
+    if( ct == itk::ImageIOBase::LONG ) success = this->_GD1< itk::RGBPixel< long >, _Dim >( io );
+    if( ct == itk::ImageIOBase::ULONG ) success = this->_GD1< itk::RGBPixel< ulong >, _Dim >( io );
+#  endif // cpPlugins_CONFIG_INTEGER_TYPES_long
+#  ifdef cpPlugins_CONFIG_INTEGER_TYPES_float
+    if( ct == itk::ImageIOBase::FLOAT ) success = this->_GD1< itk::RGBPixel< float >, _Dim >( io );
+#  endif // cpPlugins_CONFIG_INTEGER_TYPES_float
+#  ifdef cpPlugins_CONFIG_INTEGER_TYPES_double
+    if( ct == itk::ImageIOBase::DOUBLE ) success = this->_GD1< itk::RGBPixel< double >, _Dim >( io );
+#  endif // cpPlugins_CONFIG_INTEGER_TYPES_double
+#endif // cpPlugins_CONFIG_COLOR_PIXELS_RGBPixel
   }
   else if( pt == itk::ImageIOBase::RGBA )
   {
-    switch( ct )
-    {
-    case itk::ImageIOBase::CHAR   : this->_GD1< itk::RGBAPixel<   char >, _Dim >( io ); break;
-    case itk::ImageIOBase::SHORT  : this->_GD1< itk::RGBAPixel<  short >, _Dim >( io ); break;
-    case itk::ImageIOBase::INT    : this->_GD1< itk::RGBAPixel<    int >, _Dim >( io ); break;
-    case itk::ImageIOBase::LONG   : this->_GD1< itk::RGBAPixel<   long >, _Dim >( io ); break;
-    case itk::ImageIOBase::FLOAT  : this->_GD1< itk::RGBAPixel<  float >, _Dim >( io ); break;
-    case itk::ImageIOBase::DOUBLE : this->_GD1< itk::RGBAPixel< double >, _Dim >( io ); break;
-    case itk::ImageIOBase::UCHAR  : this->_GD1< itk::RGBAPixel<  uchar >, _Dim >( io ); break;
-    case itk::ImageIOBase::USHORT : this->_GD1< itk::RGBAPixel< ushort >, _Dim >( io ); break;
-    case itk::ImageIOBase::UINT   : this->_GD1< itk::RGBAPixel<   uint >, _Dim >( io ); break;
-    case itk::ImageIOBase::ULONG  : this->_GD1< itk::RGBAPixel<  ulong >, _Dim >( io ); break;
-    default: this->_Error( "RGBA pixel type not supported." ); break;
-    } // hctiws
+#ifdef cpPlugins_CONFIG_COLOR_PIXELS_RGBAPixel
+#  ifdef cpPlugins_CONFIG_INTEGER_TYPES_char
+    if( ct == itk::ImageIOBase::CHAR ) success = this->_GD1< itk::RGBAPixel< char >, _Dim >( io );
+    if( ct == itk::ImageIOBase::UCHAR ) success = this->_GD1< itk::RGBAPixel< uchar >, _Dim >( io );
+#  endif // cpPlugins_CONFIG_INTEGER_TYPES_char
+#  ifdef cpPlugins_CONFIG_INTEGER_TYPES_short
+    if( ct == itk::ImageIOBase::SHORT ) success = this->_GD1< itk::RGBAPixel< short >, _Dim >( io );
+    if( ct == itk::ImageIOBase::USHORT ) success = this->_GD1< itk::RGBAPixel< ushort >, _Dim >( io );
+#  endif // cpPlugins_CONFIG_INTEGER_TYPES_short
+#  ifdef cpPlugins_CONFIG_INTEGER_TYPES_int
+    if( ct == itk::ImageIOBase::INT ) success = this->_GD1< itk::RGBAPixel< int >, _Dim >( io );
+    if( ct == itk::ImageIOBase::UINT ) success = this->_GD1< itk::RGBAPixel< uint >, _Dim >( io );
+#  endif // cpPlugins_CONFIG_INTEGER_TYPES_int
+#  ifdef cpPlugins_CONFIG_INTEGER_TYPES_long
+    if( ct == itk::ImageIOBase::LONG ) success = this->_GD1< itk::RGBAPixel< long >, _Dim >( io );
+    if( ct == itk::ImageIOBase::ULONG ) success = this->_GD1< itk::RGBAPixel< ulong >, _Dim >( io );
+#  endif // cpPlugins_CONFIG_INTEGER_TYPES_long
+#  ifdef cpPlugins_CONFIG_INTEGER_TYPES_float
+    if( ct == itk::ImageIOBase::FLOAT ) success = this->_GD1< itk::RGBAPixel< float >, _Dim >( io );
+#  endif // cpPlugins_CONFIG_INTEGER_TYPES_float
+#  ifdef cpPlugins_CONFIG_INTEGER_TYPES_double
+    if( ct == itk::ImageIOBase::DOUBLE ) success = this->_GD1< itk::RGBAPixel< double >, _Dim >( io );
+#  endif // cpPlugins_CONFIG_INTEGER_TYPES_double
+#endif // cpPlugins_CONFIG_COLOR_PIXELS_RGBAPixel
   }
   else if( pt == itk::ImageIOBase::COMPLEX )
   {
-    switch( ct )
-    {
-    case itk::ImageIOBase::FLOAT  : this->_GD1< std::complex< float >, _Dim >( io ); break;
-    case itk::ImageIOBase::DOUBLE : this->_GD1< std::complex< double >, _Dim >( io ); break;
-    default: this->_Error( "Complex pixel type not supported." ); break;
-    } // hctiws
   }
   else if( pt == itk::ImageIOBase::COVARIANTVECTOR )
   {
-    switch( ct )
-    {
-    case itk::ImageIOBase::FLOAT  : this->_GD1< itk::CovariantVector< float, _Dim >, _Dim >( io ); break;
-    case itk::ImageIOBase::DOUBLE : this->_GD1< itk::CovariantVector< double, _Dim >, _Dim >( io ); break;
-    default: this->_Error( "CovariantVector pixel type not supported." ); break;
-    } // hctiws
   }
   else if( pt == itk::ImageIOBase::POINT )
   {
-    switch( ct )
-    {
-    case itk::ImageIOBase::FLOAT  : this->_GD1< itk::Point< float, _Dim >, _Dim >( io ); break;
-    case itk::ImageIOBase::DOUBLE : this->_GD1< itk::Point< double, _Dim >, _Dim >( io ); break;
-    default: this->_Error( "Point pixel type not supported." ); break;
-    } // hctiws
   }
   else if( pt == itk::ImageIOBase::VECTOR )
   {
-    switch( ct )
-    {
-    case itk::ImageIOBase::FLOAT  : this->_GD1< itk::Vector< float, _Dim >, _Dim >( io ); break;
-    case itk::ImageIOBase::DOUBLE : this->_GD1< itk::Vector< double, _Dim >, _Dim >( io ); break;
-    default: this->_Error( "Vector pixel type not supported." ); break;
-    } // hctiws
   }
   else if( pt == itk::ImageIOBase::SYMMETRICSECONDRANKTENSOR )
   {
-    switch( ct )
-    {
-    case itk::ImageIOBase::FLOAT  : this->_GD1< itk::SymmetricSecondRankTensor< float, _Dim >, _Dim >( io ); break;
-    case itk::ImageIOBase::DOUBLE : this->_GD1< itk::SymmetricSecondRankTensor< double, _Dim >, _Dim >( io ); break;
-    default: this->_Error( "SymmetricSecondRankTensor pixel type not supported." ); break;
-    } // hctiws
   }
   else if( pt == itk::ImageIOBase::DIFFUSIONTENSOR3D )
   {
     if( _Dim == 3 )
     {
-      switch( ct )
-      {
-      case itk::ImageIOBase::FLOAT  : this->_GD1< itk::DiffusionTensor3D< float >, 3 >( io ); break;
-      case itk::ImageIOBase::DOUBLE : this->_GD1< itk::DiffusionTensor3D< double >, 3 >( io ); break;
-      default: this->_Error( "DiffusionTensor3D pixel type not supported." ); break;
-      } // hctiws
     }
     else
       this->_Error( "DiffusionTensor3D dimension not supported." );
   }
-  /* TODO
-     else if( pt == itk::ImageIOBase::OFFSET )
-     {
-     }
-     else if( pt == itk::ImageIOBase::FIXEDARRAY )
-     {
-     }
-     else if( pt == itk::ImageIOBase::MATRIX )
-     {
-     }
-  */
-  else
-    this->_Error( "Image pixel type not yet supported." );
+  else if( pt == itk::ImageIOBase::MATRIX )
+  {
+  }
+  else if( pt == itk::ImageIOBase::OFFSET )
+  {
+    this->_GD1< itk::Offset< _Dim >, _Dim >( io );
+  }
+  else if( pt == itk::ImageIOBase::FIXEDARRAY )
+  {
+  }
+  return( success );
 }
 
 // -------------------------------------------------------------------------
 template< class _TPixel, unsigned int _Dim >
-void cpPluginsIO::ImageReader::
+bool cpPluginsIO::ImageReader::
 _GD1( itk::ImageIOBase* io )
 {
   typedef itk::Image< _TPixel, _Dim > _TImage;
@@ -308,11 +307,14 @@ _GD1( itk::ImageIOBase* io )
     {
       f->Update( );
       this->GetOutput( "Output" )->SetITK( f->GetOutput( ) );
+      return( true );
     }
     catch( itk::ExceptionObject& err )
     {
       this->_Error( err.GetDescription( ) );
-    }
+      return( false );
+
+    } // yrt
   }
   else // if( fnames.size( ) > 1 )
   {
@@ -324,11 +326,14 @@ _GD1( itk::ImageIOBase* io )
     {
       f->Update( );
       this->GetOutput( "Output" )->SetITK( f->GetOutput( ) );
+      return( true );
     }
     catch( itk::ExceptionObject& err )
     {
       this->_Error( err.GetDescription( ) );
-    }
+      return( false );
+
+    } // yrt
 
   } // fi
 }