]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/Base/RegionGrow.hxx
...
[FrontAlgorithms.git] / lib / fpa / Base / RegionGrow.hxx
index 6865916c412b5771fb7270b67a2a4e14b6ea1f92..bf0a862e23b36ee15e3bb512003c4d8f35a44245 100644 (file)
+// =========================================================================
+// @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( )
+template< class _TAlgorithm >
+itk::ModifiedTimeType fpa::Base::RegionGrow< _TAlgorithm >::
+GetMTime( ) const
 {
-  return( dynamic_cast< TGrowFunction* >( this->GetVertexFunction( ) ) );
-}
+  itk::ModifiedTimeType t = this->Superclass::GetMTime( );
+  if( this->m_ValuePredicate.IsNotNull( ) )
+  {
+    itk::ModifiedTimeType q = this->m_ValuePredicate->GetMTime( );
+    t = ( q < t )? q: t;
 
-// -------------------------------------------------------------------------
-template< class _TSuperclass >
-const typename fpa::Base::RegionGrow< _TSuperclass >::
-TGrowFunction* fpa::Base::RegionGrow< _TSuperclass >::
-GetGrowFunction( ) const
-{
-  return(
-    dynamic_cast< const TGrowFunction* >( this->GetVertexFunction( ) )
-    );
+  } // fi
+  if( this->m_VertexPredicate.IsNotNull( ) )
+  {
+    itk::ModifiedTimeType q = this->m_VertexPredicate->GetMTime( );
+    t = ( q < t )? q: t;
+
+  } // fi
+
+  return( t );
 }
 
 // -------------------------------------------------------------------------
-template< class _TSuperclass >
-typename fpa::Base::RegionGrow< _TSuperclass >::
-TOutput fpa::Base::RegionGrow< _TSuperclass >::
-GetInsideValue( ) const
+template< class _TAlgorithm >
+typename fpa::Base::RegionGrow< _TAlgorithm >::
+TOutputValue fpa::Base::RegionGrow< _TAlgorithm >::
+GetOutsideValue( ) const
 {
-  const TGrowFunction* f = this->GetGrowFunction( );
-  if( f != NULL )
-    return( f->GetInsideValue( ) );
-  else
-    return( this->m_InitResult );
+  return( this->GetInitValue( ) );
 }
 
 // -------------------------------------------------------------------------
-template< class _TSuperclass >
-typename fpa::Base::RegionGrow< _TSuperclass >::
-TOutput fpa::Base::RegionGrow< _TSuperclass >::
-GetOutsideValue( ) const
+template< class _TAlgorithm >
+void fpa::Base::RegionGrow< _TAlgorithm >::
+SetOutsideValue( const TOutputValue& v )
 {
-  const TGrowFunction* f = this->GetGrowFunction( );
-  if( f != NULL )
-    return( f->GetOutsideValue( ) );
-  else
-    return( this->m_InitResult );
+  this->SetInitValue( v );
 }
 
 // -------------------------------------------------------------------------
-template< class _TSuperclass >
-void fpa::Base::RegionGrow< _TSuperclass >::
-SetGrowFunction( TGrowFunction* f )
+template< class _TAlgorithm >
+void fpa::Base::RegionGrow< _TAlgorithm >::
+SetPredicate( TValuePredicate* p )
 {
-  TGrowFunction* old_f = this->GetGrowFunction( );
-  if( old_f != NULL )
+  if( this->m_ValuePredicate.GetPointer( ) != p )
   {
-    f->SetInsideValue( old_f->GetInsideValue( ) );
-    f->SetOutsideValue( old_f->GetOutsideValue( ) );
+    this->m_ValuePredicate = p;
+    this->Modified( );
 
   } // fi
-  this->SetVertexFunction( f );
 }
 
 // -------------------------------------------------------------------------
-template< class _TSuperclass >
-void fpa::Base::RegionGrow< _TSuperclass >::
-SetInsideValue( const TOutput& v )
+template< class _TAlgorithm >
+void fpa::Base::RegionGrow< _TAlgorithm >::
+SetPredicate( TVertexPredicate* p )
 {
-  TGrowFunction* f = this->GetGrowFunction( );
-  if( f != NULL )
+  if( this->m_VertexPredicate.GetPointer( ) != p )
   {
-    f->SetInsideValue( v );
+    this->m_VertexPredicate = p;
     this->Modified( );
 
   } // fi
 }
 
 // -------------------------------------------------------------------------
-template< class _TSuperclass >
-void fpa::Base::RegionGrow< _TSuperclass >::
-SetOutsideValue( const TOutput& v )
+template< class _TAlgorithm >
+fpa::Base::RegionGrow< _TAlgorithm >::
+RegionGrow( )
+  : Superclass( ),
+    m_InsideValue( TOutputValue( 1 ) )
+{
+  this->SetInitValue( TOutputValue( 0 ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TAlgorithm >
+fpa::Base::RegionGrow< _TAlgorithm >::
+~RegionGrow( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TAlgorithm >
+void fpa::Base::RegionGrow< _TAlgorithm >::
+_ComputeOutputValue( TNode& n )
 {
-  TGrowFunction* f = this->GetGrowFunction( );
-  if( f != NULL )
+  // Do nothing!!!
+}
+
+// -------------------------------------------------------------------------
+template< class _TAlgorithm >
+void fpa::Base::RegionGrow< _TAlgorithm >::
+_UpdateOutputValue( TNode& n )
+{
+  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 )
   {
-    f->SetOutsideValue( v );
-    this->Modified( );
+    n.Value = this->m_InitValue;
+    n.FrontId = 0;
+  }
+  else
+    n.Value = this->m_InsideValue;
+  this->Superclass::_UpdateOutputValue( n );
+}
 
-  } // fi
+// -------------------------------------------------------------------------
+template< class _TAlgorithm >
+void fpa::Base::RegionGrow< _TAlgorithm >::
+_QueueClear( )
+{
+  this->m_Queue.clear( );
 }
 
 // -------------------------------------------------------------------------
-template< class _TSuperclass >
-fpa::Base::RegionGrow< _TSuperclass >::
-RegionGrow( )
-  : Superclass( )
+template< class _TAlgorithm >
+typename fpa::Base::RegionGrow< _TAlgorithm >::
+TNode fpa::Base::RegionGrow< _TAlgorithm >::
+_QueuePop( )
 {
-  typedef fpa::Base::Functors::RegionGrow::Tautology< TVertex, TOutput > _TFunc;
-  this->SetGrowFunction( _TFunc::New( ) );
-  this->m_InitResult = this->GetGrowFunction( )->GetOutsideValue( );
+  TNode n = this->m_Queue.front( );
+  this->m_Queue.pop_front( );
+  return( n );
 }
 
 // -------------------------------------------------------------------------
-template< class _TSuperclass >
-fpa::Base::RegionGrow< _TSuperclass >::
-~RegionGrow( )
+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 _TSuperclass >
-bool fpa::Base::RegionGrow< _TSuperclass >::
-_UpdateValue( _TQueueNode& v, const _TQueueNode& p )
+template< class _TAlgorithm >
+void fpa::Base::RegionGrow< _TAlgorithm >::
+_PrepareSeeds( TNodes& nodes )
 {
-  v.Result = this->_GetInputValue( v, p );
-  return( v.Result == this->GetInsideValue( ) );
+  typename TNodes::iterator nIt = nodes.begin( );
+  for( ; nIt != nodes.end( ); ++nIt )
+    nIt->Value = this->m_InitValue;
 }
 
 #endif // __fpa__Base__RegionGrow__hxx__