From e286ff49ea3582a5f4fad437dd133ec6c05c34dc Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Wed, 31 Dec 2014 12:01:20 +0100 Subject: [PATCH] More on parameters --- lib/cpPlugins/Interface/Parameters.cxx | 11 ++- lib/cpPlugins/Interface/Parameters.h | 1 + lib/cpPlugins/Plugins/ImageReader.cxx | 97 +++++++++---------- lib/cpPlugins/Plugins/ImageReader.h | 3 - lib/cpPlugins/Plugins/ImageSeriesReader.h | 3 - lib/cpPlugins/Plugins/ImageWriter.h | 3 - lib/cpPlugins/Plugins/MarchingCubes.h | 3 - lib/cpPlugins/Plugins/MeshReader.cxx | 49 ++++------ lib/cpPlugins/Plugins/MeshReader.h | 3 - .../Plugins/RGBImageToHSVChannelsFilter.cxx | 2 +- 10 files changed, 74 insertions(+), 101 deletions(-) diff --git a/lib/cpPlugins/Interface/Parameters.cxx b/lib/cpPlugins/Interface/Parameters.cxx index c51cde6..a42582c 100644 --- a/lib/cpPlugins/Interface/Parameters.cxx +++ b/lib/cpPlugins/Interface/Parameters.cxx @@ -49,7 +49,7 @@ cpPlugins_Interface_Parameters_SetArrayMacro( Point, double ); cpPlugins::Interface::Parameters:: Parameters( ) { - this->m_Parameters.clear( ); + this->Clear( ); } // ------------------------------------------------------------------------- @@ -63,7 +63,7 @@ Parameters( const Self& other ) cpPlugins::Interface::Parameters:: ~Parameters( ) { - this->m_Parameters.clear( ); + this->Clear( ); } // ------------------------------------------------------------------------- @@ -75,6 +75,13 @@ operator=( const Self& other ) return( *this ); } +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Parameters:: +Clear( ) +{ + this->m_Parameters.clear( ); +} + // ------------------------------------------------------------------------- void cpPlugins::Interface::Parameters:: Configure( const Self::Type& type, const TString& name ) diff --git a/lib/cpPlugins/Interface/Parameters.h b/lib/cpPlugins/Interface/Parameters.h index 7a7578a..9ad706e 100644 --- a/lib/cpPlugins/Interface/Parameters.h +++ b/lib/cpPlugins/Interface/Parameters.h @@ -48,6 +48,7 @@ namespace cpPlugins Self& operator=( const Self& other ); + void Clear( ); void Configure( const Self::Type& type, const TString& name ); void SetValueAsString( const TString& name, const TString& v ); void SetValueAsInt( const TString& name, const TInt& v ); diff --git a/lib/cpPlugins/Plugins/ImageReader.cxx b/lib/cpPlugins/Plugins/ImageReader.cxx index 0aa4bfc..aa7be8e 100644 --- a/lib/cpPlugins/Plugins/ImageReader.cxx +++ b/lib/cpPlugins/Plugins/ImageReader.cxx @@ -22,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; } // ------------------------------------------------------------------------- @@ -39,18 +43,13 @@ 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" ); - + using namespace cpPlugins::Interface; + Parameters::TUint dim = this->m_Parameters.GetValueAsUint( "Dimension" ); std::string r = "cpPlugins::Plugins::ImageReader: itk::Image dimension not supported."; - if ( dIt->second.second == "1" ) r = this->_GD0< 1 >( ); - else 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 >( ); + 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 ); } @@ -60,61 +59,55 @@ template< unsigned int D > std::string cpPlugins::Plugins::ImageReader:: _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" ); + 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( cIt->second.second == "0" ) + if( ci == 0 ) { - if( tIt->second.second == "char" ) + if( pt == "char" ) r = this->_GD1< char, D >( ); - else if( tIt->second.second == "short" ) + else if( pt == "short" ) r = this->_GD1< short, D >( ); - else if( tIt->second.second == "int" ) + else if( pt == "int" ) r = this->_GD1< int, D >( ); - else if( tIt->second.second == "long" ) + else if( pt == "long" ) r = this->_GD1< long, D >( ); - else if( tIt->second.second == "uchar" ) + else if( pt == "uchar" ) r = this->_GD1< unsigned char, D >( ); - else if( tIt->second.second == "ushort" ) + else if( pt == "ushort" ) r = this->_GD1< unsigned short, D >( ); - else if( tIt->second.second == "uint" ) + else if( pt == "uint" ) r = this->_GD1< unsigned int, D >( ); - else if( tIt->second.second == "ulong" ) + else if( pt == "ulong" ) r = this->_GD1< unsigned long, D >( ); - else if( tIt->second.second == "float" ) + else if( pt == "float" ) r = this->_GD1< float, D >( ); - else if( tIt->second.second == "double" ) + else if( pt == "double" ) r = this->_GD1< double, D >( ); } - else if( cIt->second.second == "1" ) + else { - if( tIt->second.second == "char" ) + if( pt == "char" ) r = this->_GD1< itk::RGBPixel< char >, D >( ); - else if( tIt->second.second == "short" ) + else if( pt == "short" ) r = this->_GD1< itk::RGBPixel< short >, D >( ); - else if( tIt->second.second == "int" ) + else if( pt == "int" ) r = this->_GD1< itk::RGBPixel< int >, D >( ); - else if( tIt->second.second == "long" ) + else if( pt == "long" ) r = this->_GD1< itk::RGBPixel< long >, D >( ); - else if( tIt->second.second == "uchar" ) + else if( pt == "uchar" ) r = this->_GD1< itk::RGBPixel< unsigned char >, D >( ); - else if( tIt->second.second == "ushort" ) + else if( pt == "ushort" ) r = this->_GD1< itk::RGBPixel< unsigned short >, D >( ); - else if( tIt->second.second == "uint" ) + else if( pt == "uint" ) r = this->_GD1< itk::RGBPixel< unsigned int >, D >( ); - else if( tIt->second.second == "ulong" ) + else if( pt == "ulong" ) r = this->_GD1< itk::RGBPixel< unsigned long >, D >( ); - else if( tIt->second.second == "float" ) + else if( pt == "float" ) r = this->_GD1< itk::RGBPixel< float >, D >( ); - else if( tIt->second.second == "double" ) + else if( pt == "double" ) r = this->_GD1< itk::RGBPixel< double >, D >( ); } // fi return( r ); @@ -125,12 +118,10 @@ template< class P, unsigned int D > std::string cpPlugins::Plugins::ImageReader:: _GD1( ) { - TParameters::const_iterator fIt; - // Get filename - fIt = this->m_Parameters.find( "FileName" ); - if( fIt == this->m_Parameters.end( ) ) - fIt = this->m_DefaultParameters.find( "FileName" ); + using namespace cpPlugins::Interface; + Parameters::TString fname = + this->m_Parameters.GetValueAsString( "FileName" ); typedef itk::Image< P, D > _TImage; typedef itk::ImageFileReader< _TImage > _TReader; @@ -144,7 +135,7 @@ _GD1( ) dynamic_cast< _TReader* >( this->m_RealProcessObject.GetPointer( ) ); } // fi - reader->SetFileName( fIt->second.second ); + reader->SetFileName( fname ); try { reader->Update( ); diff --git a/lib/cpPlugins/Plugins/ImageReader.h b/lib/cpPlugins/Plugins/ImageReader.h index b16cf0e..d89fd9a 100644 --- a/lib/cpPlugins/Plugins/ImageReader.h +++ b/lib/cpPlugins/Plugins/ImageReader.h @@ -20,9 +20,6 @@ namespace cpPlugins typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; - typedef Superclass::TParameter TParameter; - typedef Superclass::TParameters TParameters; - public: itkNewMacro( Self ); itkTypeMacro( ImageReader, cpPluginsInterfaceImageSource ); diff --git a/lib/cpPlugins/Plugins/ImageSeriesReader.h b/lib/cpPlugins/Plugins/ImageSeriesReader.h index 7577b67..f2bcf03 100644 --- a/lib/cpPlugins/Plugins/ImageSeriesReader.h +++ b/lib/cpPlugins/Plugins/ImageSeriesReader.h @@ -20,9 +20,6 @@ namespace cpPlugins typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; - typedef Superclass::TParameter TParameter; - typedef Superclass::TParameters TParameters; - public: itkNewMacro( Self ); itkTypeMacro( ImageSeriesReader, cpPluginsInterfaceImageSource ); diff --git a/lib/cpPlugins/Plugins/ImageWriter.h b/lib/cpPlugins/Plugins/ImageWriter.h index 4278ed7..4a02fe2 100644 --- a/lib/cpPlugins/Plugins/ImageWriter.h +++ b/lib/cpPlugins/Plugins/ImageWriter.h @@ -20,9 +20,6 @@ namespace cpPlugins typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; - typedef Superclass::TParameter TParameter; - typedef Superclass::TParameters TParameters; - public: itkNewMacro( Self ); itkTypeMacro( ImageWriter, cpPluginsInterfaceImageSink ); diff --git a/lib/cpPlugins/Plugins/MarchingCubes.h b/lib/cpPlugins/Plugins/MarchingCubes.h index 7ce3afd..c84668b 100644 --- a/lib/cpPlugins/Plugins/MarchingCubes.h +++ b/lib/cpPlugins/Plugins/MarchingCubes.h @@ -20,9 +20,6 @@ namespace cpPlugins typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; - typedef Superclass::TParameter TParameter; - typedef Superclass::TParameters TParameters; - public: itkNewMacro( Self ); itkTypeMacro( MarchingCubes, cpPluginsInterfaceImageToMeshFilter ); diff --git a/lib/cpPlugins/Plugins/MeshReader.cxx b/lib/cpPlugins/Plugins/MeshReader.cxx index b219899..b7ce4ba 100644 --- a/lib/cpPlugins/Plugins/MeshReader.cxx +++ b/lib/cpPlugins/Plugins/MeshReader.cxx @@ -19,10 +19,13 @@ MeshReader( ) this->SetNumberOfOutputs( 1 ); this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 ); - this->m_DefaultParameters[ "FileName" ] = - TParameter( "string", "no_file_name" ); - this->m_DefaultParameters[ "PixelType" ] = TParameter( "type", "float" ); - this->m_DefaultParameters[ "MeshDimension" ] = TParameter( "int", "3" ); + 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.SetValueAsString( "PixelType", "float" ); + this->m_DefaultParameters.SetValueAsUint( "Dimension", 3 ); + this->m_Parameters = this->m_DefaultParameters; } // ------------------------------------------------------------------------- @@ -35,16 +38,11 @@ cpPlugins::Plugins::MeshReader:: std::string cpPlugins::Plugins::MeshReader:: _GenerateData( ) { - TParameters::const_iterator dIt; - - // Get image dimension - dIt = this->m_Parameters.find( "MeshDimension" ); - if( dIt == this->m_Parameters.end( ) ) - dIt = this->m_DefaultParameters.find( "MeshDimension" ); - + using namespace cpPlugins::Interface; + Parameters::TUint dim = this->m_Parameters.GetValueAsUint( "Dimension" ); std::string r = "cpPlugins::Plugins::MeshReader: itk::Mesh dimension not supported."; - if( dIt->second.second == "3" ) r = this->_GD0< 3 >( ); - + if( dim == 3 ) + r = this->_GD0< 3 >( ); return( r ); } @@ -53,18 +51,11 @@ template< unsigned int D > std::string cpPlugins::Plugins::MeshReader:: _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" ); - + using namespace cpPlugins::Interface; + Parameters::TString pt = this->m_Parameters.GetValueAsString( "PixelType" ); std::string r = "cpPlugins::Plugins::MeshReader: itk::Mesh pixel type not supported"; - if( tIt->second.second == "float" ) - r = this->_GD1< float, D >( ); - else if( tIt->second.second == "double" ) - r = this->_GD1< double, D >( ); + if( pt == "float" ) r = this->_GD1< float, D >( ); + else if( pt == "double" ) r = this->_GD1< double, D >( ); return( r ); } @@ -73,12 +64,10 @@ template< class P, unsigned int D > std::string cpPlugins::Plugins::MeshReader:: _GD1( ) { - TParameters::const_iterator fIt; - // Get filename - fIt = this->m_Parameters.find( "FileName" ); - if( fIt == this->m_Parameters.end( ) ) - fIt = this->m_DefaultParameters.find( "FileName" ); + using namespace cpPlugins::Interface; + Parameters::TString fname = + this->m_Parameters.GetValueAsString( "FileName" ); using namespace cpPlugins::Extensions; typedef DataStructures::QuadEdgeMesh< P, D > _TMesh; @@ -93,7 +82,7 @@ _GD1( ) dynamic_cast< _TReader* >( this->m_RealProcessObject.GetPointer( ) ); } // fi - reader->SetFileName( fIt->second.second ); + reader->SetFileName( fname ); try { reader->Update( ); diff --git a/lib/cpPlugins/Plugins/MeshReader.h b/lib/cpPlugins/Plugins/MeshReader.h index f16f843..6689608 100644 --- a/lib/cpPlugins/Plugins/MeshReader.h +++ b/lib/cpPlugins/Plugins/MeshReader.h @@ -20,9 +20,6 @@ namespace cpPlugins typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; - typedef Superclass::TParameter TParameter; - typedef Superclass::TParameters TParameters; - public: itkNewMacro( Self ); itkTypeMacro( MeshReader, cpPluginsInterfaceMeshSource ); diff --git a/lib/cpPlugins/Plugins/RGBImageToHSVChannelsFilter.cxx b/lib/cpPlugins/Plugins/RGBImageToHSVChannelsFilter.cxx index 339a818..8985c61 100644 --- a/lib/cpPlugins/Plugins/RGBImageToHSVChannelsFilter.cxx +++ b/lib/cpPlugins/Plugins/RGBImageToHSVChannelsFilter.cxx @@ -37,7 +37,7 @@ RGBImageToHSVChannelsFilter( ) this->_MakeOutput< cpPlugins::Interface::Image >( 1 ); this->_MakeOutput< cpPlugins::Interface::Image >( 2 ); - this->m_DefaultParameters.clear( ); + this->m_DefaultParameters.Clear( ); } // ------------------------------------------------------------------------- -- 2.45.1