1 #ifndef __FPA__BASE__ALGORITHM__H__
2 #define __FPA__BASE__ALGORITHM__H__
7 #include <fpa/Base/Events.h>
8 #include <fpa/Base/MinimumSpanningTree.h>
15 * Base front propagation algorithm. From a series of start seeds with
16 * costs, a priority queue is filled and emptied updating costs. Each
17 * vertex could be marked as "visited", "in the front", "not yet there"
20 * @param V Vertex type.
21 * @param C Vertex value type.
22 * @param R Result value type.
23 * @param S Space type where vertices are.
24 * @param VC Vertex lexicographical compare.
25 * @param B Base class for this algorithm. It should be any itk-based
26 * filter (itk::ProcessObject).
29 template< class V, class C, class R, class S, class VC, class B >
34 typedef Algorithm Self;
36 typedef itk::SmartPointer< Self > Pointer;
37 typedef itk::SmartPointer< const Self > ConstPointer;
43 typedef VC TVertexCompare;
45 fpa_Base_NewEvent( TStartEvent );
46 fpa_Base_NewEvent( TStartLoopEvent );
47 fpa_Base_NewEvent( TStartBacktrackingEvent );
48 fpa_Base_NewEvent( TEndEvent );
49 fpa_Base_NewEvent( TEndLoopEvent );
50 fpa_Base_NewEvent( TEndBacktrackingEvent );
51 fpa_Base_NewEventWithVertex( TAliveEvent, TVertex );
52 fpa_Base_NewEventWithVertex( TFrontEvent, TVertex );
53 fpa_Base_NewEventWithVertex( TFreezeEvent, TVertex );
54 fpa_Base_NewEventWithVertex( TBacktrackingEvent, TVertex );
57 typedef std::vector< TVertex > _TVertices;
58 typedef std::pair< TVertex, bool > _TCollision;
59 typedef std::vector< _TCollision > _TCollisionsRow;
60 typedef std::vector< _TCollisionsRow > _TCollisions;
85 typedef std::map< TVertex, _TNode, TVertexCompare > _TNodes;
89 fpa::Base::MinimumSpanningTree< V, _TCollisions, VC >
93 itkTypeMacro( Algorithm, B );
95 itkBooleanMacro( ThrowEvents );
96 itkBooleanMacro( StopAtOneFront );
98 itkGetConstMacro( ThrowEvents, bool );
99 itkGetConstMacro( StopAtOneFront, bool );
101 itkSetMacro( ThrowEvents, bool );
102 itkSetMacro( StopAtOneFront, bool );
105 TMinimumSpanningTree* GetMinimumSpanningTree( );
106 const TMinimumSpanningTree* GetMinimumSpanningTree( ) const;
107 void GraftMinimumSpanningTree( itk::DataObject* obj );
109 virtual void InvokeEvent( const itk::EventObject& e );
110 virtual void InvokeEvent( const itk::EventObject& e ) const;
112 void AddSeed( const TVertex& s, const TResult& r );
113 const TVertex& GetSeed( const unsigned int& id ) const;
115 unsigned long GetNumberOfSeeds( ) const;
119 virtual ~Algorithm( );
121 // Connection with itk's pipeline
122 virtual void GenerateData( );
124 // Main loop algorithm
125 virtual void _Loop( );
127 // Supporting methods for loop
128 virtual void _BeforeGenerateData( );
129 virtual void _AfterGenerateData( );
130 virtual void _BeforeLoop( );
131 virtual void _AfterLoop( );
133 // Methods to control forced stops
134 virtual bool _UpdateCollisions( const TVertex& a, const TVertex& b );
135 virtual bool _NeedToStop( ) const;
137 // Graph-related abstract methods
138 virtual unsigned long _NumberOfVertices( ) const = 0;
139 virtual const TValue& _VertexValue( const TVertex& v ) const = 0;
140 virtual double _Distance(
141 const TVertex& a, const TVertex& b
143 virtual bool _HasEdge( const TVertex& a, const TVertex& b ) const = 0;
144 virtual void _Neighborhood(
145 _TVertices& neighborhood, const TVertex& v
148 // Results-related abstract methods
149 virtual bool _ComputeNeighborResult(
150 TResult& result, const TVertex& neighbor, const TVertex& parent
152 virtual void _InitResults( ) = 0;
153 virtual const TResult& _Result( const TVertex& v ) const = 0;
154 virtual void _SetResult( const TVertex& v, const _TNode& n ) = 0;
156 // Marks-related abstract methods
157 virtual _TNode& _Node( const TVertex& v );
158 virtual const _TNode& _Node( const TVertex& v ) const;
159 virtual void _InitMarks( );
160 virtual void _Mark( const TVertex& v, const _TNode& node );
162 // Queue-related abstract methods
163 virtual void _InitQueue( );
164 virtual bool _IsQueueEmpty( ) const = 0;
165 virtual void _QueuePush( const TVertex& v, const _TNode& n ) = 0;
166 virtual void _QueuePop( TVertex& v, _TNode& n ) = 0;
167 virtual void _QueueClear( ) = 0;
170 // Purposely not implemented
171 Algorithm( const Self& other );
172 Self& operator=( const Self& other );
176 bool m_StopAtOneFront;
178 _TVertices m_SeedVertices;
180 _TCollisions m_Collisions;
182 unsigned int m_MinimumSpanningTreeIndex;
189 #include <fpa/Base/Algorithm.hxx>
191 #endif // __FPA__BASE__ALGORITHM__H__