1 #ifndef __FPA__BASE__ALGORITHM__H__
2 #define __FPA__BASE__ALGORITHM__H__
7 #include <fpa/Base/Events.h>
14 * Base front propagation algorithm. From a series of start seeds with
15 * costs, a priority queue is filled and emptied updating costs. Each
16 * vertex could be marked as "visited", "in the front", "not yet there"
19 * @param T Traits used for this algorithm
21 template< class T, class B >
26 // Standard class typdedefs
27 typedef Algorithm Self;
29 typedef itk::SmartPointer< Self > Pointer;
30 typedef itk::SmartPointer< const Self > ConstPointer;
34 typedef B TBaseFilter;
35 typedef typename T::TCost TCost;
36 typedef typename T::TResult TResult;
37 typedef typename T::TVertex TVertex;
38 typedef typename T::TVertexValue TVertexValue;
41 typedef typename T::TFrontId _TFrontId;
42 typedef typename T::TNode _TNode;
43 typedef typename T::TNodes _TNodes;
44 typedef typename T::TVertexCmp _TVertexCmp;
46 typedef std::map< TVertex, _TNode, _TVertexCmp > _TMarks;
48 typedef std::pair< TVertex, bool > _TCollision;
49 typedef std::vector< _TCollision > _TCollisionSitesRow;
50 typedef std::vector< _TCollisionSitesRow > _TCollisionSites;
53 typedef BaseEvent< _TNode > TEvent;
54 typedef FrontEvent< _TNode > TFrontEvent;
55 typedef MarkEvent< _TNode > TMarkEvent;
56 typedef CollisionEvent< _TNode > TCollisionEvent;
57 typedef EndEvent< _TNode > TEndEvent;
60 itkTypeMacro( Algorithm, itkProcessObject );
62 itkBooleanMacro( StopAtOneFront );
63 itkBooleanMacro( ThrowEvents );
65 itkGetConstMacro( StopAtOneFront, bool );
66 itkGetConstMacro( ThrowEvents, bool );
68 itkSetMacro( StopAtOneFront, bool );
69 itkSetMacro( ThrowEvents, bool );
72 virtual void InvokeEvent( const itk::EventObject& e );
73 virtual void InvokeEvent( const itk::EventObject& e ) const;
75 /// Seeds manipulation
76 void AddSeed( const TVertex& s, const TResult& v );
77 const TVertex& GetSeed( const unsigned long& i ) const;
79 unsigned long GetNumberOfSeeds( ) const;
83 virtual ~Algorithm( );
85 /// itk::ProcessObject
86 virtual void GenerateData( );
89 virtual void _BeforeLoop ( );
90 virtual void _AfterLoop ( );
91 virtual void _Loop ( );
92 virtual bool _CheckCollisions ( const _TNode& a, const _TNode& b );
93 virtual bool _CheckStopCondition ( );
94 virtual bool _UpdateResult ( _TNode& n );
97 virtual void _InitializeMarks ( );
98 virtual bool _IsMarked ( const TVertex& v ) const;
99 virtual _TFrontId _FrontId ( const TVertex& v ) const;
100 virtual TVertex _Parent ( const TVertex& v ) const;
101 virtual void _Mark ( const _TNode& n );
103 /// Pure virtual interface: vertices
104 virtual unsigned long _NumberOfVertices ( ) const = 0;
105 virtual TVertexValue _Value ( const TVertex& v ) const = 0;
106 virtual TResult _Result ( const TVertex& v ) const = 0;
108 /// Pure virtual interface: edges
109 virtual double _Norm ( const TVertex& a, const TVertex& b ) const = 0;
110 virtual bool _Edge ( const TVertex& a, const TVertex& b ) const = 0;
111 virtual TCost _Cost ( const TVertex& a, const TVertex& b ) const = 0;
113 /// Pure virtual interface: neighborhood
114 virtual void _Neighs ( const _TNode& n, _TNodes& N ) const = 0;
115 virtual bool _UpdateNeigh ( _TNode& nn, const _TNode& n ) = 0;
116 virtual void _NeighsInDim ( const _TNode& n,
117 const unsigned int& d,
120 /// Pure virtual interface: queue
121 virtual void _InitializeQueue ( ) = 0;
122 virtual bool _IsQueueEmpty ( ) const = 0;
123 virtual void _QueuePush ( const _TNode& n ) = 0;
124 virtual _TNode _QueuePop ( ) = 0;
125 virtual void _QueueClear ( ) = 0;
127 /// Pure virtual interface: results
128 virtual void _InitializeResults ( ) = 0;
131 // Purposely not implemented
132 Algorithm( const Self& );
133 void operator=( const Self& );
136 bool m_StopAtOneFront;
142 _TCollisionSites m_CollisionSites;
149 #include <fpa/Base/Algorithm.hxx>
151 #endif // __FPA__BASE__ALGORITHM__H__