]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/Base/Dijkstra.h
...
[FrontAlgorithms.git] / lib / fpa / Base / Dijkstra.h
index a6212cf9b770fe178605f0d241fdfd3430dfd0d6..aa62f90bbe2dcd07eae54fd684c306d277f95c57 100644 (file)
@@ -1,8 +1,10 @@
-#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/Config.h>
+#include <itkFunctionBase.h>
+#include <fpa/Base/DijkstraCostFunctionBase.h>
 
 namespace fpa
 {
@@ -10,111 +12,82 @@ namespace fpa
   {
     /**
      */
-    template< class V, class C, class VV, class VC >
-    class DijkstraTraits
-    {
-    public:
-      typedef V TVertex;
-      typedef C TResult;
-      typedef C TCost;
-      typedef VV TVertexValue;
-      typedef VC TVertexCmp;
-      typedef long TFrontId;
-
-      class TNode
-      {
-      public:
-        TNode( )
-          : Cost( 0 )
-          { }
-        TNode( const TVertex& v, const TFrontId& f )
-          : Vertex( v ),
-            Parent( v ),
-            Result( TResult( 0 ) ),
-            FrontId( f ),
-            Cost( TCost( 0 ) )
-          { }
-        TNode( const TVertex& v, const TResult& r, const TFrontId& f )
-          : Vertex( v ),
-            Parent( v ),
-            Result( r ),
-            FrontId( f ),
-            Cost( TCost( 0 ) )
-          { }
-        virtual ~TNode( )
-          { }
-
-        // NOTE: stl::heaps work as maximum priority queues
-        bool operator<( const TNode& other ) const
-          { return( other.Cost < this->Cost ); }
-
-        TVertex Vertex;
-        TVertex Parent;
-        TResult Result;
-        TFrontId FrontId;
-        TCost Cost;
-      };
-
-      typedef std::vector< TNode > TNodes;
-    };
-
-    /**
-     * Dijkstra is a front propagation algorithm that minimizes costs
-     */
-    template< class V, class C, class VV, class VC, class B >
+    template< class _TSuperclass, class _TMST >
     class Dijkstra
-      : public Algorithm< DijkstraTraits< V, C, VV, VC >, B >
+      : public _TSuperclass
     {
     public:
-      // Templated types
-      typedef V TVertex;
-      typedef C TCost;
-      typedef VV TVertexValue;
-      typedef B  TBaseFilter;
-      typedef DijkstraTraits< V, C, VV, VC > TTraits;
-
-      // Standard class typdedefs
       typedef Dijkstra                        Self;
-      typedef Algorithm< TTraits, B >         Superclass;
+      typedef _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;
+
+      typedef itk::FunctionBase< TOutput, TOutput > TCostConversionFunction;
+      typedef DijkstraCostFunctionBase< TVertex, TOutput > TCostFunction;
+
     protected:
-      typedef typename TTraits::TFrontId  _TFrontId;
-      typedef typename TTraits::TNode     _TNode;
-      typedef typename TTraits::TNodes    _TNodes;
+      typedef typename Superclass::_TQueueNode _TQueueNode;
+      struct _TQueueNodeCompare
+      {
+        bool operator( )( const _TQueueNode& a, const _TQueueNode& b )
+          {
+            return( b.Result < a.Result );
+          }
+      };
+      typedef std::vector< _TQueueNode > _TQueue;
+
+    public:
+      itkTypeMacro( Dijkstra, Algorithm );
 
-      typedef std::vector< _TNode > _TQueue;
+      itkGetObjectMacro( CostFunction, TCostFunction );
+      itkGetObjectMacro( CostConversionFunction, TCostConversionFunction );
+      itkSetObjectMacro( CostFunction, TCostFunction );
+      itkSetObjectMacro( CostConversionFunction, TCostConversionFunction );
 
     public:
-      itkTypeMacro( Dijkstra, Base );
+      _TMST* GetMinimumSpanningTree( );
+      const _TMST* GetMinimumSpanningTree( ) const;
 
     protected:
       Dijkstra( );
       virtual ~Dijkstra( );
 
-      virtual   void _InitializeQueue ( );
-      virtual   bool _IsQueueEmpty    ( ) const;
-      virtual   void _QueuePush       ( const _TNode& n );
-      virtual _TNode _QueuePop        ( );
-      virtual   void _QueueClear      ( );
-      virtual   bool _UpdateNeigh     ( _TNode& nn, const _TNode& n );
+      virtual void _AfterGenerateData( ) override;
 
-    private:
-      // Purposely not implemented
-      Dijkstra( const Self& );
-      void operator=( const Self& );
+      virtual void _UpdateResult( const _TQueueNode& n ) override;
+      virtual bool _UpdateValue(
+        _TQueueNode& v, const _TQueueNode& p
+        ) override;
+      virtual unsigned long _QueueSize( ) const override;
+      virtual void _QueueClear( ) override;
+      virtual void _QueuePush( const _TQueueNode& node ) override;
+      virtual _TQueueNode _QueuePop( ) override;
 
     private:
+      // Purposely not defined
+      Dijkstra( const Self& other );
+      Self& operator=( const Self& other );
+
+    protected:
       _TQueue m_Queue;
+      typename TCostFunction::Pointer m_CostFunction;
+      typename TCostConversionFunction::Pointer m_CostConversionFunction;
+
+      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$