-#ifndef __FPA__BASE__REGIONGROW__HXX__
-#define __FPA__BASE__REGIONGROW__HXX__
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
+
+#ifndef __fpa__Base__RegionGrow__hxx__
+#define __fpa__Base__RegionGrow__hxx__
+
+#include <queue>
// -------------------------------------------------------------------------
-template< class _TSuperclass >
-fpa::Base::RegionGrow< _TSuperclass >::
-RegionGrow( )
- : Superclass( ),
- m_RegionGrowFunction( NULL ),
- m_InsideValue( TScalar( 1 ) ),
- m_OutsideValue( TScalar( 0 ) )
+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 _TSuperclass >
-fpa::Base::RegionGrow< _TSuperclass >::
-~RegionGrow( )
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+const typename
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+TVertexFunctor*
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+GetVertexPredicate( ) const
{
+ return( this->m_VertexFunctor );
}
// -------------------------------------------------------------------------
-template< class _TSuperclass >
-bool fpa::Base::RegionGrow< _TSuperclass >::
-_Result( TNode& node, const TNode& parent )
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+void
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+SetPredicate( TIntensityFunctor* functor )
{
- if( this->m_RegionGrowFunction.IsNotNull( ) )
- {
- bool res = this->m_RegionGrowFunction->Evaluate( node.Vertex );
- node.Result = ( res )? this->m_InsideValue: this->m_OutsideValue;
- return( res );
- }
- else
+ if( this->m_IntensityFunctor.GetPointer( ) != functor )
{
- node.Result = this->m_OutsideValue;
- return( false );
+ this->m_IntensityFunctor = functor;
+ this->Modified( );
} // fi
}
// -------------------------------------------------------------------------
-template< class _TSuperclass >
-void fpa::Base::RegionGrow< _TSuperclass >::
-_QueueClear( )
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+void
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+SetPredicate( TVertexFunctor* functor )
{
- this->m_Queue.clear( );
+ if( this->m_VertexFunctor.GetPointer( ) != functor )
+ {
+ this->m_VertexFunctor = functor;
+ this->Modified( );
+
+ } // fi
}
// -------------------------------------------------------------------------
-template< class _TSuperclass >
-void fpa::Base::RegionGrow< _TSuperclass >::
-_QueuePush( const TNode& node )
+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_back( node );
}
// -------------------------------------------------------------------------
-template< class _TSuperclass >
-typename fpa::Base::RegionGrow< _TSuperclass >::
-TNode fpa::Base::RegionGrow< _TSuperclass >::
-_QueuePop( )
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+~RegionGrow( )
{
- TNode n = this->m_Queue.front( );
- this->m_Queue.pop_front( );
- return( n );
}
// -------------------------------------------------------------------------
-template< class _TSuperclass >
-bool fpa::Base::RegionGrow< _TSuperclass >::
-_IsQueueEmpty( ) const
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+void
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+GenerateData( )
{
- return( this->m_Queue.size( ) == 0 );
+ // 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__REGIONGROW__HXX__
+#endif // __fpa__Base__RegionGrow__hxx__
// eof - $RCSfile$