]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/Base/RegionGrow.h
Major refactoring
[FrontAlgorithms.git] / lib / fpa / Base / RegionGrow.h
index f7f15625415ae6ef3772b71748e113782e6423fe..6028b754622fb5f91c9413cf92b79cca0da7a9bc 100644 (file)
 #define __FPA__BASE__REGIONGROW__H__
 
 #include <queue>
-#include <vector>
 #include <fpa/Base/Algorithm.h>
 
 namespace fpa
 {
   namespace Base
   {
-    /**
-     */
-    template< class V, class R, class VV, class VC >
-    class RegionGrowTraits
-    {
-    public:
-      typedef R  TResult;
-      typedef V  TVertex;
-      typedef VV TVertexValue;
-      typedef VC TVertexCmp;
-
-      typedef bool TCost;
-      typedef long TFrontId;
-
-      class TNode
-      {
-      public:
-        TNode( )
-          { }
-        TNode( const TVertex& v, const TFrontId& f )
-          : Vertex( v ),
-            Parent( v ),
-            FrontId( f )
-          { }
-        TNode( const TVertex& v, const TResult& r, const TFrontId& f )
-          : Vertex( v ),
-            Parent( v ),
-            Result( r ),
-            FrontId( f )
-          { }
-        virtual ~TNode( )
-          { }
-
-        TVertex Vertex;
-        TVertex Parent;
-        TResult Result;
-        TFrontId FrontId;
-      };
-
-      typedef std::vector< TNode > TNodes;
-    };
-
     /**
      * Region grow is a front propagation with no costs.
+     *
+     * @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).
+     *
      */
-    template< class V, class R, class VV, class VC, class B >
+    template< class V, class C, class R, class B >
     class RegionGrow
-      : public Algorithm< RegionGrowTraits< V, R, VV, VC >, B >
+      : public Algorithm< V, C, R, B >
     {
     public:
-      typedef V  TVertex;
-      typedef R  TResult;
-      typedef VV TVertexValue;
-      typedef B  TBaseFilter;
-
-      /// Standard class typdedefs
-      typedef RegionGrowTraits< V, R, VV, VC > TTraits;
       typedef RegionGrow                       Self;
-      typedef Algorithm< TTraits, B >          Superclass;
+      typedef Algorithm< V, C, R, B >          Superclass;
       typedef itk::SmartPointer< Self >        Pointer;
       typedef itk::SmartPointer< const Self >  ConstPointer;
 
-      typedef typename TTraits::TCost TCost;
+      typedef typename Superclass::TVertex TVertex;
+      typedef typename Superclass::TValue  TValue;
+      typedef typename Superclass::TResult TResult;
 
     protected:
-      typedef typename TTraits::TFrontId  _TFrontId;
-      typedef typename TTraits::TNode     _TNode;
-      typedef typename TTraits::TNodes    _TNodes;
-      typedef std::queue< _TNode >        _TQueue;
+      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;
+
+      typedef std::queue< _TNode > _TQueue;
 
     public:
       itkTypeMacro( RegionGrow, Algorithm );
 
+      itkGetConstMacro( InsideValue, TResult );
+      itkGetConstMacro( OutsideValue, TResult );
+
+      itkSetMacro( InsideValue, TResult );
+      itkSetMacro( OutsideValue, TResult );
+
     protected:
       RegionGrow( );
       virtual ~RegionGrow( );
 
-      virtual   bool _UpdateResult    ( _TNode& n );
-      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 bool _CheckMembership( const TVertex& v ) const = 0;
+
+      // Results-related abstract methods
+      virtual bool _ComputeNeighborResult(
+        TResult& result, const TVertex& neighbor, const TVertex& parent
+        ) const;
 
-      virtual bool _CheckMembership( const _TNode& n ) const = 0;
+      // Queue-related abstract methods
+      virtual bool _IsQueueEmpty( ) const;
+      virtual void _QueuePush( const _TNode& n );
+      virtual _TNode _QueuePop( );
+      virtual void _QueueClear( );
 
     private:
-      RegionGrow( const Self& );     // Not impl.
-      void operator=( const Self& ); // Not impl.
+      // Purposely not implemented
+      RegionGrow( const Self& other );
+      Self& operator=( const Self& other );
 
     protected:
+      TResult m_InsideValue;
+      TResult m_OutsideValue;
       _TQueue m_Queue;
     };