+#include <cpPlugins/Plugins/ImageSeriesReader.h>
+#include <cpPlugins/Interface/Image.h>
+
+#include <set>
+#include <sstream>
+
+#include <itkImageSeriesReader.h>
+
+#define ITK_MANUAL_INSTANTIATION
+#include <itkImage.h>
+#include <itkRGBPixel.h>
+
+// -------------------------------------------------------------------------
+cpPlugins::Plugins::ImageSeriesReader::
+ImageSeriesReader( )
+ : Superclass( )
+{
+ this->SetNumberOfOutputs( 1 );
+ this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
+
+ this->m_DefaultParameters[ "FileNames" ] =
+ TParameter( "string", "file_name1;file_name2;file_name3;..." );
+ this->m_DefaultParameters[ "PixelType" ] = TParameter( "type", "uchar" );
+ this->m_DefaultParameters[ "ImageDimension" ] = TParameter( "int", "3" );
+ this->m_DefaultParameters[ "IsColorImage" ] = TParameter( "bool", "0" );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Plugins::ImageSeriesReader::
+~ImageSeriesReader( )
+{
+}
+
+// -------------------------------------------------------------------------
+std::string cpPlugins::Plugins::ImageSeriesReader::
+GetClassName( ) const
+{
+ return( "cpPlugins::Plugins::ImageSeriesReader" );
+}
+
+// -------------------------------------------------------------------------
+std::string cpPlugins::Plugins::ImageSeriesReader::
+_GenerateData( )
+{
+ TParameters::const_iterator dIt;
+
+ // Get image dimension
+ dIt = this->m_Parameters.find( "ImageDimension" );
+ if( dIt == this->m_Parameters.end( ) )
+ dIt = this->m_DefaultParameters.find( "ImageDimension" );
+
+ std::string r = "cpPlugins::Plugins::ImageSeriesReader: itk::Image dimension not supported.";
+ if( dIt->second.second == "2" ) r = this->_GD0< 2 >( );
+ else if( dIt->second.second == "3" ) r = this->_GD0< 3 >( );
+ else if( dIt->second.second == "4" ) r = this->_GD0< 4 >( );
+
+ return( r );
+}
+
+// -------------------------------------------------------------------------
+template< unsigned int D >
+std::string cpPlugins::Plugins::ImageSeriesReader::
+_GD0( )
+{
+ TParameters::const_iterator tIt, cIt;
+
+ // Get image pixel type
+ tIt = this->m_Parameters.find( "PixelType" );
+ if( tIt == this->m_Parameters.end( ) )
+ tIt = this->m_DefaultParameters.find( "PixelType" );
+ cIt = this->m_Parameters.find( "IsColorImage" );
+ if( cIt == this->m_Parameters.end( ) )
+ cIt = this->m_DefaultParameters.find( "IsColorImage" );
+
+ std::string r = "cpPlugins::Plugins::ImageSeriesReader: itk::Image pixel type not supported";
+ if( cIt->second.second == "0" )
+ {
+ if( tIt->second.second == "char" )
+ r = this->_GD1< char, D >( );
+ else if( tIt->second.second == "short" )
+ r = this->_GD1< short, D >( );
+ else if( tIt->second.second == "int" )
+ r = this->_GD1< int, D >( );
+ else if( tIt->second.second == "long" )
+ r = this->_GD1< long, D >( );
+ else if( tIt->second.second == "uchar" )
+ r = this->_GD1< unsigned char, D >( );
+ else if( tIt->second.second == "ushort" )
+ r = this->_GD1< unsigned short, D >( );
+ else if( tIt->second.second == "uint" )
+ r = this->_GD1< unsigned int, D >( );
+ else if( tIt->second.second == "ulong" )
+ r = this->_GD1< unsigned long, D >( );
+ else if( tIt->second.second == "float" )
+ r = this->_GD1< float, D >( );
+ else if( tIt->second.second == "double" )
+ r = this->_GD1< double, D >( );
+ }
+ else if( cIt->second.second == "1" )
+ {
+ if( tIt->second.second == "char" )
+ r = this->_GD1< itk::RGBPixel< char >, D >( );
+ else if( tIt->second.second == "short" )
+ r = this->_GD1< itk::RGBPixel< short >, D >( );
+ else if( tIt->second.second == "int" )
+ r = this->_GD1< itk::RGBPixel< int >, D >( );
+ else if( tIt->second.second == "long" )
+ r = this->_GD1< itk::RGBPixel< long >, D >( );
+ else if( tIt->second.second == "uchar" )
+ r = this->_GD1< itk::RGBPixel< unsigned char >, D >( );
+ else if( tIt->second.second == "ushort" )
+ r = this->_GD1< itk::RGBPixel< unsigned short >, D >( );
+ else if( tIt->second.second == "uint" )
+ r = this->_GD1< itk::RGBPixel< unsigned int >, D >( );
+ else if( tIt->second.second == "ulong" )
+ r = this->_GD1< itk::RGBPixel< unsigned long >, D >( );
+ else if( tIt->second.second == "float" )
+ r = this->_GD1< itk::RGBPixel< float >, D >( );
+ else if( tIt->second.second == "double" )
+ r = this->_GD1< itk::RGBPixel< double >, D >( );
+ } // fi
+ return( r );
+}
+
+// -------------------------------------------------------------------------
+template< class P, unsigned int D >
+std::string cpPlugins::Plugins::ImageSeriesReader::
+_GD1( )
+{
+ TParameters::const_iterator fIt;
+
+ // Get filenames
+ std::set< std::string > filenames;
+ fIt = this->m_Parameters.find( "FileNames" );
+ if( fIt == this->m_Parameters.end( ) )
+ fIt = this->m_DefaultParameters.find( "FileName" );
+ std::istringstream filenames_stream( fIt->second.second );
+ std::string filename;
+ while( std::getline( filenames_stream, filename, ';' ) )
+ filenames.insert( filename );
+
+ // Reader
+ typedef itk::Image< P, D > _TImage;
+ typedef itk::ImageSeriesReader< _TImage > _TReader;
+
+ _TReader* reader =
+ dynamic_cast< _TReader* >( this->m_Reader.GetPointer( ) );
+ if( reader == NULL )
+ {
+ this->m_Reader = _TReader::New( );
+ reader = dynamic_cast< _TReader* >( this->m_Reader.GetPointer( ) );
+
+ } // fi
+ std::set< std::string >::const_iterator fnIt = filenames.begin( );
+ for( ; fnIt != filenames.end( ); ++fnIt )
+ reader->AddFileName( *fnIt );
+ try
+ {
+ reader->Update( );
+ }
+ catch( itk::ExceptionObject& err )
+ {
+ return( err.GetDescription( ) );
+
+ } // yrt
+ this->_SetOutput( 0, reader->GetOutput( ) );
+ return( "" );
+}
+
+// eof - $RCSfile$