X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FPlugins%2FBasicFilters%2FFloodFillImageFilter.cxx;h=98b9e5864c92eb4540ddd70be56023ea3cf46b68;hb=da7cadeecad8bf04551591e9cb9e86977e2cbb47;hp=07fc9393ec14f52b2a41faaa8542ce38995c9e37;hpb=2553991938011b002691361f0ed4ae95a552a686;p=cpPlugins.git diff --git a/lib/cpPlugins/Plugins/BasicFilters/FloodFillImageFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/FloodFillImageFilter.cxx index 07fc939..98b9e58 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/FloodFillImageFilter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/FloodFillImageFilter.cxx @@ -1,5 +1,6 @@ #include "FloodFillImageFilter.h" #include +#include #include #include @@ -9,14 +10,21 @@ cpPlugins::BasicFilters::FloodFillImageFilter:: FloodFillImageFilter( ) : Superclass( ) { - this->SetNumberOfInputs( 1 ); - this->SetNumberOfOutputs( 1 ); - this->_MakeOutput< cpPlugins::Interface::Image >( 0 ); - - double seed[ 3 ] = { double( 0 ) }; - this->m_Parameters->ConfigureAsPoint( "Seed", 3, seed ); - this->m_Parameters->ConfigureAsUint( "InsideValue", 0 ); - this->m_Parameters->ConfigureAsUint( "OutsideValue", 255 ); + /* TODO + this->_AddInput( "Input" ); + this->_AddInput( "Seed" ); + this->_AddOutput< cpPlugins::Interface::Image >( "Output" ); + + this->m_Parameters->ConfigureAsReal( "Window" ); + this->m_Parameters->ConfigureAsReal( "Level" ); + this->m_Parameters->ConfigureAsUint( "InsideValue" ); + this->m_Parameters->ConfigureAsUint( "OutsideValue" ); + + this->m_Parameters->SetReal( "Window", 0 ); + this->m_Parameters->SetReal( "Level", 0 ); + this->m_Parameters->SetUint( "InsideValue", 0 ); + this->m_Parameters->SetUint( "OutsideValue", 255 ); + */ } // ------------------------------------------------------------------------- @@ -29,8 +37,9 @@ cpPlugins::BasicFilters::FloodFillImageFilter:: std::string cpPlugins::BasicFilters::FloodFillImageFilter:: _GenerateData( ) { + /* TODO cpPlugins::Interface::Image* image = - this->GetInput< cpPlugins::Interface::Image >( 0 ); + this->GetInput< cpPlugins::Interface::Image >( "Input" ); if( image == NULL ) return( "FloodFillImageFilter: No input image." ); @@ -40,6 +49,8 @@ _GenerateData( ) else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 ); else r = "FloodFillImageFilter: Input image type not supported."; return( r ); + */ + return( "" ); } // ------------------------------------------------------------------------- @@ -47,14 +58,18 @@ template< class I > std::string cpPlugins::BasicFilters::FloodFillImageFilter:: _GD0( itk::DataObject* image ) { + /* TODO return( this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >( image ) ); + */ + return( "" ); } // ------------------------------------------------------------------------- +/* TODO template< class I, class R = float > class cpPlugins_BasicFilters_FloodFillImageFilter_Function : public itk::ImageFunction< I, bool, R > @@ -76,6 +91,9 @@ public: itkImageFunction ); + itkSetMacro( Window, double ); + itkSetMacro( Level, double ); + public: virtual bool Evaluate( const TPoint& point ) const { @@ -83,7 +101,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 { @@ -92,7 +132,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( ) @@ -103,13 +146,21 @@ 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; }; +*/ // ------------------------------------------------------------------------- template< class I, class O > inline std::string cpPlugins::BasicFilters::FloodFillImageFilter:: _RealGD( itk::DataObject* image ) { + /* TODO typedef typename O::PixelType _OP; typedef cpPlugins_BasicFilters_FloodFillImageFilter_Function< I > _F; typedef itk::FloodFilledImageFunctionConditionalConstIterator< I, _F > _It; @@ -118,6 +169,8 @@ _RealGD( itk::DataObject* image ) 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" ) ); @@ -136,6 +189,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 ); @@ -144,7 +200,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 ); @@ -152,6 +208,8 @@ _RealGD( itk::DataObject* image ) } else return( "FloodFillImageFilter: output not correctly created." ); + */ + return( "" ); } // eof - $RCSfile$