From: Leonardo Flórez-Valencia Date: Thu, 6 Jul 2017 16:46:36 +0000 (-0500) Subject: ... X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=89393f2267e42e921571c0184320d6c6382f34ab;p=FrontAlgorithms.git ... --- diff --git a/lib/fpa/Base/Algorithm.h b/lib/fpa/Base/Algorithm.h index 43f7a08..5a02d6e 100644 --- a/lib/fpa/Base/Algorithm.h +++ b/lib/fpa/Base/Algorithm.h @@ -99,8 +99,8 @@ namespace fpa virtual TInputValue _GetInputValue( const TVertex& v ) const = 0; virtual TOutputValue _GetOutputValue( const TVertex& v ) const = 0; - virtual bool _ComputeOutputValue( TNode& n ) = 0; - virtual void _UpdateOutputValue( const TNode& n ) = 0; + virtual void _ComputeOutputValue( TNode& n ) = 0; + virtual void _UpdateOutputValue( TNode& n ) = 0; virtual void _QueueClear( ) = 0; virtual void _QueuePush( const TNode& node ) = 0; virtual unsigned long _QueueSize( ) const = 0; diff --git a/lib/fpa/Base/Algorithm.hxx b/lib/fpa/Base/Algorithm.hxx index 3a8b2d0..26729aa 100644 --- a/lib/fpa/Base/Algorithm.hxx +++ b/lib/fpa/Base/Algorithm.hxx @@ -139,12 +139,13 @@ GenerateData( ) this->InvokeEvent( TEvent( node.Vertex, node.FrontId, false ) ); if( !( this->_IsMarked( node.Vertex ) ) ) { - // Mark it - if( this->_Mark( node.Vertex, node.FrontId ) ) - { - // Update output value - this->_UpdateOutputValue( node ); + // Update output value and mark vertex + this->_UpdateOutputValue( node ); + this->_Mark( node.Vertex, node.FrontId ); + // The actual node was effectively marked? + if( node.FrontId > 0 ) + { // Add neighborhood TNeighborhood neighbors = this->_GetNeighbors( node.Vertex ); typename TNeighborhood::const_iterator nIt = neighbors.begin( ); @@ -167,12 +168,9 @@ GenerateData( ) nnode.Vertex = *nIt; nnode.Parent = node.Vertex; nnode.FrontId = node.FrontId; - if( this->_ComputeOutputValue( nnode ) ) - { - this->_QueuePush( nnode ); - this->InvokeEvent( TEvent( nnode.Vertex, nnode.FrontId, true ) ); - - } // fi + this->_ComputeOutputValue( nnode ); + this->_QueuePush( nnode ); + this->InvokeEvent( TEvent( nnode.Vertex, nnode.FrontId, true ) ); } // fi ++nIt; diff --git a/lib/fpa/Base/MarksInterface.h b/lib/fpa/Base/MarksInterface.h index 3b99765..9644457 100644 --- a/lib/fpa/Base/MarksInterface.h +++ b/lib/fpa/Base/MarksInterface.h @@ -27,7 +27,7 @@ namespace fpa virtual bool _IsMarked( const TVertex& v ) const = 0; virtual unsigned long _GetMark( const TVertex& v ) const = 0; - virtual bool _Mark( const TVertex& v, unsigned long frontId ) = 0; + virtual void _Mark( const TVertex& v, unsigned long frontId ) = 0; virtual void _InitMarks( unsigned long nSeeds ); virtual bool _Collisions( const TVertex& a, const TVertex& b ); diff --git a/lib/fpa/Base/Mori.h b/lib/fpa/Base/Mori.h index 6863278..ef8d7cc 100644 --- a/lib/fpa/Base/Mori.h +++ b/lib/fpa/Base/Mori.h @@ -72,7 +72,8 @@ namespace fpa virtual void _BeforeGenerateData( ) override; virtual void _AfterGenerateData( ) override; virtual void _FinishOneLoop( ) override; - virtual bool _ComputeOutputValue( TNode& n ) override; + virtual void _ComputeOutputValue( TNode& n ) override; + virtual void _UpdateOutputValue( TNode& n ) override; virtual void _QueueClear( ) override; virtual TNode _QueuePop( ) override; virtual void _QueuePush( const TNode& node ) override; diff --git a/lib/fpa/Base/Mori.hxx b/lib/fpa/Base/Mori.hxx index f014144..548d755 100644 --- a/lib/fpa/Base/Mori.hxx +++ b/lib/fpa/Base/Mori.hxx @@ -114,7 +114,6 @@ _AfterGenerateData( ) std::cout << int( sIt->first ) << " " << int( sIt->second.first ) << " " << sIt->second.second << std::endl; } // rof - std::cerr << ( this->m_CurrentThreshold != this->m_Thresholds.end( ) ) << std::endl; } // ------------------------------------------------------------------------- @@ -126,7 +125,6 @@ _FinishOneLoop( ) { this->m_Signal[ this->m_Signal.size( ) + 1 ] = TSignalData( *this->m_CurrentThreshold, this->m_Count ); - std::cerr << *( this->m_CurrentThreshold ) << std::endl; this->m_CurrentThreshold++; this->m_CurrentQueue = ( this->m_CurrentQueue + 1 ) % 2; if( this->m_CurrentThreshold != this->m_Thresholds.end( ) ) @@ -142,22 +140,35 @@ _FinishOneLoop( ) // ------------------------------------------------------------------------- template< class _TAlgorithm > -bool fpa::Base::Mori< _TAlgorithm >:: +void fpa::Base::Mori< _TAlgorithm >:: _ComputeOutputValue( TNode& n ) +{ + // Do nothing!!! +} + +// ------------------------------------------------------------------------- +template< class _TAlgorithm > +void fpa::Base::Mori< _TAlgorithm >:: +_UpdateOutputValue( TNode& n ) { TInputValue value = this->_GetInputValue( n.Vertex ); bool inside = this->m_Predicate->Evaluate( value ); - n.Value = this->m_InsideValue; if( !inside ) { + n.Value = this->m_InitValue; n.FrontId++; this->m_Queues[ ( this->m_CurrentQueue + 1 ) % 2 ].push_back( n ); + n.FrontId = 0; } else + { + n.Value = this->m_InsideValue; this->m_Count++; - return( inside ); + + } // fi + this->Superclass::_UpdateOutputValue( n ); } - + // ------------------------------------------------------------------------- template< class _TAlgorithm > void fpa::Base::Mori< _TAlgorithm >:: @@ -201,7 +212,7 @@ _PrepareSeeds( TNodes& nodes ) { typename TNodes::iterator nIt = nodes.begin( ); for( ; nIt != nodes.end( ); ++nIt ) - nIt->Value = this->m_InsideValue; + nIt->Value = this->m_InitValue; } #endif // __fpa__Base__Mori__hxx__ diff --git a/lib/fpa/Base/RegionGrow.h b/lib/fpa/Base/RegionGrow.h index 28657d6..8d7439f 100644 --- a/lib/fpa/Base/RegionGrow.h +++ b/lib/fpa/Base/RegionGrow.h @@ -63,7 +63,8 @@ namespace fpa RegionGrow( ); virtual ~RegionGrow( ); - virtual bool _ComputeOutputValue( TNode& n ) override; + virtual void _ComputeOutputValue( TNode& n ) override; + virtual void _UpdateOutputValue( TNode& n ) override; virtual void _QueueClear( ) override; virtual TNode _QueuePop( ) override; virtual void _QueuePush( const TNode& node ) override; diff --git a/lib/fpa/Base/RegionGrow.hxx b/lib/fpa/Base/RegionGrow.hxx index 503222c..bf0a862 100644 --- a/lib/fpa/Base/RegionGrow.hxx +++ b/lib/fpa/Base/RegionGrow.hxx @@ -90,8 +90,16 @@ fpa::Base::RegionGrow< _TAlgorithm >:: // ------------------------------------------------------------------------- template< class _TAlgorithm > -bool fpa::Base::RegionGrow< _TAlgorithm >:: +void fpa::Base::RegionGrow< _TAlgorithm >:: _ComputeOutputValue( TNode& n ) +{ + // Do nothing!!! +} + +// ------------------------------------------------------------------------- +template< class _TAlgorithm > +void fpa::Base::RegionGrow< _TAlgorithm >:: +_UpdateOutputValue( TNode& n ) { TInputValue value = this->_GetInputValue( n.Vertex ); bool inside = false; @@ -99,8 +107,14 @@ _ComputeOutputValue( TNode& n ) inside = this->m_ValuePredicate->Evaluate( value ); if( this->m_VertexPredicate.IsNotNull( ) ) inside &= this->m_VertexPredicate->Evaluate( n.Vertex ); - n.Value = ( inside )? this->m_InsideValue: this->m_InitValue; - return( inside ); + if( !inside ) + { + n.Value = this->m_InitValue; + n.FrontId = 0; + } + else + n.Value = this->m_InsideValue; + this->Superclass::_UpdateOutputValue( n ); } // ------------------------------------------------------------------------- @@ -145,7 +159,7 @@ _PrepareSeeds( TNodes& nodes ) { typename TNodes::iterator nIt = nodes.begin( ); for( ; nIt != nodes.end( ); ++nIt ) - nIt->Value = this->m_InsideValue; + nIt->Value = this->m_InitValue; } #endif // __fpa__Base__RegionGrow__hxx__ diff --git a/lib/fpa/Image/Algorithm.h b/lib/fpa/Image/Algorithm.h index 12a2f91..58dc5ee 100644 --- a/lib/fpa/Image/Algorithm.h +++ b/lib/fpa/Image/Algorithm.h @@ -64,10 +64,10 @@ namespace fpa virtual TNeighborhood _GetNeighbors( const TVertex& v ) const override; virtual TInputValue _GetInputValue( const TVertex& v ) const override; virtual TOutputValue _GetOutputValue( const TVertex& v ) const override; - virtual void _UpdateOutputValue( const TNode& n ) override; + virtual void _UpdateOutputValue( TNode& n ) override; virtual bool _IsMarked( const TVertex& v ) const override; virtual unsigned long _GetMark( const TVertex& v ) const override; - virtual bool _Mark( const TVertex& v, unsigned long frontId ) override; + virtual void _Mark( const TVertex& v, unsigned long frontId ) override; private: // Purposely not implemented. diff --git a/lib/fpa/Image/Algorithm.hxx b/lib/fpa/Image/Algorithm.hxx index a94f131..ba3497f 100644 --- a/lib/fpa/Image/Algorithm.hxx +++ b/lib/fpa/Image/Algorithm.hxx @@ -181,7 +181,7 @@ _GetOutputValue( const TVertex& v ) const template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface > void fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >:: -_UpdateOutputValue( const TNode& n ) +_UpdateOutputValue( TNode& n ) { this->GetOutput( )->SetPixel( n.Vertex, n.Value ); } @@ -206,12 +206,11 @@ _GetMark( const TVertex& v ) const // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface > -bool +void fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >:: _Mark( const TVertex& v, unsigned long frontId ) { this->GetMarks( )->SetPixel( v, TFrontId( frontId ) ); - return( true ); } #endif // __fpa__Image__Algorithm__hxx__ diff --git a/tests/image/RegionGrow_Tautology.cxx b/tests/image/RegionGrow_Tautology.cxx index d19969b..db60d0a 100644 --- a/tests/image/RegionGrow_Tautology.cxx +++ b/tests/image/RegionGrow_Tautology.cxx @@ -44,7 +44,7 @@ int main( int argc, char* argv[] ) filter->SetOutsideValue( 0 ); // Get all seeds - for( int i = 6; i < argc; i += 2 ) + for( int i = 5; i < argc; i += 2 ) { if( i + 1 < argc ) {