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 <itkDataObject.h>
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 TMarksInterface( this ),
67 TSeedsInterface( this ),
68 m_VisualDebug( false ),
69 m_InitValue( TOutputValue( 0 ) )
73 // -------------------------------------------------------------------------
74 template< class _TTraits >
75 fpa::Filters::Algorithm< _TTraits >::
80 // -------------------------------------------------------------------------
81 template< class _TTraits >
82 void fpa::Filters::Algorithm< _TTraits >::
86 this->InvokeEvent( itk::StartEvent( ) );
87 this->_BeforeGenerateData( );
88 this->_ConfigureOutputs( );
89 this->_PrepareSeeds( this->_GetReferenceInput( ) );
90 this->_InitCollisions( this->GetSeeds( ).size( ) );
93 for( TNode seed: this->GetSeeds( ) )
95 seed.Value = this->m_InitValue;
96 this->_QueuePush( seed );
97 this->InvokeEvent( TEvent( seed.Vertex, seed.FrontId, true ) );
102 while( this->_QueueSize( ) > 0 )
104 // Get next candidate
105 TNode node = this->_QueuePop( );
106 this->InvokeEvent( TEvent( node.Vertex, node.FrontId, false ) );
108 if( !( this->_IsMarked( node ) ) )
110 // Update output value and mark vertex
111 this->_UpdateOutputValue( 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->_ComputeOutputValue( 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::LightBaseVertexFunction< TVertex > _TVertexFunc;
199 const itk::DataObject* input = this->GetInput( );
200 for( itk::Object* o: this->m_AssociatedObjects )
202 _TVertexFunc* f = dynamic_cast< _TVertexFunc* >( o );
204 f->SetDataObject( input );
209 // -------------------------------------------------------------------------
210 template< class _TTraits >
211 void fpa::Filters::Algorithm< _TTraits >::
212 _AfterGenerateData( )
216 // -------------------------------------------------------------------------
217 template< class _TTraits >
218 void fpa::Filters::Algorithm< _TTraits >::
223 // -------------------------------------------------------------------------
224 template< class _TTraits >
225 const itk::DataObject* fpa::Filters::Algorithm< _TTraits >::
226 _GetReferenceInput( ) const
228 return( this->GetInput( ) );
231 // -------------------------------------------------------------------------
232 template< class _TTraits >
233 typename fpa::Filters::Algorithm< _TTraits >::
234 TInputValue fpa::Filters::Algorithm< _TTraits >::
235 _GetInputValue( const TNode& n ) const
237 return( this->_GetInputValue( n.Vertex ) );
240 // -------------------------------------------------------------------------
241 template< class _TTraits >
242 typename fpa::Filters::Algorithm< _TTraits >::
243 TOutputValue fpa::Filters::Algorithm< _TTraits >::
244 _GetOutputValue( const TNode& n ) const
246 return( this->_GetOutputValue( n.Vertex ) );
249 #endif // __fpa__Filters__Algorithm__hxx__