#include #include #include #include #define ITK_MANUAL_INSTANTIATION #include #include // ------------------------------------------------------------------------- std::string cpPlugins::Plugins::ImageReader:: GetClassName( ) const { return( "cpPlugins::Plugins::ImageReader" ); } // ------------------------------------------------------------------------- cpPlugins::Plugins::ImageReader:: ImageReader( ) : Superclass( ) { this->SetNumberOfOutputs( 1 ); this->_MakeOutput< cpPlugins::Interface::Image >( 0 ); using namespace cpPlugins::Interface; this->m_DefaultParameters.Configure( Parameters::StringList, "FileNames" ); this->m_DefaultParameters.Configure( Parameters::String, "PixelType" ); this->m_DefaultParameters.Configure( Parameters::Uint, "Dimension" ); this->m_DefaultParameters.Configure( Parameters::Uint, "IsColorImage" ); this->m_DefaultParameters.SetValueAsString( "PixelType", "uchar" ); this->m_DefaultParameters.SetValueAsUint( "Dimension", 3 ); this->m_DefaultParameters.SetValueAsUint( "IsColorImage", 0 ); this->m_Parameters = this->m_DefaultParameters; } // ------------------------------------------------------------------------- cpPlugins::Plugins::ImageReader:: ~ImageReader( ) { } // ------------------------------------------------------------------------- std::string cpPlugins::Plugins::ImageReader:: _GenerateData( ) { using namespace cpPlugins::Interface; Parameters::TUint dim = this->m_Parameters.GetValueAsUint( "Dimension" ); std::string r = "cpPlugins::Plugins::ImageReader: itk::Image dimension not supported."; if ( dim == 1 ) r = this->_GD0< 1 >( ); else if( dim == 2 ) r = this->_GD0< 2 >( ); else if( dim == 3 ) r = this->_GD0< 3 >( ); else if( dim == 4 ) r = this->_GD0< 4 >( ); return( r ); } // ------------------------------------------------------------------------- template< unsigned int D > std::string cpPlugins::Plugins::ImageReader:: _GD0( ) { using namespace cpPlugins::Interface; Parameters::TString pt = this->m_Parameters.GetValueAsString( "PixelType" ); Parameters::TUint ci = this->m_Parameters.GetValueAsUint( "IsColorImage" ); std::string r = "cpPlugins::Plugins::ImageReader: itk::Image pixel type not supported"; if( ci == 0 ) { if( pt == "char" ) r = this->_GD1< char, D >( ); else if( pt == "short" ) r = this->_GD1< short, D >( ); else if( pt == "int" ) r = this->_GD1< int, D >( ); else if( pt == "long" ) r = this->_GD1< long, D >( ); else if( pt == "uchar" ) r = this->_GD1< unsigned char, D >( ); else if( pt == "ushort" ) r = this->_GD1< unsigned short, D >( ); else if( pt == "uint" ) r = this->_GD1< unsigned int, D >( ); else if( pt == "ulong" ) r = this->_GD1< unsigned long, D >( ); else if( pt == "float" ) r = this->_GD1< float, D >( ); else if( pt == "double" ) r = this->_GD1< double, D >( ); } else { if( pt == "char" ) r = this->_GD1< itk::RGBPixel< char >, D >( ); else if( pt == "short" ) r = this->_GD1< itk::RGBPixel< short >, D >( ); else if( pt == "int" ) r = this->_GD1< itk::RGBPixel< int >, D >( ); else if( pt == "long" ) r = this->_GD1< itk::RGBPixel< long >, D >( ); else if( pt == "uchar" ) r = this->_GD1< itk::RGBPixel< unsigned char >, D >( ); else if( pt == "ushort" ) r = this->_GD1< itk::RGBPixel< unsigned short >, D >( ); else if( pt == "uint" ) r = this->_GD1< itk::RGBPixel< unsigned int >, D >( ); else if( pt == "ulong" ) r = this->_GD1< itk::RGBPixel< unsigned long >, D >( ); else if( pt == "float" ) r = this->_GD1< itk::RGBPixel< float >, D >( ); else if( pt == "double" ) r = this->_GD1< itk::RGBPixel< double >, D >( ); } // fi return( r ); } // ------------------------------------------------------------------------- template< class P, unsigned int D > std::string cpPlugins::Plugins::ImageReader:: _GD1( ) { typedef itk::Image< P, D > _TImage; // Get filenames using namespace cpPlugins::Interface; std::vector< Parameters::TString > unordered_names; this->m_Parameters.GetValueAsStringList( unordered_names, "FileNames" ); if( unordered_names.size( ) == 1 ) { // Read single image typedef itk::ImageFileReader< _TImage > _TSingleReader; _TSingleReader* singleReader = dynamic_cast< _TSingleReader* >( this->m_RealProcessObject.GetPointer( ) ); if( singleReader == NULL ) { this->m_RealProcessObject = _TSingleReader::New( ); singleReader = dynamic_cast< _TSingleReader* >( this->m_RealProcessObject.GetPointer( ) ); } // fi singleReader->SetFileName( unordered_names.front( ) ); try { singleReader->Update( ); } catch( itk::ExceptionObject& err ) { return( err.GetDescription( ) ); } // yrt this->_SetOutput( 0, singleReader->GetOutput( ) ); return( "" ); } else if( unordered_names.size( ) > 1 ) { // Read image series std::set< std::string > ordered_names; for( unsigned int i = 0; i < unordered_names.size( ); ++i ) ordered_names.insert( unordered_names[ i ] ); typedef itk::ImageSeriesReader< _TImage > _TMultiReader; _TMultiReader* multiReader = dynamic_cast< _TMultiReader* >( this->m_RealProcessObject.GetPointer( ) ); if( multiReader == NULL ) { this->m_RealProcessObject = _TMultiReader::New( ); multiReader = dynamic_cast< _TMultiReader* >( this->m_RealProcessObject.GetPointer( ) ); } // fi std::set< std::string >::const_iterator fnIt = ordered_names.begin( ); for( ; fnIt != ordered_names.end( ); ++fnIt ) multiReader->AddFileName( *fnIt ); try { multiReader->Update( ); } catch( itk::ExceptionObject& err ) { return( err.GetDescription( ) ); } // yrt this->_SetOutput( 0, multiReader->GetOutput( ) ); return( "" ); } else return( "No image filename(s) given." ); } // eof - $RCSfile$