-#ifndef __FPA__BASE__REGIONGROWING__HXX__
-#define __FPA__BASE__REGIONGROWING__HXX__
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
-// -------------------------------------------------------------------------
-template< class V, class C, class R, class S, class VC, class B >
-fpa::Base::RegionGrow< V, C, R, S, VC, B >::
-RegionGrow( )
- : Superclass( ),
- m_InsideValue( TResult( 1 ) ),
- m_OutsideValue( TResult( 0 ) )
-{
-}
+#ifndef __fpa__Base__RegionGrow__hxx__
+#define __fpa__Base__RegionGrow__hxx__
+
+#include <queue>
// -------------------------------------------------------------------------
-template< class V, class C, class R, class S, class VC, class B >
-fpa::Base::RegionGrow< V, C, R, S, VC, B >::
-~RegionGrow( )
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+const typename
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+TIntensityFunctor*
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+GetIntensityPredicate( ) const
{
+ return( this->m_IntensityFunctor );
}
// -------------------------------------------------------------------------
-template< class V, class C, class R, class S, class VC, class B >
-bool fpa::Base::RegionGrow< V, C, R, S, VC, B >::
-_CheckMembership( const TVertex& v ) const
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+const typename
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+TVertexFunctor*
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+GetVertexPredicate( ) const
{
- if( this->m_GrowingFunction.IsNotNull( ) )
- return( this->m_GrowingFunction->Evaluate( v ) );
- else
- return( false );
+ return( this->m_VertexFunctor );
}
// -------------------------------------------------------------------------
-template< class V, class C, class R, class S, class VC, class B >
-bool fpa::Base::RegionGrow< V, C, R, S, VC, B >::
-_ComputeNeighborResult(
- TResult& result, const TVertex& neighbor, const TVertex& parent
- ) const
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+void
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+SetPredicate( TIntensityFunctor* functor )
{
- if( this->_CheckMembership( neighbor ) )
- {
- result = this->m_InsideValue;
- return( true );
- }
- else
+ if( this->m_IntensityFunctor.GetPointer( ) != functor )
{
- result = this->m_OutsideValue;
- return( false );
+ this->m_IntensityFunctor = functor;
+ this->Modified( );
} // fi
}
// -------------------------------------------------------------------------
-template< class V, class C, class R, class S, class VC, class B >
-bool fpa::Base::RegionGrow< V, C, R, S, VC, B >::
-_IsQueueEmpty( ) const
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+void
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+SetPredicate( TVertexFunctor* functor )
{
- return( this->m_Queue.empty( ) );
+ if( this->m_VertexFunctor.GetPointer( ) != functor )
+ {
+ this->m_VertexFunctor = functor;
+ this->Modified( );
+
+ } // fi
}
// -------------------------------------------------------------------------
-template< class V, class C, class R, class S, class VC, class B >
-void fpa::Base::RegionGrow< V, C, R, S, VC, B >::
-_QueuePush( const TVertex& v, const _TNode& n )
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+RegionGrow( )
+ : Superclass( ),
+ _TMarksInterface( this ),
+ _TSeedsInterface( this ),
+ m_InsideValue( TOutputValue( 1 ) ),
+ m_OutsideValue( TOutputValue( 0 ) )
{
- this->m_Queue.push( std::pair< TVertex, _TNode >( v, n ) );
}
// -------------------------------------------------------------------------
-template< class V, class C, class R, class S, class VC, class B >
-void fpa::Base::RegionGrow< V, C, R, S, VC, B >::
-_QueuePop( TVertex& v, _TNode& n )
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+~RegionGrow( )
{
- v = this->m_Queue.front( ).first;
- n = this->m_Queue.front( ).second;
- this->m_Queue.pop( );
}
// -------------------------------------------------------------------------
-template< class V, class C, class R, class S, class VC, class B >
-void fpa::Base::RegionGrow< V, C, R, S, VC, B >::
-_QueueClear( )
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+void
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+GenerateData( )
{
- while( this->m_Queue.size( ) > 0 )
- this->m_Queue.pop( );
+ // 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;
+ typename TSeedsInterface::TSeeds::const_iterator sIt = this->BeginSeeds( );
+ for( ; sIt != this->EndSeeds( ); ++sIt )
+ q.push( _TNode( *sIt, frontId++ ) );
+
+ // Main loop
+ while( q.size( ) > 0 )
+ {
+ // 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 );
+ typename TVertices::const_iterator neighIt = neighbors.begin( );
+ bool coll = false;
+ while( neighIt != neighbors.end( ) && !coll )
+ {
+ TVertex neigh = *neighIt;
+ 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( );
+ coll = true;
+
+ } // fi
+ }
+ else
+ q.push( _TNode( neigh, node.second ) );
+ ++neighIt;
+
+ } // elihw
+
+ } // elihw
+ this->_FreeMarks( );
}
-#endif // __FPA__BASE__REGIONGROWING__HXX__
+#endif // __fpa__Base__RegionGrow__hxx__
// eof - $RCSfile$