X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2Ffpa%2FBase%2FRegionGrow.hxx;h=bf0a862e23b36ee15e3bb512003c4d8f35a44245;hb=a44c34f8d4118730a65ab3a7f9b6fc12614ce67a;hp=9e7bb7b801276b1db0a853c042f3ce1cdc77c1c7;hpb=f287dfe5d76525d02c37224c0a09ed6277fbbb52;p=FrontAlgorithms.git diff --git a/lib/fpa/Base/RegionGrow.hxx b/lib/fpa/Base/RegionGrow.hxx index 9e7bb7b..bf0a862 100644 --- a/lib/fpa/Base/RegionGrow.hxx +++ b/lib/fpa/Base/RegionGrow.hxx @@ -6,140 +6,160 @@ #ifndef __fpa__Base__RegionGrow__hxx__ #define __fpa__Base__RegionGrow__hxx__ -#include +// ------------------------------------------------------------------------- +template< class _TAlgorithm > +itk::ModifiedTimeType fpa::Base::RegionGrow< _TAlgorithm >:: +GetMTime( ) const +{ + itk::ModifiedTimeType t = this->Superclass::GetMTime( ); + if( this->m_ValuePredicate.IsNotNull( ) ) + { + itk::ModifiedTimeType q = this->m_ValuePredicate->GetMTime( ); + t = ( q < t )? q: t; + + } // fi + if( this->m_VertexPredicate.IsNotNull( ) ) + { + itk::ModifiedTimeType q = this->m_VertexPredicate->GetMTime( ); + t = ( q < t )? q: t; + + } // fi + + return( t ); +} // ------------------------------------------------------------------------- -template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > -const typename -fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >:: -TIntensityFunctor* -fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >:: -GetIntensityPredicate( ) const +template< class _TAlgorithm > +typename fpa::Base::RegionGrow< _TAlgorithm >:: +TOutputValue fpa::Base::RegionGrow< _TAlgorithm >:: +GetOutsideValue( ) const { - return( this->m_IntensityFunctor ); + return( this->GetInitValue( ) ); } // ------------------------------------------------------------------------- -template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > -const typename -fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >:: -TVertexFunctor* -fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >:: -GetVertexPredicate( ) const +template< class _TAlgorithm > +void fpa::Base::RegionGrow< _TAlgorithm >:: +SetOutsideValue( const TOutputValue& v ) { - return( this->m_VertexFunctor ); + this->SetInitValue( v ); } // ------------------------------------------------------------------------- -template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > -void -fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >:: -SetPredicate( TIntensityFunctor* functor ) +template< class _TAlgorithm > +void fpa::Base::RegionGrow< _TAlgorithm >:: +SetPredicate( TValuePredicate* p ) { - if( this->m_IntensityFunctor.GetPointer( ) != functor ) + if( this->m_ValuePredicate.GetPointer( ) != p ) { - this->m_IntensityFunctor = functor; + this->m_ValuePredicate = p; this->Modified( ); } // fi } // ------------------------------------------------------------------------- -template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > -void -fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >:: -SetPredicate( TVertexFunctor* functor ) +template< class _TAlgorithm > +void fpa::Base::RegionGrow< _TAlgorithm >:: +SetPredicate( TVertexPredicate* p ) { - if( this->m_VertexFunctor.GetPointer( ) != functor ) + if( this->m_VertexPredicate.GetPointer( ) != p ) { - this->m_VertexFunctor = functor; + this->m_VertexPredicate = p; this->Modified( ); } // fi } // ------------------------------------------------------------------------- -template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > -fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >:: +template< class _TAlgorithm > +fpa::Base::RegionGrow< _TAlgorithm >:: RegionGrow( ) : Superclass( ), - _TMarksInterface( this ), - _TSeedsInterface( this ), - m_InsideValue( TOutputValue( 1 ) ), - m_OutsideValue( TOutputValue( 0 ) ) + m_InsideValue( TOutputValue( 1 ) ) { + this->SetInitValue( TOutputValue( 0 ) ); } // ------------------------------------------------------------------------- -template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > -fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >:: +template< class _TAlgorithm > +fpa::Base::RegionGrow< _TAlgorithm >:: ~RegionGrow( ) { } // ------------------------------------------------------------------------- -template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > -void -fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >:: -GenerateData( ) +template< class _TAlgorithm > +void fpa::Base::RegionGrow< _TAlgorithm >:: +_ComputeOutputValue( TNode& n ) +{ + // Do nothing!!! +} + +// ------------------------------------------------------------------------- +template< class _TAlgorithm > +void fpa::Base::RegionGrow< _TAlgorithm >:: +_UpdateOutputValue( TNode& n ) { - // Init objects - this->_ConfigureOutputs( this->m_OutsideValue ); - this->_InitMarks( this->GetNumberOfSeeds( ) ); - - // Init queue - typedef std::pair< TVertex, unsigned long > _TNode; - std::queue< _TNode > q; - unsigned long frontId = 1; - for( TVertex seed: this->GetSeeds( ) ) - q.push( _TNode( seed, frontId++ ) ); - - // Main loop - while( q.size( ) > 0 ) + TInputValue value = this->_GetInputValue( n.Vertex ); + bool inside = false; + if( this->m_ValuePredicate.IsNotNull( ) ) + inside = this->m_ValuePredicate->Evaluate( value ); + if( this->m_VertexPredicate.IsNotNull( ) ) + inside &= this->m_VertexPredicate->Evaluate( n.Vertex ); + if( !inside ) { - // Get next candidate - _TNode node = q.front( ); - q.pop( ); - if( this->_IsMarked( node.first ) ) - continue; - this->_Mark( node.first, node.second ); - - // Apply inclusion predicate - TInputValue value = this->_GetInputValue( node.first ); - bool inside = false; - if( this->m_IntensityFunctor.IsNotNull( ) ) - inside = this->m_IntensityFunctor->Evaluate( value ); - if( this->m_VertexFunctor.IsNotNull( ) ) - inside &= this->m_VertexFunctor->Evaluate( node.first ); - if( !inside ) - continue; - - // Ok, pixel lays inside region - this->_SetOutputValue( node.first, this->m_InsideValue ); - - // Add neighborhood - TVertices neighbors = this->_GetNeighbors( node.first ); - for( TVertex neigh: neighbors ) - { - if( this->_IsMarked( neigh ) ) - { - // Invoke stop at collisions - unsigned long nColl = this->_Collisions( node.first, neigh ); - if( - this->StopAtOneFront( ) && - this->GetNumberOfSeeds( ) > 1 && - nColl == 1 - ) - while( q.size( ) > 0 ) - q.pop( ); - } - else - q.push( _TNode( neigh, node.second ) ); - - } // rof - - } // elihw - this->_FreeMarks( ); + n.Value = this->m_InitValue; + n.FrontId = 0; + } + else + n.Value = this->m_InsideValue; + this->Superclass::_UpdateOutputValue( n ); +} + +// ------------------------------------------------------------------------- +template< class _TAlgorithm > +void fpa::Base::RegionGrow< _TAlgorithm >:: +_QueueClear( ) +{ + this->m_Queue.clear( ); +} + +// ------------------------------------------------------------------------- +template< class _TAlgorithm > +typename fpa::Base::RegionGrow< _TAlgorithm >:: +TNode fpa::Base::RegionGrow< _TAlgorithm >:: +_QueuePop( ) +{ + TNode n = this->m_Queue.front( ); + this->m_Queue.pop_front( ); + return( n ); +} + +// ------------------------------------------------------------------------- +template< class _TAlgorithm > +void fpa::Base::RegionGrow< _TAlgorithm >:: +_QueuePush( const TNode& node ) +{ + this->m_Queue.push_back( node ); +} + +// ------------------------------------------------------------------------- +template< class _TAlgorithm > +unsigned long fpa::Base::RegionGrow< _TAlgorithm >:: +_QueueSize( ) const +{ + return( this->m_Queue.size( ) ); +} + +// ------------------------------------------------------------------------- +template< class _TAlgorithm > +void fpa::Base::RegionGrow< _TAlgorithm >:: +_PrepareSeeds( TNodes& nodes ) +{ + typename TNodes::iterator nIt = nodes.begin( ); + for( ; nIt != nodes.end( ); ++nIt ) + nIt->Value = this->m_InitValue; } #endif // __fpa__Base__RegionGrow__hxx__