+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
+
#ifndef __fpa__Base__RegionGrow__hxx__
#define __fpa__Base__RegionGrow__hxx__
-#include <fpa/Base/Functors/RegionGrow/Tautology.h>
-
-// -------------------------------------------------------------------------
-template< class _TSuperclass >
-typename fpa::Base::RegionGrow< _TSuperclass >::
-TGrowFunction* fpa::Base::RegionGrow< _TSuperclass >::
-GetGrowFunction( )
-{
- // TODO: return( dynamic_cast< TGrowFunction* >( this->GetVertexFunction( ) ) );
- return( this->m_GrowFunction );
-}
-
-// -------------------------------------------------------------------------
-template< class _TSuperclass >
-const typename fpa::Base::RegionGrow< _TSuperclass >::
-TGrowFunction* fpa::Base::RegionGrow< _TSuperclass >::
-GetGrowFunction( ) const
-{
- /* TODO
- return(
- dynamic_cast< const TGrowFunction* >( this->GetVertexFunction( ) )
- );
- */
- return( this->m_GrowFunction );
-}
+#include <queue>
// -------------------------------------------------------------------------
-template< class _TSuperclass >
-typename fpa::Base::RegionGrow< _TSuperclass >::
-TOutput fpa::Base::RegionGrow< _TSuperclass >::
-GetInsideValue( ) const
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+const typename
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+TIntensityFunctor*
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+GetIntensityPredicate( ) const
{
- const TGrowFunction* f = this->GetGrowFunction( );
- if( f != NULL )
- return( f->GetInsideValue( ) );
- else
- return( this->m_InitResult );
+ return( this->m_IntensityFunctor );
}
// -------------------------------------------------------------------------
-template< class _TSuperclass >
-typename fpa::Base::RegionGrow< _TSuperclass >::
-TOutput fpa::Base::RegionGrow< _TSuperclass >::
-GetOutsideValue( ) 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
{
- const TGrowFunction* f = this->GetGrowFunction( );
- if( f != NULL )
- return( f->GetOutsideValue( ) );
- else
- return( this->m_InitResult );
+ return( this->m_VertexFunctor );
}
// -------------------------------------------------------------------------
-template< class _TSuperclass >
-void fpa::Base::RegionGrow< _TSuperclass >::
-SetGrowFunction( TGrowFunction* f )
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+void
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+SetPredicate( TIntensityFunctor* functor )
{
- TGrowFunction* old_f = this->GetGrowFunction( );
- if( old_f != NULL )
+ if( this->m_IntensityFunctor.GetPointer( ) != functor )
{
- f->SetInsideValue( old_f->GetInsideValue( ) );
- f->SetOutsideValue( old_f->GetOutsideValue( ) );
-
- } // fi
- this->m_GrowFunction = f;
-}
-
-// -------------------------------------------------------------------------
-template< class _TSuperclass >
-void fpa::Base::RegionGrow< _TSuperclass >::
-SetInsideValue( const TOutput& v )
-{
- TGrowFunction* f = this->GetGrowFunction( );
- if( f != NULL )
- {
- f->SetInsideValue( v );
+ this->m_IntensityFunctor = functor;
this->Modified( );
} // fi
}
// -------------------------------------------------------------------------
-template< class _TSuperclass >
-void fpa::Base::RegionGrow< _TSuperclass >::
-SetOutsideValue( const TOutput& v )
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+void
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+SetPredicate( TVertexFunctor* functor )
{
- TGrowFunction* f = this->GetGrowFunction( );
- if( f != NULL )
+ if( this->m_VertexFunctor.GetPointer( ) != functor )
{
- f->SetOutsideValue( v );
+ this->m_VertexFunctor = functor;
this->Modified( );
} // fi
}
// -------------------------------------------------------------------------
-template< class _TSuperclass >
-fpa::Base::RegionGrow< _TSuperclass >::
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
RegionGrow( )
- : Superclass( )
+ : Superclass( ),
+ _TMarksInterface( this ),
+ _TSeedsInterface( this ),
+ m_InsideValue( TOutputValue( 1 ) ),
+ m_OutsideValue( TOutputValue( 0 ) )
{
- typedef fpa::Base::Functors::RegionGrow::Tautology< TVertex, TOutput > _TFunc;
- this->SetGrowFunction( _TFunc::New( ) );
- this->m_InitResult = this->GetGrowFunction( )->GetOutsideValue( );
}
// -------------------------------------------------------------------------
-template< class _TSuperclass >
-fpa::Base::RegionGrow< _TSuperclass >::
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
~RegionGrow( )
{
}
// -------------------------------------------------------------------------
-template< class _TSuperclass >
-bool fpa::Base::RegionGrow< _TSuperclass >::
-_UpdateValue( _TQueueNode& v, const _TQueueNode& p )
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+void
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+GenerateData( )
{
- v.Result = this->_GetInputValue( v, p );
- return( v.Result == this->GetInsideValue( ) );
+ // 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__