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 _TMarksInterface, class _TSeedsInterface >
11 fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::TEvent::
17 // -------------------------------------------------------------------------
18 template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
19 fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::TEvent::
20 TEvent( const TVertex& v, unsigned long fid, bool intoq )
28 // -------------------------------------------------------------------------
29 template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
30 fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::TEvent::
35 // -------------------------------------------------------------------------
36 template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
38 fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::TEvent::
41 return( "fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::TEvent" );
44 // -------------------------------------------------------------------------
45 template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
47 fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::TEvent::
48 CheckEvent( const itk::EventObject* e ) const
50 return( dynamic_cast< const Self* >( e ) != NULL );
53 // -------------------------------------------------------------------------
54 template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
56 fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::TEvent::
62 // -------------------------------------------------------------------------
63 template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
64 void fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::
65 InvokeEvent( const itk::EventObject& e )
68 if( a.CheckEvent( &e ) )
70 if( this->m_VisualDebug )
71 this->Superclass::InvokeEvent( e );
74 this->Superclass::InvokeEvent( e );
77 // -------------------------------------------------------------------------
78 template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
79 void fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::
80 InvokeEvent( const itk::EventObject& e ) const
83 if( a.CheckEvent( &e ) )
85 if( this->m_VisualDebug )
86 this->Superclass::InvokeEvent( e );
89 this->Superclass::InvokeEvent( e );
92 // -------------------------------------------------------------------------
93 template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
94 fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::
97 _TMarksInterface( this ),
98 _TSeedsInterface( this ),
99 m_VisualDebug( false )
103 // -------------------------------------------------------------------------
104 template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
105 fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::
110 // -------------------------------------------------------------------------
111 template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
112 void fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::
115 this->InvokeEvent( itk::StartEvent( ) );
118 this->_BeforeGenerateData( );
119 this->_ConfigureOutput( this->m_InitValue );
120 this->_InitMarks( this->GetNumberOfSeeds( ) );
124 typename TSeeds::const_iterator sIt = this->BeginSeeds( );
125 for( ; sIt != this->EndSeeds( ); ++sIt )
127 this->_QueuePush( *sIt );
128 this->InvokeEvent( TEvent( sIt->Vertex, sIt->FrontId, true ) );
133 while( this->_QueueSize( ) > 0 )
135 // Get next candidate
136 TNode node = this->_QueuePop( );
137 this->InvokeEvent( TEvent( node.Vertex, node.FrontId, false ) );
138 if( !( this->_IsMarked( node.Vertex ) ) )
141 if( this->_Mark( node.Vertex, node.FrontId ) )
143 // Update output value
144 this->_UpdateOutputValue( node );
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 nnode.Value = this->_ComputeOutputValue( nnode );
169 this->_QueuePush( nnode );
170 this->InvokeEvent( TEvent( nnode.Vertex, nnode.FrontId, true ) );
184 this->_AfterGenerateData( );
185 this->InvokeEvent( itk::EndEvent( ) );
188 // -------------------------------------------------------------------------
189 template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
190 void fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::
191 _BeforeGenerateData( )
195 // -------------------------------------------------------------------------
196 template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
197 void fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::
198 _AfterGenerateData( )
202 // -------------------------------------------------------------------------
203 template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
204 void fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::
207 this->_QueueClear( );
210 #endif // __fpa__Base__Algorithm__hxx__