]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/Base/RegionGrow.h
...
[FrontAlgorithms.git] / lib / fpa / Base / RegionGrow.h
index e52fb6203c0e256624d8a010819ddc154b323cb7..8bc2776420f6a59d17dfa207d59bd2cb351b4829 100644 (file)
 #define __FPA__BASE__REGIONGROW__H__
 
 #include <queue>
-#include <vector>
+#include <utility>
 #include <fpa/Base/Algorithm.h>
+#include <fpa/Base/Functors/TautologyFunction.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 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 R, class VV, class VC, class B >
+    template< class V, class C, class R, class S, class VC, class B >
     class RegionGrow
-      : public Algorithm< RegionGrowTraits< V, R, VV, VC >, B >
+      : public Algorithm< V, C, R, S, VC, 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, S, VC, 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;
+      typedef typename Superclass::TSpace         TSpace;
+      typedef typename Superclass::TVertexCompare TVertexCompare;
+
+      typedef fpa::Base::Functors::TautologyFunction< S, V > TGrowingFunction;
 
     protected:
-      typedef typename TTraits::TFrontId  _TFrontId;
-      typedef typename TTraits::TNode     _TNode;
-      typedef typename TTraits::TNodes    _TNodes;
+      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;
 
-    private:
-      typedef std::queue< _TNode > _TQueue;
+      typedef std::queue< std::pair< TVertex, _TNode > > _TQueue;
 
     public:
-      itkTypeMacro( RegionGrow, Base );
+      itkTypeMacro( RegionGrow, Algorithm );
+
+      itkGetConstMacro( InsideValue, TResult );
+      itkGetConstMacro( OutsideValue, TResult );
+      itkGetObjectMacro( GrowingFunction, TGrowingFunction );
+      itkGetConstObjectMacro( GrowingFunction, TGrowingFunction );
+
+      itkSetMacro( InsideValue, TResult );
+      itkSetMacro( OutsideValue, TResult );
+      itkSetObjectMacro( GrowingFunction, TGrowingFunction );
 
     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;
 
-      virtual bool _CheckMembership( const _TNode& n ) const = 0;
+      // Results-related abstract methods
+      virtual bool _ComputeNeighborResult(
+        TResult& result, const TVertex& neighbor, const TVertex& parent
+        ) const ITK_OVERRIDE;
 
-    private:
-      RegionGrow( const Self& );     // Not impl.
-      void operator=( const Self& ); // Not impl.
+      // Queue-related abstract methods
+      virtual bool _IsQueueEmpty( ) const ITK_OVERRIDE;
+      virtual void _QueuePush( const TVertex& v, const _TNode& n ) ITK_OVERRIDE;
+      virtual void _QueuePop( TVertex& v, _TNode& n ) ITK_OVERRIDE;
+      virtual void _QueueClear( ) ITK_OVERRIDE;
 
     private:
+      // Purposely not implemented
+      RegionGrow( const Self& other );
+      Self& operator=( const Self& other );
+
+    protected:
+      TResult m_InsideValue;
+      TResult m_OutsideValue;
       _TQueue m_Queue;
+
+      typename TGrowingFunction::Pointer m_GrowingFunction;
     };
 
   } // ecapseman
 
 } // ecapseman
 
+#ifndef ITK_MANUAL_INSTANTIATION
 #include <fpa/Base/RegionGrow.hxx>
+#endif // ITK_MANUAL_INSTANTIATION
 
 #endif // __FPA__BASE__REGIONGROW__H__