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__
9 #include <fpa/Functors/BaseVertexFunction.h>
11 // -------------------------------------------------------------------------
12 template< class _TTraits >
13 itk::ModifiedTimeType fpa::Filters::Algorithm< _TTraits >::
16 itk::ModifiedTimeType q = this->Superclass::GetMTime( );
17 itk::ModifiedTimeType t;
18 for( itk::Object* o: this->m_AssociatedObjects )
31 // -------------------------------------------------------------------------
32 template< class _TTraits >
33 void fpa::Filters::Algorithm< _TTraits >::
34 InvokeEvent( const itk::EventObject& e )
37 if( a.CheckEvent( &e ) )
39 if( this->m_VisualDebug )
40 this->Superclass::InvokeEvent( e );
43 this->Superclass::InvokeEvent( e );
46 // -------------------------------------------------------------------------
47 template< class _TTraits >
48 void fpa::Filters::Algorithm< _TTraits >::
49 InvokeEvent( const itk::EventObject& e ) const
52 if( a.CheckEvent( &e ) )
54 if( this->m_VisualDebug )
55 this->Superclass::InvokeEvent( e );
58 this->Superclass::InvokeEvent( e );
61 // -------------------------------------------------------------------------
62 template< class _TTraits >
63 fpa::Filters::Algorithm< _TTraits >::
66 TTraits::TMarksInterface( this ),
67 TTraits::TSeedsInterface( this ),
68 m_VisualDebug( false ),
69 m_InitValue( TOutputValue( 0 ) ),
70 m_FillValue( std::numeric_limits< TOutputValue >::max( ) )
74 // -------------------------------------------------------------------------
75 template< class _TTraits >
76 fpa::Filters::Algorithm< _TTraits >::
81 // -------------------------------------------------------------------------
82 template< class _TTraits >
83 void fpa::Filters::Algorithm< _TTraits >::
87 this->InvokeEvent( itk::StartEvent( ) );
88 this->_BeforeGenerateData( );
89 this->_ConfigureOutputs( );
90 this->_PrepareSeeds( this->_GetReferenceInput( ) );
91 this->_InitCollisions( this->GetSeeds( ).size( ) );
94 for( TNode seed: this->GetSeeds( ) )
96 seed.Value = this->m_InitValue;
97 this->_QueuePush( seed );
98 this->InvokeEvent( TEvent( seed.Vertex, seed.FrontId, true ) );
103 while( this->_QueueSize( ) > 0 )
105 // Get next candidate
106 TNode node = this->_QueuePop( );
107 this->InvokeEvent( TEvent( node.Vertex, node.FrontId, false ) );
109 if( this->_IsNotMarked( node ) )
111 // Update output value and mark vertex
112 this->_PostComputeOutputValue( node );
113 this->_AssignOutputValue( node );
116 // The actual node was effectively marked?
117 if( node.FrontId > 0 )
120 TNeighborhood neighbors = this->_GetNeighbors( node.Vertex );
121 typename TNeighborhood::const_iterator nIt = neighbors.begin( );
123 while( nIt != neighbors.end( ) && !coll )
125 if( this->_IsMarked( *nIt ) )
127 // Invoke stop at collisions
128 if( this->_Collisions( node.Vertex, *nIt ) )
130 this->_QueueClear( );
139 nnode.Parent = node.Vertex;
140 nnode.FrontId = node.FrontId;
141 this->_PreComputeOutputValue( nnode );
142 this->_QueuePush( nnode );
143 this->InvokeEvent( TEvent( nnode.Vertex, nnode.FrontId, true ) );
153 this->_Reinitialize( );
158 this->_AfterGenerateData( );
159 this->InvokeEvent( itk::EndEvent( ) );
162 // -------------------------------------------------------------------------
163 template< class _TTraits >
164 void fpa::Filters::Algorithm< _TTraits >::
165 _Associate( itk::Object* o )
167 if( this->m_AssociatedObjects.insert( o ).second )
171 // -------------------------------------------------------------------------
172 template< class _TTraits >
173 void fpa::Filters::Algorithm< _TTraits >::
174 _Deassociate( itk::Object* o )
176 std::set< itk::Object* >::iterator i = this->m_AssociatedObjects.find( o );
177 if( i != this->m_AssociatedObjects.end( ) )
179 this->m_AssociatedObjects.erase( i );
185 // -------------------------------------------------------------------------
186 template< class _TTraits >
187 void fpa::Filters::Algorithm< _TTraits >::
190 if( this->m_AssociatedObjects.size( ) > 0 )
192 this->m_AssociatedObjects.clear( );
195 // -------------------------------------------------------------------------
196 template< class _TTraits >
197 void fpa::Filters::Algorithm< _TTraits >::
198 _BeforeGenerateData( )
200 typedef fpa::Functors::BaseVertexFunction< TVertex > _TFunction;
201 const itk::DataObject* input = this->GetInput( );
202 for( itk::Object* o: this->m_AssociatedObjects )
204 _TFunction* f = dynamic_cast< _TFunction* >( o );
206 f->SetDataObject( input );
211 // -------------------------------------------------------------------------
212 template< class _TTraits >
213 void fpa::Filters::Algorithm< _TTraits >::
214 _AfterGenerateData( )
216 // Nothing to do at this level
219 // -------------------------------------------------------------------------
220 template< class _TTraits >
221 typename fpa::Filters::Algorithm< _TTraits >::
222 TInputValue fpa::Filters::Algorithm< _TTraits >::
223 _GetInputValue( const TNode& n ) const
225 return( this->_GetInputValue( n.Vertex ) );
228 // -------------------------------------------------------------------------
229 template< class _TTraits >
230 typename fpa::Filters::Algorithm< _TTraits >::
231 TOutputValue fpa::Filters::Algorithm< _TTraits >::
232 _GetOutputValue( const TNode& n ) const
234 return( this->_GetOutputValue( n.Vertex ) );
237 // -------------------------------------------------------------------------
238 template< class _TTraits >
239 typename fpa::Filters::Algorithm< _TTraits >::
240 TNeighborhood fpa::Filters::Algorithm< _TTraits >::
241 _GetNeighbors( const TNode& n ) const
243 return( this->_GetNeighbors( n.Vertex ) );
246 // -------------------------------------------------------------------------
247 template< class _TTraits >
248 const itk::DataObject* fpa::Filters::Algorithm< _TTraits >::
249 _GetReferenceInput( ) const
251 return( this->GetInput( ) );
254 // -------------------------------------------------------------------------
255 template< class _TTraits >
256 bool fpa::Filters::Algorithm< _TTraits >::
257 _IsMarked( const TNode& n ) const
259 return( this->_IsMarked( n.Vertex ) );
262 // -------------------------------------------------------------------------
263 template< class _TTraits >
264 bool fpa::Filters::Algorithm< _TTraits >::
265 _IsNotMarked( const TVertex& v ) const
267 return( !( this->_IsMarked( v ) ) );
270 // -------------------------------------------------------------------------
271 template< class _TTraits >
272 bool fpa::Filters::Algorithm< _TTraits >::
273 _IsNotMarked( const TNode& n ) const
275 return( this->_IsNotMarked( n.Vertex ) );
278 // -------------------------------------------------------------------------
279 template< class _TTraits >
280 void fpa::Filters::Algorithm< _TTraits >::
283 // Nothing to do at this level
286 #endif // __fpa__Filters__Algorithm__hxx__