]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Base/Dijkstra.h
3831526a553e5a85bd4c9ccd77d9367e0a735b07
[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 B Base class for this algorithm. It should be any itk-based
18      *          filter (itk::ProcessObject).
19      *
20      */
21     template< class V, class C, class R, class B >
22     class Dijkstra
23       : public Algorithm< V, C, R, B >
24     {
25     public:
26       typedef Dijkstra                         Self;
27       typedef Algorithm< V, C, R, B >          Superclass;
28       typedef itk::SmartPointer< Self >        Pointer;
29       typedef itk::SmartPointer< const Self >  ConstPointer;
30
31       typedef typename Superclass::TVertex TVertex;
32       typedef typename Superclass::TValue  TValue;
33       typedef typename Superclass::TResult TResult;
34
35     protected:
36       typedef typename Superclass::_TVertices      _TVertices;
37       typedef typename Superclass::_TCollision     _TCollision;
38       typedef typename Superclass::_TCollisionsRow _TCollisionsRow;
39       typedef typename Superclass::_TCollisions    _TCollisions;
40       typedef typename Superclass::_TNode          _TNode;
41       typedef typename Superclass::_TNodes         _TNodes;
42
43       typedef std::vector< _TNode > _TQueue;
44       struct _TNodeCompare
45       {
46         // Make the min-heap behave as a max-heap
47         bool operator()( const _TNode& a, const _TNode& b ) const
48           { return( b.Result < a.Result ); }
49       };
50
51     public:
52       itkTypeMacro( Dijkstra, Algorithm );
53
54     protected:
55       Dijkstra( );
56       virtual ~Dijkstra( );
57
58       virtual TResult _Cost( const TVertex& v, const TVertex& p ) const = 0;
59
60       // Results-related abstract methods
61       virtual bool _ComputeNeighborResult(
62         TResult& result, const TVertex& neighbor, const TVertex& parent
63         ) const;
64
65       // Queue-related abstract methods
66       virtual bool _IsQueueEmpty( ) const;
67       virtual void _QueuePush( const _TNode& n );
68       virtual _TNode _QueuePop( );
69       virtual void _QueueClear( );
70
71     private:
72       // Purposely not implemented
73       Dijkstra( const Self& other );
74       Self& operator=( const Self& other );
75
76     protected:
77       _TQueue m_Queue;
78       static _TNodeCompare m_NodeCompare;
79     };
80
81   } // ecapseman
82
83 } // ecapseman
84
85 #include <fpa/Base/Dijkstra.hxx>
86
87 #endif // __FPA__BASE__DIJKSTRA__H__
88
89 // eof - $RCSfile$