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 _TTraits >
11 fpa::Base::Algorithm< _TTraits >::TEvent::
17 // -------------------------------------------------------------------------
18 template< class _TTraits >
19 fpa::Base::Algorithm< _TTraits >::TEvent::
20 TEvent( const TVertex& v, unsigned long fid, bool intoq )
28 // -------------------------------------------------------------------------
29 template< class _TTraits >
30 fpa::Base::Algorithm< _TTraits >::TEvent::
35 // -------------------------------------------------------------------------
36 template< class _TTraits >
37 const char* fpa::Base::Algorithm< _TTraits >::TEvent::
40 return( "fpa::Base::Algorithm< _TTraits >::TEvent" );
43 // -------------------------------------------------------------------------
44 template< class _TTraits >
45 bool fpa::Base::Algorithm< _TTraits >::TEvent::
46 CheckEvent( const itk::EventObject* e ) const
48 return( dynamic_cast< const Self* >( e ) != NULL );
51 // -------------------------------------------------------------------------
52 template< class _TTraits >
53 itk::EventObject* fpa::Base::Algorithm< _TTraits >::TEvent::
59 // -------------------------------------------------------------------------
60 template< class _TTraits >
61 void fpa::Base::Algorithm< _TTraits >::
62 InvokeEvent( const itk::EventObject& e )
65 if( a.CheckEvent( &e ) )
67 if( this->m_VisualDebug )
68 this->Superclass::InvokeEvent( e );
71 this->Superclass::InvokeEvent( e );
74 // -------------------------------------------------------------------------
75 template< class _TTraits >
76 void fpa::Base::Algorithm< _TTraits >::
77 InvokeEvent( const itk::EventObject& e ) const
80 if( a.CheckEvent( &e ) )
82 if( this->m_VisualDebug )
83 this->Superclass::InvokeEvent( e );
86 this->Superclass::InvokeEvent( e );
89 // -------------------------------------------------------------------------
90 template< class _TTraits >
91 fpa::Base::Algorithm< _TTraits >::
94 TMarksInterface( this ),
95 TSeedsInterface( this ),
96 m_VisualDebug( false )
100 // -------------------------------------------------------------------------
101 template< class _TTraits >
102 fpa::Base::Algorithm< _TTraits >::
107 // -------------------------------------------------------------------------
108 template< class _TTraits >
109 void fpa::Base::Algorithm< _TTraits >::
112 this->InvokeEvent( itk::StartEvent( ) );
115 this->_BeforeGenerateData( );
116 this->_ConfigureOutput( this->m_InitValue );
117 this->_InitMarks( this->GetSeeds( ).size( ) );
118 TNodes seeds = this->_UnifySeeds( );
119 this->_PrepareSeeds( seeds );
123 typename TNodes::const_iterator sIt = seeds.begin( );
124 for( ; sIt != seeds.end( ); ++sIt )
126 this->_QueuePush( *sIt );
127 this->InvokeEvent( TEvent( sIt->Vertex, sIt->FrontId, true ) );
132 while( this->_QueueSize( ) > 0 )
134 // Get next candidate
135 TNode node = this->_QueuePop( );
136 this->InvokeEvent( TEvent( node.Vertex, node.FrontId, false ) );
137 if( !( this->_IsMarked( node.Vertex ) ) )
139 // Update output value and mark vertex
140 this->_UpdateOutputValue( node );
141 this->_Mark( node.Vertex, node.FrontId );
143 // The actual node was effectively marked?
144 if( node.FrontId > 0 )
147 TNeighborhood neighbors = this->_GetNeighbors( node.Vertex );
148 typename TNeighborhood::const_iterator nIt = neighbors.begin( );
150 while( nIt != neighbors.end( ) && !coll )
152 if( this->_IsMarked( *nIt ) )
154 // Invoke stop at collisions
155 if( this->_Collisions( node.Vertex, *nIt ) )
157 this->_QueueClear( );
166 nnode.Parent = node.Vertex;
167 nnode.FrontId = node.FrontId;
168 this->_ComputeOutputValue( nnode );
169 this->_QueuePush( nnode );
170 this->InvokeEvent( TEvent( nnode.Vertex, nnode.FrontId, true ) );
180 this->_FinishOneLoop( );
185 this->_AfterGenerateData( );
186 this->InvokeEvent( itk::EndEvent( ) );
189 // -------------------------------------------------------------------------
190 template< class _TTraits >
191 void fpa::Base::Algorithm< _TTraits >::
192 _BeforeGenerateData( )
196 // -------------------------------------------------------------------------
197 template< class _TTraits >
198 void fpa::Base::Algorithm< _TTraits >::
199 _AfterGenerateData( )
203 // -------------------------------------------------------------------------
204 template< class _TTraits >
205 void fpa::Base::Algorithm< _TTraits >::
210 // -------------------------------------------------------------------------
211 template< class _TTraits >
212 void fpa::Base::Algorithm< _TTraits >::
215 this->_QueueClear( );
218 #endif // __fpa__Base__Algorithm__hxx__