1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5 #ifndef __fpa__Filters__Algorithm__hxx__
6 #define __fpa__Filters__Algorithm__hxx__
8 #include <fpa/Functors/BaseVertexFunction.h>
10 // -------------------------------------------------------------------------
11 template< class _TTraits >
12 itk::ModifiedTimeType fpa::Filters::Algorithm< _TTraits >::
15 itk::ModifiedTimeType q = this->Superclass::GetMTime( );
16 itk::ModifiedTimeType t;
17 for( itk::Object* o: this->m_AssociatedObjects )
30 // -------------------------------------------------------------------------
31 template< class _TTraits >
32 void fpa::Filters::Algorithm< _TTraits >::
33 InvokeEvent( const itk::EventObject& e )
36 if( a.CheckEvent( &e ) )
38 if( this->m_VisualDebug )
39 this->Superclass::InvokeEvent( e );
42 this->Superclass::InvokeEvent( e );
45 // -------------------------------------------------------------------------
46 template< class _TTraits >
47 void fpa::Filters::Algorithm< _TTraits >::
48 InvokeEvent( const itk::EventObject& e ) const
51 if( a.CheckEvent( &e ) )
53 if( this->m_VisualDebug )
54 this->Superclass::InvokeEvent( e );
57 this->Superclass::InvokeEvent( e );
60 // -------------------------------------------------------------------------
61 template< class _TTraits >
62 fpa::Filters::Algorithm< _TTraits >::
65 TTraits::TMarksInterface( this ),
66 TTraits::TSeedsInterface( this ),
67 m_VisualDebug( false ),
68 m_InitValue( TOutputValue( 0 ) )
72 // -------------------------------------------------------------------------
73 template< class _TTraits >
74 fpa::Filters::Algorithm< _TTraits >::
79 // -------------------------------------------------------------------------
80 template< class _TTraits >
81 void fpa::Filters::Algorithm< _TTraits >::
85 this->InvokeEvent( itk::StartEvent( ) );
86 this->_BeforeGenerateData( );
87 this->_ConfigureOutputs( );
88 this->_PrepareSeeds( this->_GetReferenceInput( ) );
89 this->_InitCollisions( this->GetSeeds( ).size( ) );
92 for( TNode seed: this->GetSeeds( ) )
94 seed.Value = this->m_InitValue;
95 this->_QueuePush( seed );
96 this->InvokeEvent( TEvent( seed.Vertex, seed.FrontId, true ) );
101 while( this->_QueueSize( ) > 0 )
103 // Get next candidate
104 TNode node = this->_QueuePop( );
105 this->InvokeEvent( TEvent( node.Vertex, node.FrontId, false ) );
107 if( this->_IsNotMarked( node ) )
109 // Update output value and mark vertex
110 this->_PostComputeOutputValue( node );
111 this->_AssignOutputValue( node );
114 // The actual node was effectively marked?
115 if( node.FrontId > 0 )
118 TNeighborhood neighbors = this->_GetNeighbors( node.Vertex );
119 typename TNeighborhood::const_iterator nIt = neighbors.begin( );
121 while( nIt != neighbors.end( ) && !coll )
123 if( this->_IsMarked( *nIt ) )
125 // Invoke stop at collisions
126 if( this->_Collisions( node.Vertex, *nIt ) )
128 this->_QueueClear( );
137 nnode.Parent = node.Vertex;
138 nnode.FrontId = node.FrontId;
139 this->_PreComputeOutputValue( nnode );
140 this->_QueuePush( nnode );
141 this->InvokeEvent( TEvent( nnode.Vertex, nnode.FrontId, true ) );
151 this->_Reinitialize( );
156 this->_AfterGenerateData( );
157 this->InvokeEvent( itk::EndEvent( ) );
160 // -------------------------------------------------------------------------
161 template< class _TTraits >
162 void fpa::Filters::Algorithm< _TTraits >::
163 _Associate( itk::Object* o )
165 if( this->m_AssociatedObjects.insert( o ).second )
169 // -------------------------------------------------------------------------
170 template< class _TTraits >
171 void fpa::Filters::Algorithm< _TTraits >::
172 _Deassociate( itk::Object* o )
174 std::set< itk::Object* >::iterator i = this->m_AssociatedObjects.find( o );
175 if( i != this->m_AssociatedObjects.end( ) )
177 this->m_AssociatedObjects.erase( i );
183 // -------------------------------------------------------------------------
184 template< class _TTraits >
185 void fpa::Filters::Algorithm< _TTraits >::
188 if( this->m_AssociatedObjects.size( ) > 0 )
190 this->m_AssociatedObjects.clear( );
193 // -------------------------------------------------------------------------
194 template< class _TTraits >
195 void fpa::Filters::Algorithm< _TTraits >::
196 _BeforeGenerateData( )
198 typedef fpa::Functors::BaseVertexFunction< TVertex > _TFunction;
199 const itk::DataObject* input = this->GetInput( );
200 for( itk::Object* o: this->m_AssociatedObjects )
202 _TFunction* f = dynamic_cast< _TFunction* >( o );
204 f->SetDataObject( input );
209 // -------------------------------------------------------------------------
210 template< class _TTraits >
211 void fpa::Filters::Algorithm< _TTraits >::
212 _AfterGenerateData( )
214 // Nothing to do at this level
217 // -------------------------------------------------------------------------
218 template< class _TTraits >
219 typename fpa::Filters::Algorithm< _TTraits >::
220 TInputValue fpa::Filters::Algorithm< _TTraits >::
221 _GetInputValue( const TNode& n ) const
223 return( this->_GetInputValue( n.Vertex ) );
226 // -------------------------------------------------------------------------
227 template< class _TTraits >
228 typename fpa::Filters::Algorithm< _TTraits >::
229 TOutputValue fpa::Filters::Algorithm< _TTraits >::
230 _GetOutputValue( const TNode& n ) const
232 return( this->_GetOutputValue( n.Vertex ) );
235 // -------------------------------------------------------------------------
236 template< class _TTraits >
237 typename fpa::Filters::Algorithm< _TTraits >::
238 TNeighborhood fpa::Filters::Algorithm< _TTraits >::
239 _GetNeighbors( const TNode& n ) const
241 return( this->_GetNeighbors( n.Vertex ) );
244 // -------------------------------------------------------------------------
245 template< class _TTraits >
246 const itk::DataObject* fpa::Filters::Algorithm< _TTraits >::
247 _GetReferenceInput( ) const
249 return( this->GetInput( ) );
252 // -------------------------------------------------------------------------
253 template< class _TTraits >
254 bool fpa::Filters::Algorithm< _TTraits >::
255 _IsMarked( const TNode& n ) const
257 return( this->_IsMarked( n.Vertex ) );
260 // -------------------------------------------------------------------------
261 template< class _TTraits >
262 bool fpa::Filters::Algorithm< _TTraits >::
263 _IsNotMarked( const TVertex& v ) const
265 return( !( this->_IsMarked( v ) ) );
268 // -------------------------------------------------------------------------
269 template< class _TTraits >
270 bool fpa::Filters::Algorithm< _TTraits >::
271 _IsNotMarked( const TNode& n ) const
273 return( this->_IsNotMarked( n.Vertex ) );
276 // -------------------------------------------------------------------------
277 template< class _TTraits >
278 void fpa::Filters::Algorithm< _TTraits >::
281 // Nothing to do at this level
284 #endif // __fpa__Filters__Algorithm__hxx__