From 346f515d533f3906ea180d73cc650bf9e3bcbc15 Mon Sep 17 00:00:00 2001 From: Jose Luis Guzman-Rodriguez Date: Tue, 27 Jan 2015 16:52:37 -0500 Subject: [PATCH] Almost compatible with new cpPlugins --- lib/cpm/Plugins/SimpleFillRegion.cxx | 63 ++++++++++------------------ lib/cpm/Plugins/SimpleFillRegion.h | 14 ++++--- 2 files changed, 31 insertions(+), 46 deletions(-) diff --git a/lib/cpm/Plugins/SimpleFillRegion.cxx b/lib/cpm/Plugins/SimpleFillRegion.cxx index 5dd4911..1821ca2 100644 --- a/lib/cpm/Plugins/SimpleFillRegion.cxx +++ b/lib/cpm/Plugins/SimpleFillRegion.cxx @@ -25,6 +25,13 @@ if( dynamic_cast< itk::Image< p2, d >* >( i ) != NULL ) \ r = this->f< p1, p2, d >( ) +// ------------------------------------------------------------------------- +std::string cpm::Plugins::SimpleFillRegion:: +GetClassName( ) const +{ + return( "cpm::Plugins::SimpleFillRegion" ); +} + // ------------------------------------------------------------------------- cpm::Plugins::SimpleFillRegion:: SimpleFillRegion( ) @@ -34,9 +41,15 @@ SimpleFillRegion( ) this->SetNumberOfOutputs( 1 ); this->_MakeOutput< cpPlugins::Interface::Image >( 0 ); - this->m_DefaultParameters[ "MinDelta" ] = TParameter( "double", "0" ); - this->m_DefaultParameters[ "MaxDelta" ] = TParameter( "double", "0" ); - this->m_DefaultParameters[ "Seed" ] = TParameter( "point", "0:0:0" ); + using namespace cpPlugins::Interface; + this->m_DefaultParameters.Configure( Parameters::Real, "MinDelta" ); + this->m_DefaultParameters.Configure( Parameters::Real, "MaxDelta" ); + this->m_DefaultParameters.Configure( Parameters::Point, "Seed" ); + + this->m_DefaultParameters.SetValueAsReal( "MinDelta", 0 ); + this->m_DefaultParameters.SetValueAsReal( "MaxDelta", 0 ); + this->m_DefaultParameters.SetValueAsPoint( "Seed", 3, 0.0, 0.0, 0.0 ); + this->m_Parameters = this->m_DefaultParameters; } // ------------------------------------------------------------------------- @@ -45,13 +58,6 @@ cpm::Plugins::SimpleFillRegion:: { } -// ------------------------------------------------------------------------- -std::string cpm::Plugins::SimpleFillRegion:: -GetClassName( ) const -{ - return( "cpm::Plugins::SimpleFillRegion" ); -} - // ------------------------------------------------------------------------- std::string cpm::Plugins::SimpleFillRegion:: _GenerateData( ) @@ -181,25 +187,10 @@ _GD2( ) _TImage2* i2 = dynamic_cast< _TImage2* >( this->_GetInput( 1 ) ); // Transform input seed - typename _TImage1::PointType pnt; - TParameters::const_iterator sIt; - sIt = this->m_Parameters.find( "Seed" ); - if( sIt == this->m_Parameters.end( ) ) - return( "cpm::Plugins::SimpleFillRegion: no seed given." ); - char* buff = new char[ sIt->second.second.size( ) + 1 ]; - std::memcpy( buff, sIt->second.second.c_str( ), sIt->second.second.size( ) ); - buff[ sIt->second.second.size( ) ] = '\0'; - char* tok = std::strtok( buff, ":" ); - for( unsigned int d = 0; d < D; ++d ) - { - pnt[ d ] = std::atof( tok ); - tok = std::strtok( NULL, ":" ); - - } // rof - delete [] buff; + typename _TImage1::PointType pnt = + this->m_Parameters.GetValueAsPoint< typename _TImage1::PointType >( "Seed" ); typename _TImage1::IndexType idx; - if( !( i1->TransformPhysicalPointToIndex( pnt, idx ) ) ) - return( "cpm::Plugins::SimpleFillRegion: seed is outside image regions." ); + i1->TransformPhysicalPointToIndex( pnt, idx ); // Check spatial compatilibity if( i1->GetLargestPossibleRegion( ) != i2->GetLargestPossibleRegion( ) ) @@ -212,16 +203,8 @@ _GD2( ) return( "cpm::Plugins::SimpleFillRegion: incompatible directions." ); // Create output - cpPlugins::Interface::Image* out_obj = - dynamic_cast< cpPlugins::Interface::Image* >( this->GetOutput( 0 ) ); - typename _TImage2::Pointer out = - dynamic_cast< _TImage2* >( out_obj->GetDataObject( ) ); - if( out.IsNull( ) ) - { - out = _TImage2::New( ); - this->_SetOutput( 0, out ); - - } // fi + typename _TImage2::Pointer out = _TImage2::New( ); + this->_SetOutput( 0, out ); // Create memory, if needed if( @@ -242,8 +225,8 @@ _GD2( ) } // fi out->FillBuffer( P2( 0 ) ); - P1 min_delta = P1( std::atof( this->m_Parameters[ "MinDelta" ].second.c_str( ) ) ); - P1 max_delta = P1( std::atof( this->m_Parameters[ "MaxDelta" ].second.c_str( ) ) ); + P1 min_delta = P1( this->m_Parameters.GetValueAsReal( "MinDelta" ) ); + P1 max_delta = P1( this->m_Parameters.GetValueAsReal( "MaxDelta" ) ); P1 lower = i1->GetPixel( idx ) - min_delta; P1 upper = i1->GetPixel( idx ) + min_delta; diff --git a/lib/cpm/Plugins/SimpleFillRegion.h b/lib/cpm/Plugins/SimpleFillRegion.h index 4b5cb9c..8bab400 100644 --- a/lib/cpm/Plugins/SimpleFillRegion.h +++ b/lib/cpm/Plugins/SimpleFillRegion.h @@ -15,17 +15,19 @@ namespace cpm public: typedef SimpleFillRegion Self; typedef cpPlugins::Interface::ImageToImageFilter Superclass; - - typedef Superclass::TParameter TParameter; - typedef Superclass::TParameters TParameters; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; public: - SimpleFillRegion( ); - virtual ~SimpleFillRegion( ); + itkNewMacro( Self ); + itkTypeMacro( SimpleFillRegion, cpPlugins_Interface_ImageToImageFilter ); virtual std::string GetClassName( ) const; protected: + SimpleFillRegion( ); + virtual ~SimpleFillRegion( ); + virtual std::string _GenerateData( ); template< unsigned int D > @@ -42,7 +44,7 @@ namespace cpm }; // --------------------------------------------------------------------- - PLUMA_INHERIT_PROVIDER( SimpleFillRegion, cpPlugins::Interface::Object ); + CPPLUGINS_INHERIT_PROVIDER( SimpleFillRegion ); } // ecapseman -- 2.47.1