]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/Base/Dijkstra.h
...
[FrontAlgorithms.git] / lib / fpa / Base / Dijkstra.h
index a6212cf9b770fe178605f0d241fdfd3430dfd0d6..d231c7c41da897886b69c63d97f0fca117908646 100644 (file)
@@ -1,8 +1,14 @@
-#ifndef __FPA__BASE__DIJKSTRA__H__
-#define __FPA__BASE__DIJKSTRA__H__
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
 
-#include <vector>
-#include <fpa/Base/Algorithm.h>
+#ifndef __fpa__Base__Dijkstra__h__
+#define __fpa__Base__Dijkstra__h__
+
+#include <itkFunctionBase.h>
+#include <fpa/Base/MinimumSpanningTree.h>
+#include <fpa/Base/Functors/VertexParentBase.h>
 
 namespace fpa
 {
@@ -10,111 +16,86 @@ 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 _TFilter, class _TMarksInterface, class _TSeedsInterface, class _TMST >
     class Dijkstra
-      : public Algorithm< DijkstraTraits< V, C, VV, VC >, B >
+      : public _TFilter,
+        public _TMarksInterface,
+        public _TSeedsInterface
     {
     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 _TFilter                        Superclass;
+      typedef _TMarksInterface                TMarksInterface;
+      typedef _TSeedsInterface                TSeedsInterface;
+      typedef _TMST                           TMST;
       typedef itk::SmartPointer< Self >       Pointer;
       typedef itk::SmartPointer< const Self > ConstPointer;
 
+      typedef typename Superclass::TInputValue  TInputValue;
+      typedef typename Superclass::TOutputValue TOutputValue;
+      typedef typename Superclass::TVertex      TVertex;
+      typedef typename Superclass::TVertices    TVertices;
+
+      typedef itk::FunctionBase< TInputValue, TOutputValue > TIntensityFunctor;
+      typedef fpa::Base::Functors::VertexParentBase< TVertex, TOutputValue > TVertexFunctor;
+
     protected:
-      typedef typename TTraits::TFrontId  _TFrontId;
-      typedef typename TTraits::TNode     _TNode;
-      typedef typename TTraits::TNodes    _TNodes;
+      struct _TNode
+      {
+        TVertex Vertex;
+        TVertex Parent;
+        TOutputValue Cost;
+        unsigned long FrontId;
+        _TNode( const TVertex& v, const TVertex& p, const unsigned long& fId )
+          {
+            this->Vertex = v;
+            this->Parent = p;
+            this->FrontId = fId;
+            this->Cost = TOutputValue( 0 );
+          }
+        bool operator<( const _TNode& b ) const
+          {
+            return( b.Cost < this->Cost );
+          }
+      };
 
-      typedef std::vector< _TNode > _TQueue;
+    public:
+      itkTypeMacro( Dijkstra, TFilter );
 
     public:
-      itkTypeMacro( Dijkstra, Base );
+      TMST* GetMinimumSpanningTree( );
+      const TMST* GetMinimumSpanningTree( ) const;
+
+      const TIntensityFunctor* GetIntensityFunctor( ) const;
+      const TVertexFunctor* GetVertexFunctor( ) const;
+
+      void SetFunctor( TIntensityFunctor* functor );
+      void SetFunctor( TVertexFunctor* functor );
 
     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 GenerateData( ) override;
 
     private:
-      // Purposely not implemented
-      Dijkstra( const Self& );
-      void operator=( const Self& );
+      Dijkstra( const Self& other );
+      Self& operator=( const Self& other );
 
-    private:
-      _TQueue m_Queue;
+    protected:
+      typename TIntensityFunctor::Pointer m_IntensityFunctor;
+      typename TVertexFunctor::Pointer m_VertexFunctor;
+      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$