+++ /dev/null
-// =========================================================================
-// @author Leonardo Florez Valencia
-// @email florez-l@javeriana.edu.co
-// =========================================================================
-#ifndef __fpa__Filters__Algorithm__hxx__
-#define __fpa__Filters__Algorithm__hxx__
-
-#include <itkDataObject.h>
-#include <fpa/Functors/BaseVertexFunction.h>
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-itk::ModifiedTimeType fpa::Filters::Algorithm< _TTraits >::
-GetMTime( ) const
-{
- itk::ModifiedTimeType q = this->Superclass::GetMTime( );
- itk::ModifiedTimeType t;
- for( itk::Object* o: this->m_AssociatedObjects )
- {
- if( o != NULL )
- {
- t = o->GetMTime( );
- q = ( q < t )? q: t;
-
- } // fi
-
- } // rof
- return( q );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-void fpa::Filters::Algorithm< _TTraits >::
-InvokeEvent( const itk::EventObject& e )
-{
- TEvent a;
- if( a.CheckEvent( &e ) )
- {
- if( this->m_VisualDebug )
- this->Superclass::InvokeEvent( e );
- }
- else
- this->Superclass::InvokeEvent( e );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-void fpa::Filters::Algorithm< _TTraits >::
-InvokeEvent( const itk::EventObject& e ) const
-{
- TEvent a;
- if( a.CheckEvent( &e ) )
- {
- if( this->m_VisualDebug )
- this->Superclass::InvokeEvent( e );
- }
- else
- this->Superclass::InvokeEvent( e );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-fpa::Filters::Algorithm< _TTraits >::
-Algorithm( )
- : Superclass( ),
- TMarksInterface( this ),
- TSeedsInterface( this ),
- m_VisualDebug( false ),
- m_InitValue( TOutputValue( 0 ) )
-{
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-fpa::Filters::Algorithm< _TTraits >::
-~Algorithm( )
-{
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-void fpa::Filters::Algorithm< _TTraits >::
-GenerateData( )
-{
- // Init algorithm
- this->InvokeEvent( itk::StartEvent( ) );
- this->_BeforeGenerateData( );
- this->_ConfigureOutputs( );
- this->_PrepareSeeds( this->_GetReferenceInput( ) );
- this->_InitCollisions( this->GetSeeds( ).size( ) );
-
- // Init queue
- for( TNode seed: this->GetSeeds( ) )
- {
- seed.Value = this->m_InitValue;
- this->_QueuePush( seed );
- this->InvokeEvent( TEvent( seed.Vertex, seed.FrontId, true ) );
-
- } // rof
-
- // Main loop
- while( this->_QueueSize( ) > 0 )
- {
- // Get next candidate
- TNode node = this->_QueuePop( );
- this->InvokeEvent( TEvent( node.Vertex, node.FrontId, false ) );
-
- if( !( this->_IsMarked( node ) ) )
- {
- // Update output value and mark vertex
- this->_UpdateOutputValue( node );
- this->_Mark( node );
-
- // The actual node was effectively marked?
- if( node.FrontId > 0 )
- {
- // Add neighborhood
- TNeighborhood neighbors = this->_GetNeighbors( node.Vertex );
- typename TNeighborhood::const_iterator nIt = neighbors.begin( );
- bool coll = false;
- while( nIt != neighbors.end( ) && !coll )
- {
- if( this->_IsMarked( *nIt ) )
- {
- // Invoke stop at collisions
- if( this->_Collisions( node.Vertex, *nIt ) )
- {
- this->_QueueClear( );
- coll = true;
-
- } // fi
- }
- else
- {
- TNode nnode;
- nnode.Vertex = *nIt;
- nnode.Parent = node.Vertex;
- nnode.FrontId = node.FrontId;
- this->_ComputeOutputValue( nnode );
- this->_QueuePush( nnode );
- this->InvokeEvent( TEvent( nnode.Vertex, nnode.FrontId, true ) );
-
- } // fi
- ++nIt;
-
- } // elihw
-
- } // fi
-
- } // fi
- this->_Reinitialize( );
-
- } // elihw
-
- // Finish algorithm
- this->_AfterGenerateData( );
- this->InvokeEvent( itk::EndEvent( ) );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-void fpa::Filters::Algorithm< _TTraits >::
-_Associate( itk::Object* o )
-{
- if( this->m_AssociatedObjects.insert( o ).second )
- this->Modified( );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-void fpa::Filters::Algorithm< _TTraits >::
-_Deassociate( itk::Object* o )
-{
- std::set< itk::Object* >::iterator i = this->m_AssociatedObjects.find( o );
- if( i != this->m_AssociatedObjects.end( ) )
- {
- this->m_AssociatedObjects.erase( i );
- this->Modified( );
-
- } // fi
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-void fpa::Filters::Algorithm< _TTraits >::
-_DeassociateAll( )
-{
- if( this->m_AssociatedObjects.size( ) > 0 )
- this->Modified( );
- this->m_AssociatedObjects.clear( );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-void fpa::Filters::Algorithm< _TTraits >::
-_BeforeGenerateData( )
-{
- typedef fpa::Functors::LightBaseVertexFunction< TVertex > _TVertexFunc;
- const itk::DataObject* input = this->GetInput( );
- for( itk::Object* o: this->m_AssociatedObjects )
- {
- _TVertexFunc* f = dynamic_cast< _TVertexFunc* >( o );
- if( f != NULL )
- f->SetDataObject( input );
-
- } // rof
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-void fpa::Filters::Algorithm< _TTraits >::
-_AfterGenerateData( )
-{
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-void fpa::Filters::Algorithm< _TTraits >::
-_Reinitialize( )
-{
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-const itk::DataObject* fpa::Filters::Algorithm< _TTraits >::
-_GetReferenceInput( ) const
-{
- return( this->GetInput( ) );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-typename fpa::Filters::Algorithm< _TTraits >::
-TInputValue fpa::Filters::Algorithm< _TTraits >::
-_GetInputValue( const TNode& n ) const
-{
- return( this->_GetInputValue( n.Vertex ) );
-}
-
-// -------------------------------------------------------------------------
-template< class _TTraits >
-typename fpa::Filters::Algorithm< _TTraits >::
-TOutputValue fpa::Filters::Algorithm< _TTraits >::
-_GetOutputValue( const TNode& n ) const
-{
- return( this->_GetOutputValue( n.Vertex ) );
-}
-
-#endif // __fpa__Filters__Algorithm__hxx__
-// eof - $RCSfile$