1 #ifndef __FPA__BASE__ALGORITHM__H__
2 #define __FPA__BASE__ALGORITHM__H__
8 #include <fpa/Config.h>
9 #include <fpa/Base/Events.h>
16 * Base front propagation algorithm. From a series of start seeds with
17 * costs, a priority queue is filled and emptied updating costs. Each
18 * vertex could be marked as "visited", "in the front", "not yet there"
21 * @param _TVertex Vertex type.
22 * @param _TScalar Scalar (real computations) type.
23 * @param _TFilter Base class for this algorithm. It should be any
24 * itk-based filter (itk::ProcessObject).
25 * @param _TVertexCompare Vertex lexicographical compare.
28 template< class _TVertex, class _TScalar, class _TFilter, class _TVertexCompare = std::less< _TVertex > >
33 typedef Algorithm Self;
34 typedef _TFilter Superclass;
35 typedef itk::SmartPointer< Self > Pointer;
36 typedef itk::SmartPointer< const Self > ConstPointer;
39 typedef _TVertex TVertex;
40 typedef _TScalar TScalar;
41 typedef _TFilter TFilter;
42 typedef _TVertexCompare TVertexCompare;
45 typedef unsigned long TFrontId;
47 // Minigraph to represent collisions
48 typedef std::pair< TVertex, bool > TCollision;
49 typedef std::vector< TCollision > TCollisionsRow;
50 typedef std::vector< TCollisionsRow > TCollisions;
60 * WARNING: std::set< T > objects are immutable
64 static const TVertexCompare VertexCompare;
66 mutable TVertex Parent;
67 mutable TScalar Result;
68 mutable TFrontId FrontId;
69 mutable TNodeLabel Label;
70 bool operator<( const TNode& other ) const
71 { return( VertexCompare( this->Vertex, other.Vertex ) ); }
73 typedef std::set< TNode > TNodes;
74 typedef std::vector< TVertex > TVertices;
77 itkTypeMacro( Algorithm, _TFilter );
79 itkBooleanMacro( StopAtOneFront );
80 itkGetConstMacro( StopAtOneFront, bool );
81 itkSetMacro( StopAtOneFront, bool );
83 itkBooleanMacro( ThrowEvents );
84 itkGetConstMacro( ThrowEvents, bool );
85 itkSetMacro( ThrowEvents, bool );
87 fpa_Base_NewEvent( TStartEvent );
88 fpa_Base_NewEvent( TStartLoopEvent );
89 fpa_Base_NewEvent( TStartBacktrackingEvent );
90 fpa_Base_NewEvent( TEndEvent );
91 fpa_Base_NewEvent( TEndLoopEvent );
92 fpa_Base_NewEvent( TEndBacktrackingEvent );
93 fpa_Base_NewEventWithVertex( TCollisionEvent, TVertex );
94 fpa_Base_NewEventWithVertex( TAliveEvent, TVertex );
95 fpa_Base_NewEventWithVertex( TFrontEvent, TVertex );
96 fpa_Base_NewEventWithVertex( TFreezeEvent, TVertex );
97 fpa_Base_NewEventWithVertex( TBacktrackingEvent, TVertex );
100 virtual void InvokeEvent( const itk::EventObject& e );
101 virtual void InvokeEvent( const itk::EventObject& e ) const;
103 unsigned long GetNumberOfSeeds( ) const;
104 void AddSeed( const TVertex& s, const TScalar& v = TScalar( 0 ) );
105 void AddSeed( const TNode& n );
106 void RemoveSeed( const TVertex& s );
107 void RemoveAllSeeds( );
110 // Methods to extend itk-based architecture
112 virtual ~Algorithm( );
113 virtual void GenerateData( ) fpa_OVERRIDE;
115 // Front propagation generic methods
116 virtual void _Loop( );
118 // Front propagation methods to be overloaded
119 virtual void _BeforeGenerateData( );
120 virtual void _AfterGenerateData( );
121 virtual void _BeforeLoop( );
122 virtual void _AfterLoop( );
124 virtual void _InitMarks( ) = 0;
125 virtual void _InitResults( ) = 0;
126 virtual void _DeallocateAuxiliary( ) = 0;
128 virtual TFrontId _GetMark( const TVertex& v ) = 0;
129 virtual TFrontId _GetMark( const TNode& v );
131 virtual void _Visit( const TNode& n ) = 0;
132 virtual bool _NeedToStop( );
134 virtual TVertices _GetNeighborhood( const TVertex& v ) const = 0;
135 virtual TVertices _GetNeighborhood( const TNode& n ) const;
137 virtual bool _Result( TNode& node, const TNode& parent ) = 0;
139 virtual void _QueueClear( ) = 0;
140 virtual void _QueuePush( const TNode& node ) = 0;
141 virtual TNode _QueuePop( ) = 0;
142 virtual bool _IsQueueEmpty( ) const = 0;
144 virtual bool _UpdateCollisions( const TVertex& a, const TVertex& b );
147 // Purposely not implemented
148 Algorithm( const Self& other );
149 Self& operator=( const Self& other );
153 TCollisions m_Collisions;
154 bool m_StopAtOneFront;
162 #ifndef ITK_MANUAL_INSTANTIATION
163 # include <fpa/Base/Algorithm.hxx>
166 #endif // __FPA__BASE__ALGORITHM__H__