X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FPlugins%2FBasicFilters%2FFloodFillImageFilter.cxx;h=71f90cc70e8876b1bf374f5daaddf533a1cb900c;hb=3633aade338a13bc83642e99e6d61b6499e4b3af;hp=471c10bdb07deb2d961afbc725d4e7cc4a1ade64;hpb=9586180ab9da1ba2778099482b0231b933192719;p=cpPlugins.git diff --git a/lib/cpPlugins/Plugins/BasicFilters/FloodFillImageFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/FloodFillImageFilter.cxx index 471c10b..71f90cc 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/FloodFillImageFilter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/FloodFillImageFilter.cxx @@ -9,18 +9,15 @@ cpPlugins::BasicFilters::FloodFillImageFilter:: FloodFillImageFilter( ) : Superclass( ) { - this->SetNumberOfInputs( 1 ); - this->SetNumberOfOutputs( 1 ); - this->_MakeOutput< cpPlugins::Interface::Image >( 0 ); - - using namespace cpPlugins::Interface; - this->m_DefaultParameters.Configure( Parameters::Point, "Seed" ); - this->m_DefaultParameters.Configure( Parameters::Real, "InsideValue" ); - this->m_DefaultParameters.Configure( Parameters::Real, "OutsideValue" ); - this->m_DefaultParameters.SetValueAsPoint( "Seed", 3, 0, 0, 0 ); - this->m_DefaultParameters.SetValueAsReal( "InsideValue", 255 ); - this->m_DefaultParameters.SetValueAsReal( "OutsideValue", 0 ); - this->m_Parameters = this->m_DefaultParameters; + this->_AddInput( "Input" ); + this->_MakeOutput< cpPlugins::Interface::Image >( "Output" ); + + double seed[ 3 ] = { double( 0 ) }; + this->m_Parameters->ConfigureAsPoint( "Seed", 3, seed ); + this->m_Parameters->ConfigureAsReal( "Window", 0 ); + this->m_Parameters->ConfigureAsReal( "Level", 0 ); + this->m_Parameters->ConfigureAsUint( "InsideValue", 0 ); + this->m_Parameters->ConfigureAsUint( "OutsideValue", 255 ); } // ------------------------------------------------------------------------- @@ -34,7 +31,7 @@ std::string cpPlugins::BasicFilters::FloodFillImageFilter:: _GenerateData( ) { cpPlugins::Interface::Image* image = - this->GetInput< cpPlugins::Interface::Image >( 0 ); + this->GetInput< cpPlugins::Interface::Image >( "Input" ); if( image == NULL ) return( "FloodFillImageFilter: No input image." ); @@ -80,6 +77,9 @@ public: itkImageFunction ); + itkSetMacro( Window, double ); + itkSetMacro( Level, double ); + public: virtual bool Evaluate( const TPoint& point ) const { @@ -87,7 +87,29 @@ public: } virtual bool EvaluateAtIndex( const TIndex& index ) const { - return( true ); + if( !( this->IsInsideBuffer( index ) ) ) + return( false ); + + const I* image = this->GetInputImage( ); + double w2 = this->m_Window / double( 2 ); + double min = this->m_Level - w2; + double max = this->m_Level + w2; + unsigned char val = double( 0 ); + double x = double( image->GetPixel( index ) ); + double m = double( 100 ) / this->m_Window; + double b = ( this->m_Window - ( double( 2 ) * this->m_Level ) ); + b *= double( 50 ) / this->m_Window; + if( x > min && x < max ) + val = ( unsigned char )( ( m * x ) + b ); + + if( this->m_Start ) + { + this->m_StartValue = val; + this->m_Start = false; + return( true ); + } + else + return( std::abs( this->m_StartValue - val ) <= 2 ); } virtual bool EvaluateAtContinuousIndex( const TCIndex& index ) const { @@ -96,7 +118,10 @@ public: protected: cpPlugins_BasicFilters_FloodFillImageFilter_Function( ) - : Superclass( ) + : Superclass( ), + m_Window( double( 0 ) ), + m_Level( double( 0 ) ), + m_Start( true ) { } virtual ~cpPlugins_BasicFilters_FloodFillImageFilter_Function( ) @@ -107,6 +132,12 @@ private: // Purposely not implemented cpPlugins_BasicFilters_FloodFillImageFilter_Function( const Self& other ); Self& operator=( const Self& other ); + +protected: + double m_Window; + double m_Level; + mutable unsigned char m_StartValue; + mutable bool m_Start; }; // ------------------------------------------------------------------------- @@ -119,9 +150,13 @@ _RealGD( itk::DataObject* image ) typedef itk::FloodFilledImageFunctionConditionalConstIterator< I, _F > _It; typename I::PointType pseed; - pseed = this->m_Parameters.GetValueAsPoint< typename I::PointType >( "Seed" ); - _OP in_val = _OP( this->m_Parameters.GetValueAsReal( "InsideValue" ) ); - _OP out_val = _OP( this->m_Parameters.GetValueAsReal( "OutsideValue" ) ); + pseed = this->m_Parameters->GetPoint< typename I::PointType >( + "Seed", I::ImageDimension + ); + double window = this->m_Parameters->GetReal( "Window" ); + double level = this->m_Parameters->GetReal( "Level" ); + _OP in_val = _OP( this->m_Parameters->GetUint( "InsideValue" ) ); + _OP out_val = _OP( this->m_Parameters->GetUint( "OutsideValue" ) ); const I* in = dynamic_cast< const I* >( image ); typename I::IndexType seed; @@ -138,6 +173,9 @@ _RealGD( itk::DataObject* image ) out->FillBuffer( out_val ); typename _F::Pointer f = _F::New( ); + f->SetInputImage( in ); + f->SetWindow( window ); + f->SetLevel( level ); _It i( in, f ); i.AddSeed( seed ); @@ -146,7 +184,7 @@ _RealGD( itk::DataObject* image ) // Connect output cpPlugins::Interface::Image* out_port = - this->GetOutput< cpPlugins::Interface::Image >( 0 ); + this->GetOutput< cpPlugins::Interface::Image >( "Output" ); if( out_port != NULL ) { out_port->SetITK< O >( out );