X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FPlugins%2FImageReader.cxx;h=aa7be8e6ce9c1d1c1f0b8b3cb55f3676d4d4f082;hb=7166b8d4db14d08a7df0dec5f98988eab186e941;hp=2d25301b04ba35fcbba36d0dc1b32b04ef706e1f;hpb=1adce86c283e253ec41f762652bc477d56d617a5;p=cpPlugins.git diff --git a/lib/cpPlugins/Plugins/ImageReader.cxx b/lib/cpPlugins/Plugins/ImageReader.cxx index 2d25301..aa7be8e 100644 --- a/lib/cpPlugins/Plugins/ImageReader.cxx +++ b/lib/cpPlugins/Plugins/ImageReader.cxx @@ -7,6 +7,13 @@ #include #include +// ------------------------------------------------------------------------- +std::string cpPlugins::Plugins::ImageReader:: +GetClassName( ) const +{ + return( "cpPlugins::Plugins::ImageReader" ); +} + // ------------------------------------------------------------------------- cpPlugins::Plugins::ImageReader:: ImageReader( ) @@ -15,11 +22,15 @@ ImageReader( ) this->SetNumberOfOutputs( 1 ); this->_MakeOutput< cpPlugins::Interface::Image >( 0 ); - this->m_DefaultParameters[ "FileName" ] = - TParameter( "string", "no_file_name" ); - this->m_DefaultParameters[ "PixelType" ] = TParameter( "type", "uchar" ); - this->m_DefaultParameters[ "ImageDimension" ] = TParameter( "int", "2" ); - this->m_DefaultParameters[ "IsColorImage" ] = TParameter( "bool", "0" ); + using namespace cpPlugins::Interface; + this->m_DefaultParameters.Configure( Parameters::String, "FileName" ); + 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; } // ------------------------------------------------------------------------- @@ -28,122 +39,103 @@ cpPlugins::Plugins::ImageReader:: { } -// ------------------------------------------------------------------------- -std::string cpPlugins::Plugins::ImageReader:: -GetClassName( ) const -{ - return( "cpPlugins::Plugins::ImageReader" ); -} - // ------------------------------------------------------------------------- std::string cpPlugins::Plugins::ImageReader:: _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 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 ); + 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:: -_GenerateData0( ) +_GD0( ) { - TParameters::const_iterator tIt, cIt; - - // Get image pixelType - 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 ret = "itk::Image pixel type not supported"; - if( cIt->second.second == "0" ) + 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( tIt->second.second == "char" ) - ret = this->_GenerateData1< char, D >( ); - else if( tIt->second.second == "short" ) - ret = this->_GenerateData1< short, D >( ); - else if( tIt->second.second == "int" ) - ret = this->_GenerateData1< int, D >( ); - else if( tIt->second.second == "long" ) - ret = this->_GenerateData1< long, D >( ); - else if( tIt->second.second == "uchar" ) - ret = this->_GenerateData1< unsigned char, D >( ); - else if( tIt->second.second == "ushort" ) - ret = this->_GenerateData1< unsigned short, D >( ); - else if( tIt->second.second == "uint" ) - ret = this->_GenerateData1< unsigned int, D >( ); - else if( tIt->second.second == "ulong" ) - ret = this->_GenerateData1< unsigned long, D >( ); - else if( tIt->second.second == "float" ) - ret = this->_GenerateData1< float, D >( ); - else if( tIt->second.second == "double" ) - ret = this->_GenerateData1< double, D >( ); + 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( cIt->second.second == "1" ) + else { - if( tIt->second.second == "char" ) - ret = this->_GenerateData1< itk::RGBPixel< char >, D >( ); - else if( tIt->second.second == "short" ) - ret = this->_GenerateData1< itk::RGBPixel< short >, D >( ); - else if( tIt->second.second == "int" ) - ret = this->_GenerateData1< itk::RGBPixel< int >, D >( ); - else if( tIt->second.second == "long" ) - ret = this->_GenerateData1< itk::RGBPixel< long >, D >( ); - else if( tIt->second.second == "uchar" ) - ret = this->_GenerateData1< itk::RGBPixel< unsigned char >, D >( ); - else if( tIt->second.second == "ushort" ) - ret = this->_GenerateData1< itk::RGBPixel< unsigned short >, D >( ); - else if( tIt->second.second == "uint" ) - ret = this->_GenerateData1< itk::RGBPixel< unsigned int >, D >( ); - else if( tIt->second.second == "ulong" ) - ret = this->_GenerateData1< itk::RGBPixel< unsigned long >, D >( ); - else if( tIt->second.second == "float" ) - ret = this->_GenerateData1< itk::RGBPixel< float >, D >( ); - else if( tIt->second.second == "double" ) - ret = this->_GenerateData1< itk::RGBPixel< double >, D >( ); + 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( ret ); + return( r ); } // ------------------------------------------------------------------------- template< class P, unsigned int D > std::string cpPlugins::Plugins::ImageReader:: -_GenerateData1( ) +_GD1( ) { - TParameters::const_iterator fIt; - - // Get image pixelType - fIt = this->m_Parameters.find( "FileName" ); - if( fIt == this->m_Parameters.end( ) ) - fIt = this->m_DefaultParameters.find( "FileName" ); + // Get filename + using namespace cpPlugins::Interface; + Parameters::TString fname = + this->m_Parameters.GetValueAsString( "FileName" ); typedef itk::Image< P, D > _TImage; - typedef itk::ImageFileReader< _TImage > _TImageReader; + typedef itk::ImageFileReader< _TImage > _TReader; - _TImageReader* reader = - dynamic_cast< _TImageReader* >( this->m_Reader.GetPointer( ) ); + _TReader* reader = + dynamic_cast< _TReader* >( this->m_RealProcessObject.GetPointer( ) ); if( reader == NULL ) { - this->m_Reader = _TImageReader::New( ); - reader = dynamic_cast< _TImageReader* >( this->m_Reader.GetPointer( ) ); + this->m_RealProcessObject = _TReader::New( ); + reader = + dynamic_cast< _TReader* >( this->m_RealProcessObject.GetPointer( ) ); } // fi - reader->SetFileName( fIt->second.second ); + reader->SetFileName( fname ); try { reader->Update( );