X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2Ffpa%2FBase%2FAlgorithm.hxx;h=26729aaa37e77fdad63c16d4d207fa7bf66e9ba7;hb=89393f2267e42e921571c0184320d6c6382f34ab;hp=6af90482cef00943d3e6ee3121cb15c4d9957c5d;hpb=60785c9e18cab1a338f1ce54551e97a5ddfabac1;p=FrontAlgorithms.git diff --git a/lib/fpa/Base/Algorithm.hxx b/lib/fpa/Base/Algorithm.hxx index 6af9048..26729aa 100644 --- a/lib/fpa/Base/Algorithm.hxx +++ b/lib/fpa/Base/Algorithm.hxx @@ -6,13 +6,97 @@ #ifndef __fpa__Base__Algorithm__hxx__ #define __fpa__Base__Algorithm__hxx__ +// ------------------------------------------------------------------------- +template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > +fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::TEvent:: +TEvent( ) + : Superclass( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > +fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::TEvent:: +TEvent( const TVertex& v, unsigned long fid, bool intoq ) + : Superclass( ), + Vertex( v ), + FrontId( fid ), + IntoQueue( intoq ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > +fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::TEvent:: +~TEvent( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > +const char* +fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::TEvent:: +GetEventName( ) const +{ + return( "fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::TEvent" ); +} + +// ------------------------------------------------------------------------- +template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > +bool +fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::TEvent:: +CheckEvent( const itk::EventObject* e ) const +{ + return( dynamic_cast< const Self* >( e ) != NULL ); +} + +// ------------------------------------------------------------------------- +template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > +itk::EventObject* +fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::TEvent:: +MakeObject( ) const +{ + return( new Self ); +} + +// ------------------------------------------------------------------------- +template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > +void fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >:: +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 _TFilter, class _TMarksInterface, class _TSeedsInterface > +void fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >:: +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 _TFilter, class _TMarksInterface, class _TSeedsInterface > fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >:: Algorithm( ) : Superclass( ), _TMarksInterface( this ), - _TSeedsInterface( this ) + _TSeedsInterface( this ), + m_VisualDebug( false ) { } @@ -28,28 +112,42 @@ template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > void fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >:: GenerateData( ) { + this->InvokeEvent( itk::StartEvent( ) ); + // Init objects + this->_BeforeGenerateData( ); this->_ConfigureOutput( this->m_InitValue ); - this->_InitMarks( this->GetNumberOfSeeds( ) ); + this->_InitMarks( this->GetSeeds( ).size( ) ); + TNodes seeds = this->_UnifySeeds( ); + this->_PrepareSeeds( seeds ); // Init queue this->_QueueInit( ); - typename TSeeds::const_iterator sIt = this->BeginSeeds( ); - for( ; sIt != this->EndSeeds( ); ++sIt ) + typename TNodes::const_iterator sIt = seeds.begin( ); + for( ; sIt != seeds.end( ); ++sIt ) + { this->_QueuePush( *sIt ); + this->InvokeEvent( TEvent( sIt->Vertex, sIt->FrontId, true ) ); + + } // rof // Main loop while( this->_QueueSize( ) > 0 ) { // Get next candidate TNode node = this->_QueuePop( ); - if( !( this->_IsMarked( node ) ) ) + this->InvokeEvent( TEvent( node.Vertex, node.FrontId, false ) ); + if( !( this->_IsMarked( node.Vertex ) ) ) { - // Mark it - if( this->_Mark( node ) ) + // Update output value and mark vertex + this->_UpdateOutputValue( node ); + this->_Mark( node.Vertex, node.FrontId ); + + // The actual node was effectively marked? + if( node.FrontId > 0 ) { // Add neighborhood - TNeighborhood neighbors = this->_GetNeighbors( node ); + TNeighborhood neighbors = this->_GetNeighbors( node.Vertex ); typename TNeighborhood::const_iterator nIt = neighbors.begin( ); bool coll = false; while( nIt != neighbors.end( ) && !coll ) @@ -57,7 +155,7 @@ GenerateData( ) if( this->_IsMarked( *nIt ) ) { // Invoke stop at collisions - if( this->_Collisions( node, *nIt ) ) + if( this->_Collisions( node.Vertex, *nIt ) ) { this->_QueueClear( ); coll = true; @@ -65,7 +163,16 @@ GenerateData( ) } // fi } else - this->_QueuePush( *nIt ); + { + 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 @@ -73,8 +180,42 @@ GenerateData( ) } // fi } // fi + this->_FinishOneLoop( ); } // elihw + + // Finish + this->_AfterGenerateData( ); + this->InvokeEvent( itk::EndEvent( ) ); +} + +// ------------------------------------------------------------------------- +template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > +void fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >:: +_BeforeGenerateData( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > +void fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >:: +_AfterGenerateData( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > +void fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >:: +_FinishOneLoop( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TFilter, class _TMarksInterface, class _TSeedsInterface > +void fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >:: +_QueueInit( ) +{ + this->_QueueClear( ); } #endif // __fpa__Base__Algorithm__hxx__