]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/Base/RegionGrow.hxx
...
[FrontAlgorithms.git] / lib / fpa / Base / RegionGrow.hxx
index bdc1ed34c7818bb162480615ab83749cd107b345..09fe59a726de35fa761af02f636317ee09db42f6 100644 (file)
-#ifndef __FPA__BASE__REGIONGROWING__HXX__
-#define __FPA__BASE__REGIONGROWING__HXX__
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
 
-// -------------------------------------------------------------------------
-template< class V, class R, class VV, class VC, class B >
-fpa::Base::RegionGrow< V, R, VV, VC, B >::
-RegionGrow( )
-  : Superclass( )
-{
-}
+#ifndef __fpa__Base__RegionGrow__hxx__
+#define __fpa__Base__RegionGrow__hxx__
 
-// -------------------------------------------------------------------------
-template< class V, class R, class VV, class VC, class B >
-fpa::Base::RegionGrow< V, R, VV, VC, B >::
-~RegionGrow( )
-{
-}
+#include <queue>
 
 // -------------------------------------------------------------------------
-template< class V, class R, class VV, class VC, class B >
-bool fpa::Base::RegionGrow< V, R, VV, VC, B >::
-_UpdateResult( _TNode& n )
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+const typename
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+TIntensityFunctor*
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+GetIntensityPredicate( ) const
 {
-  n.Result = R( this->_CheckMembership( n ) );
-  return( n.Result );
+  return( this->m_IntensityFunctor );
 }
 
 // -------------------------------------------------------------------------
-template< class V, class R, class VV, class VC, class B >
-void fpa::Base::RegionGrow< V, R, VV, VC, B >::
-_InitializeQueue( )
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+const typename
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+TVertexFunctor*
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+GetVertexPredicate( ) const
 {
-  for(
-    typename _TNodes::const_iterator vIt = this->m_Seeds.begin( );
-    vIt != this->m_Seeds.end( );
-    vIt++
-    )
-    this->_QueuePush( *vIt );
+  return( this->m_VertexFunctor );
 }
 
 // -------------------------------------------------------------------------
-template< class V, class R, class VV, class VC, class B >
-bool fpa::Base::RegionGrow< V, R, VV, VC, B >::
-_IsQueueEmpty( ) const
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+void
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+SetPredicate( TIntensityFunctor* functor )
 {
-  return( this->m_Queue.empty( ) );
+  if( this->m_IntensityFunctor.GetPointer( ) != functor )
+  {
+    this->m_IntensityFunctor = functor;
+    this->Modified( );
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------
-template< class V, class R, class VV, class VC, class B >
-void fpa::Base::RegionGrow< V, R, VV, VC, B >::
-_QueuePush( const _TNode& n )
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+void
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+SetPredicate( TVertexFunctor* functor )
 {
-  this->m_Queue.push( n );
+  if( this->m_VertexFunctor.GetPointer( ) != functor )
+  {
+    this->m_VertexFunctor = functor;
+    this->Modified( );
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------
-template< class V, class R, class VV, class VC, class B >
-typename fpa::Base::RegionGrow< V, R, VV, VC, B >::
-_TNode fpa::Base::RegionGrow< V, R, VV, VC, B >::
-_QueuePop( )
+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 ) )
 {
-  _TNode n = this->m_Queue.front( );
-  this->m_Queue.pop( );
-  return( n );
 }
 
 // -------------------------------------------------------------------------
-template< class V, class R, class VV, class VC, class B >
-void fpa::Base::RegionGrow< V, R, VV, VC, B >::
-_QueueClear( )
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+~RegionGrow( )
 {
-  while( this->m_Queue.size( ) > 0 )
-    this->m_Queue.pop( );
 }
 
 // -------------------------------------------------------------------------
-template< class V, class R, class VV, class VC, class B >
-bool fpa::Base::RegionGrow< V, R, VV, VC, B >::
-_UpdateNeigh( _TNode& nn, const _TNode& n )
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+void
+fpa::Base::RegionGrow< _TFilter, _TMarksInterface, _TSeedsInterface >::
+GenerateData( )
 {
-  return( true );
+  // 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$