1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
6 #ifndef __fpa__Base__Algorithm__hxx__
7 #define __fpa__Base__Algorithm__hxx__
9 // -------------------------------------------------------------------------
10 template< class _TFilter, class _TMarks, class _TSeeds >
11 void fpa::Base::Algorithm< _TFilter, _TMarks, _TSeeds >::
12 InvokeEvent( const itk::EventObject& e )
15 if( a.CheckEvent( &e ) )
17 if( this->m_VisualDebug )
18 this->Superclass::InvokeEvent( e );
21 this->Superclass::InvokeEvent( e );
24 // -------------------------------------------------------------------------
25 template< class _TFilter, class _TMarks, class _TSeeds >
26 void fpa::Base::Algorithm< _TFilter, _TMarks, _TSeeds >::
27 InvokeEvent( const itk::EventObject& e ) const
30 if( a.CheckEvent( &e ) )
32 if( this->m_VisualDebug )
33 this->Superclass::InvokeEvent( e );
36 this->Superclass::InvokeEvent( e );
39 // -------------------------------------------------------------------------
40 template< class _TFilter, class _TMarks, class _TSeeds >
41 fpa::Base::Algorithm< _TFilter, _TMarks, _TSeeds >::
46 m_VisualDebug( false )
50 // -------------------------------------------------------------------------
51 template< class _TFilter, class _TMarks, class _TSeeds >
52 fpa::Base::Algorithm< _TFilter, _TMarks, _TSeeds >::
57 // -------------------------------------------------------------------------
58 template< class _TFilter, class _TMarks, class _TSeeds >
59 void fpa::Base::Algorithm< _TFilter, _TMarks, _TSeeds >::
62 this->InvokeEvent( itk::StartEvent( ) );
65 this->_BeforeGenerateData( );
66 this->_ConfigureOutput( this->m_InitValue );
67 this->_InitMarks( this->GetSeeds( ).size( ) );
68 TNodes seeds = this->_UnifySeeds( );
69 this->_PrepareSeeds( seeds );
73 typename TNodes::const_iterator sIt = seeds.begin( );
74 for( ; sIt != seeds.end( ); ++sIt )
76 this->_QueuePush( *sIt );
77 this->InvokeEvent( TEvent( sIt->Vertex, sIt->FrontId, true ) );
82 while( this->_QueueSize( ) > 0 )
85 TNode node = this->_QueuePop( );
86 this->InvokeEvent( TEvent( node.Vertex, node.FrontId, false ) );
87 if( !( this->_IsMarked( node.Vertex ) ) )
89 // Update output value and mark vertex
90 this->_UpdateOutputValue( node );
91 this->_Mark( node.Vertex, node.FrontId );
93 // The actual node was effectively marked?
94 if( node.FrontId > 0 )
97 TNeighborhood neighbors = this->_GetNeighbors( node.Vertex );
98 typename TNeighborhood::const_iterator nIt = neighbors.begin( );
100 while( nIt != neighbors.end( ) && !coll )
102 if( this->_IsMarked( *nIt ) )
104 // Invoke stop at collisions
105 if( this->_Collisions( node.Vertex, *nIt ) )
107 this->_QueueClear( );
116 nnode.Parent = node.Vertex;
117 nnode.FrontId = node.FrontId;
118 this->_ComputeOutputValue( nnode );
119 this->_QueuePush( nnode );
120 this->InvokeEvent( TEvent( nnode.Vertex, nnode.FrontId, true ) );
130 this->_FinishOneLoop( );
135 this->_AfterGenerateData( );
136 this->InvokeEvent( itk::EndEvent( ) );
139 // -------------------------------------------------------------------------
140 template< class _TFilter, class _TMarks, class _TSeeds >
141 void fpa::Base::Algorithm< _TFilter, _TMarks, _TSeeds >::
142 _BeforeGenerateData( )
146 // -------------------------------------------------------------------------
147 template< class _TFilter, class _TMarks, class _TSeeds >
148 void fpa::Base::Algorithm< _TFilter, _TMarks, _TSeeds >::
149 _AfterGenerateData( )
153 // -------------------------------------------------------------------------
154 template< class _TFilter, class _TMarks, class _TSeeds >
155 void fpa::Base::Algorithm< _TFilter, _TMarks, _TSeeds >::
160 // -------------------------------------------------------------------------
161 template< class _TFilter, class _TMarks, class _TSeeds >
162 void fpa::Base::Algorithm< _TFilter, _TMarks, _TSeeds >::
165 this->_QueueClear( );
168 #endif // __fpa__Base__Algorithm__hxx__