]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/Base/Algorithm.h
Almost there...
[FrontAlgorithms.git] / lib / fpa / Base / Algorithm.h
index 35c6a378d09d3ede36655be646d39abfa616659b..cc8497d558354409c7389626f36daebd3eeb8710 100644 (file)
@@ -1,9 +1,11 @@
 #ifndef __FPA__BASE__ALGORITHM__H__
 #define __FPA__BASE__ALGORITHM__H__
 
+#include <map>
 #include <utility>
 #include <vector>
 #include <fpa/Base/Events.h>
+#include <fpa/Base/MinimumSpanningTree.h>
 
 namespace fpa
 {
@@ -15,14 +17,15 @@ namespace fpa
      * vertex could be marked as "visited", "in the front", "not yet there"
      * or "freezed".
      *
-     * @param V Vertex type.
-     * @param C Vertex value type.
-     * @param R Result value type.
-     * @param B Base class for this algorithm. It should be any itk-based
-     *          filter (itk::ProcessObject).
+     * @param V  Vertex type.
+     * @param C  Vertex value type.
+     * @param R  Result value type.
+     * @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 B >
+    template< class V, class C, class R, class VC, class B >
     class Algorithm
       : public B
     {
@@ -32,17 +35,21 @@ namespace fpa
       typedef itk::SmartPointer< Self >       Pointer;
       typedef itk::SmartPointer< const Self > ConstPointer;
 
-      typedef V TVertex;
-      typedef C TValue;
-      typedef R TResult;
+      typedef V  TVertex;
+      typedef C  TValue;
+      typedef R  TResult;
+      typedef VC TVertexCompare;
 
       fpa_Base_NewEvent( TStartEvent );
       fpa_Base_NewEvent( TStartLoopEvent );
+      fpa_Base_NewEvent( TStartBacktrackingEvent );
       fpa_Base_NewEvent( TEndEvent );
       fpa_Base_NewEvent( TEndLoopEvent );
+      fpa_Base_NewEvent( TEndBacktrackingEvent );
       fpa_Base_NewEventWithVertex( TAliveEvent, TVertex );
       fpa_Base_NewEventWithVertex( TFrontEvent, TVertex );
       fpa_Base_NewEventWithVertex( TFreezeEvent, TVertex );
+      fpa_Base_NewEventWithVertex( TBacktrackingEvent, TVertex );
 
     protected:
       typedef std::vector< TVertex >         _TVertices;
@@ -68,13 +75,15 @@ namespace fpa
         virtual ~_TNode( );
 
       public:
-        TVertex     Vertex;
-        TVertex     Parent;
-        TResult     Result;
-        long        FrontId;
-        _TNodeLabel Label;
+        TVertex Parent;
+        TResult Result;
+        short   FrontId;
+        char    Label;
       };
-      typedef std::vector< _TNode > _TNodes;
+      typedef std::map< TVertex, _TNode, TVertexCompare > _TNodes;
+
+    public:
+      typedef fpa::Base::MinimumSpanningTree< TVertex, _TCollisions, TVertexCompare > TMinimumSpanningTree;
 
     public:
       itkTypeMacro( Algorithm, B );
@@ -89,6 +98,10 @@ namespace fpa
       itkSetMacro( StopAtOneFront, bool );
 
     public:
+      TMinimumSpanningTree* GetMinimumSpanningTree( );
+      const TMinimumSpanningTree* GetMinimumSpanningTree( ) const;
+      void GraftMinimumSpanningTree( itk::DataObject* obj );
+
       virtual void InvokeEvent( const itk::EventObject& e );
       virtual void InvokeEvent( const itk::EventObject& e ) const;
 
@@ -134,18 +147,19 @@ namespace fpa
         ) const = 0;
       virtual void _InitResults( ) = 0;
       virtual const TResult& _Result( const TVertex& v ) const = 0;
-      virtual void _SetResult( const TVertex& v, const TResult& r ) = 0;
+      virtual void _SetResult( const TVertex& v, const _TNode& n ) = 0;
 
       // Marks-related abstract methods
-      virtual const _TNode& _Node( const TVertex& v ) const = 0;
-      virtual void _InitMarks( ) = 0;
-      virtual void _Mark( const _TNode& node ) = 0;
+      virtual _TNode& _Node( const TVertex& v );
+      virtual const _TNode& _Node( const TVertex& v ) const;
+      virtual void _InitMarks( );
+      virtual void _Mark( const TVertex& v, const _TNode& node );
 
       // Queue-related abstract methods
       virtual void _InitQueue( );
       virtual bool _IsQueueEmpty( ) const = 0;
-      virtual void _QueuePush( const _TNode& n ) = 0;
-      virtual _TNode _QueuePop( ) = 0;
+      virtual void _QueuePush( const TVertex& v, const _TNode& n ) = 0;
+      virtual void _QueuePop( TVertex& v, _TNode& n ) = 0;
       virtual void _QueueClear( ) = 0;
 
     private:
@@ -157,7 +171,11 @@ namespace fpa
       bool         m_ThrowEvents;
       bool         m_StopAtOneFront;
       _TNodes      m_Seeds;
+      _TVertices   m_SeedVertices;
+      _TNodes      m_Marks;
       _TCollisions m_Collisions;
+
+      unsigned int m_MinimumSpanningTreeIndex;
     };
 
   } // ecapseman