]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/Base/Dijkstra.h
...
[FrontAlgorithms.git] / lib / fpa / Base / Dijkstra.h
index 69fe86a798289509fb31557b6927c90dbbd64466..08c704e83b9b7d019eafd6904be1b68158d8e771 100644 (file)
-#ifndef __FPA__BASE__DIJKSTRA__H__
-#define __FPA__BASE__DIJKSTRA__H__
+#ifndef __fpa__Base__Dijkstra__h__
+#define __fpa__Base__Dijkstra__h__
 
-#include <vector>
-#include <fpa/Base/Algorithm.h>
+#include <fpa/Base/PriorityQueueAlgorithm.h>
 
 namespace fpa
 {
   namespace Base
   {
     /**
-     * Dijkstra is a front propagation algorithm that minimizes costs
-     *
-     * @param V  Vertex type.
-     * @param C  Vertex value type.
-     * @param R  Result value type.
-     * @param S  Space type where vertices are.
-     * @param VC Vertex lexicographical compare.
-     * @param B  Base class for this algorithm. It should be any itk-based
-     *           filter (itk::ProcessObject).
-     *
      */
-    template< class V, class C, class R, class S, class VC, class B >
+    template< class _TSuperclass, class _TMST >
     class Dijkstra
-      : public Algorithm< V, C, R, S, VC, B >
+      : public fpa::Base::PriorityQueueAlgorithm< _TSuperclass >
     {
     public:
-      typedef Dijkstra                         Self;
-      typedef Algorithm< V, C, R, S, VC, B >   Superclass;
-      typedef itk::SmartPointer< Self >        Pointer;
-      typedef itk::SmartPointer< const Self >  ConstPointer;
-
-      typedef typename Superclass::TVertex              TVertex;
-      typedef typename Superclass::TValue               TValue;
-      typedef typename Superclass::TResult              TResult;
-      typedef typename Superclass::TSpace               TSpace;
-      typedef typename Superclass::TVertexCompare       TVertexCompare;
-      typedef typename Superclass::TMinimumSpanningTree TMinimumSpanningTree;
-
-      typedef typename Superclass::TStartEvent     TStartEvent;
-      typedef typename Superclass::TStartLoopEvent TStartLoopEvent;
-      typedef typename Superclass::TEndEvent       TEndEvent;
-      typedef typename Superclass::TEndLoopEvent   TEndLoopEvent;
-      typedef typename Superclass::TAliveEvent     TAliveEvent;
-      typedef typename Superclass::TFrontEvent     TFrontEvent;
-      typedef typename Superclass::TFreezeEvent    TFreezeEvent;
-
-      typedef typename Superclass::TStartBacktrackingEvent TStartBacktrackingEvent;
-      typedef typename Superclass::TEndBacktrackingEvent TEndBacktrackingEvent;
-      typedef typename Superclass::TBacktrackingEvent TBacktrackingEvent;
+      typedef Dijkstra                                          Self;
+      typedef fpa::Base::PriorityQueueAlgorithm< _TSuperclass > Superclass;
+      typedef itk::SmartPointer< Self >                         Pointer;
+      typedef itk::SmartPointer< const Self >                   ConstPointer;
+
+      typedef _TMST TMST;
+      typedef typename Superclass::TOutput TOutput;
+      typedef typename Superclass::TVertex TVertex;
 
     protected:
-      typedef typename Superclass::_TVertices      _TVertices;
-      typedef typename Superclass::_TCollision     _TCollision;
-      typedef typename Superclass::_TCollisionsRow _TCollisionsRow;
-      typedef typename Superclass::_TCollisions    _TCollisions;
-      typedef typename Superclass::_TNode          _TNode;
-      typedef typename Superclass::_TNodes         _TNodes;
-
-      struct _TQueueNode
-      {
-        TVertex Vertex;
-        _TNode  Node;
-
-        // Make the min-heap behave as a max-heap
-        bool operator<( const _TQueueNode& other ) const
-          { return( other.Node.Result < this->Node.Result ); }
-      };
-      typedef std::vector< _TQueueNode > _TQueue;
+      typedef typename Superclass::_TQueueNode _TQueueNode;
 
     public:
       itkTypeMacro( Dijkstra, Algorithm );
 
-      itkBooleanMacro( LocalCosts );
-      itkGetConstMacro( LocalCosts, bool );
-      itkSetMacro( LocalCosts, bool );
+    public:
+      _TMST* GetMinimumSpanningTree( );
+      const _TMST* GetMinimumSpanningTree( ) const;
 
     protected:
       Dijkstra( );
       virtual ~Dijkstra( );
 
-      virtual TResult _Cost( const TVertex& v, const TVertex& p ) const = 0;
-
-      // Results-related abstract methods
-      virtual bool _ComputeNeighborResult(
-        TResult& result, const TVertex& neighbor, const TVertex& parent
-        ) const;
+      virtual void _AfterGenerateData( ) override;
 
-      // Queue-related abstract methods
-      virtual bool _IsQueueEmpty( ) const;
-      virtual void _QueuePush( const TVertex& v, const _TNode& n );
-      virtual void _QueuePop( TVertex& v, _TNode& n );
-      virtual void _QueueClear( );
+      virtual void _UpdateResult( const _TQueueNode& n ) override;
+      virtual bool _UpdateValue(
+        _TQueueNode& v, const _TQueueNode& p
+        ) override;
 
     private:
-      // Purposely not implemented
+      // Purposely not defined
       Dijkstra( const Self& other );
       Self& operator=( const Self& other );
 
     protected:
-      bool m_LocalCosts;
-      _TQueue m_Queue;
+      unsigned long m_MSTIndex;
     };
 
   } // ecapseman
 
 } // ecapseman
 
-#include <fpa/Base/Dijkstra.hxx>
+#ifndef ITK_MANUAL_INSTANTIATION
+#  include <fpa/Base/Dijkstra.hxx>
+#endif // ITK_MANUAL_INSTANTIATION
 
-#endif // __FPA__BASE__DIJKSTRA__H__
+#endif // __fpa__Base__Dijkstra__h__
 
 // eof - $RCSfile$