]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Base/Dijkstra.h
Almost there...
[FrontAlgorithms.git] / lib / fpa / Base / Dijkstra.h
1 #ifndef __FPA__BASE__DIJKSTRA__H__
2 #define __FPA__BASE__DIJKSTRA__H__
3
4 #include <vector>
5 #include <fpa/Base/Algorithm.h>
6
7 namespace fpa
8 {
9   namespace Base
10   {
11     /**
12      * Dijkstra is a front propagation algorithm that minimizes costs
13      *
14      * @param V  Vertex type.
15      * @param C  Vertex value type.
16      * @param R  Result value type.
17      * @param VC Vertex lexicographical compare.
18      * @param B  Base class for this algorithm. It should be any itk-based
19      *           filter (itk::ProcessObject).
20      *
21      */
22     template< class V, class C, class R, class VC, class B >
23     class Dijkstra
24       : public Algorithm< V, C, R, VC, B >
25     {
26     public:
27       typedef Dijkstra                         Self;
28       typedef Algorithm< V, C, R, VC, B >      Superclass;
29       typedef itk::SmartPointer< Self >        Pointer;
30       typedef itk::SmartPointer< const Self >  ConstPointer;
31
32       typedef typename Superclass::TVertex        TVertex;
33       typedef typename Superclass::TValue         TValue;
34       typedef typename Superclass::TResult        TResult;
35       typedef typename Superclass::TVertexCompare TVertexCompare;
36
37       typedef typename Superclass::TStartEvent     TStartEvent;
38       typedef typename Superclass::TStartLoopEvent TStartLoopEvent;
39       typedef typename Superclass::TEndEvent       TEndEvent;
40       typedef typename Superclass::TEndLoopEvent   TEndLoopEvent;
41       typedef typename Superclass::TAliveEvent     TAliveEvent;
42       typedef typename Superclass::TFrontEvent     TFrontEvent;
43       typedef typename Superclass::TFreezeEvent    TFreezeEvent;
44
45       typedef typename Superclass::TStartBacktrackingEvent TStartBacktrackingEvent;
46       typedef typename Superclass::TEndBacktrackingEvent TEndBacktrackingEvent;
47       typedef typename Superclass::TBacktrackingEvent TBacktrackingEvent;
48
49     protected:
50       typedef typename Superclass::_TVertices      _TVertices;
51       typedef typename Superclass::_TCollision     _TCollision;
52       typedef typename Superclass::_TCollisionsRow _TCollisionsRow;
53       typedef typename Superclass::_TCollisions    _TCollisions;
54       typedef typename Superclass::_TNode          _TNode;
55       typedef typename Superclass::_TNodes         _TNodes;
56
57       struct _TQueueNode
58       {
59         TVertex Vertex;
60         _TNode  Node;
61
62         // Make the min-heap behave as a max-heap
63         bool operator<( const _TQueueNode& other ) const
64           { return( other.Node.Result < this->Node.Result ); }
65       };
66       typedef std::vector< _TQueueNode > _TQueue;
67
68     public:
69       itkTypeMacro( Dijkstra, Algorithm );
70
71     protected:
72       Dijkstra( );
73       virtual ~Dijkstra( );
74
75       virtual TResult _Cost( const TVertex& v, const TVertex& p ) const = 0;
76
77       // Results-related abstract methods
78       virtual bool _ComputeNeighborResult(
79         TResult& result, const TVertex& neighbor, const TVertex& parent
80         ) const;
81
82       // Queue-related abstract methods
83       virtual bool _IsQueueEmpty( ) const;
84       virtual void _QueuePush( const TVertex& v, const _TNode& n );
85       virtual void _QueuePop( TVertex& v, _TNode& n );
86       virtual void _QueueClear( );
87
88     private:
89       // Purposely not implemented
90       Dijkstra( const Self& other );
91       Self& operator=( const Self& other );
92
93     protected:
94       _TQueue m_Queue;
95     };
96
97   } // ecapseman
98
99 } // ecapseman
100
101 #include <fpa/Base/Dijkstra.hxx>
102
103 #endif // __FPA__BASE__DIJKSTRA__H__
104
105 // eof - $RCSfile$