]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/Base/RegionGrow.h
...
[FrontAlgorithms.git] / lib / fpa / Base / RegionGrow.h
index f7f15625415ae6ef3772b71748e113782e6423fe..4790b851a9273768e1d0ae5f4cf1e79e03d025aa 100644 (file)
@@ -1,9 +1,9 @@
-#ifndef __FPA__BASE__REGIONGROW__H__
-#define __FPA__BASE__REGIONGROW__H__
+#ifndef __fpa__Base__RegionGrow__h__
+#define __fpa__Base__RegionGrow__h__
 
 #include <queue>
-#include <vector>
-#include <fpa/Base/Algorithm.h>
+#include <fpa/Base/QueueAlgorithm.h>
+#include <fpa/Base/Functors/RegionGrow/Base.h>
 
 namespace fpa
 {
@@ -11,105 +11,69 @@ namespace fpa
   {
     /**
      */
-    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.
-     */
-    template< class V, class R, class VV, class VC, class B >
+    template< class _TSuperclass >
     class RegionGrow
-      : public Algorithm< RegionGrowTraits< V, R, VV, VC >, B >
+      : public fpa::Base::QueueAlgorithm< _TSuperclass >
     {
     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 itk::SmartPointer< Self >        Pointer;
-      typedef itk::SmartPointer< const Self >  ConstPointer;
+      typedef RegionGrow                                Self;
+      typedef fpa::Base::QueueAlgorithm< _TSuperclass > Superclass;
+      typedef itk::SmartPointer< Self >                 Pointer;
+      typedef itk::SmartPointer< const Self >           ConstPointer;
 
-      typedef typename TTraits::TCost TCost;
+      typedef typename Superclass::TOutput TOutput;
+      typedef typename Superclass::TVertex TVertex;
+      typedef fpa::Base::Functors::RegionGrow::Base< TVertex, TOutput > TGrowFunction;
 
     protected:
-      typedef typename TTraits::TFrontId  _TFrontId;
-      typedef typename TTraits::TNode     _TNode;
-      typedef typename TTraits::TNodes    _TNodes;
-      typedef std::queue< _TNode >        _TQueue;
+      typedef typename Superclass::_TQueueNode _TQueueNode;
 
     public:
       itkTypeMacro( RegionGrow, Algorithm );
 
+    public:
+      TGrowFunction* GetGrowFunction( );
+      const TGrowFunction* GetGrowFunction( ) const;
+      TOutput GetInsideValue( ) const;
+      TOutput GetOutsideValue( ) const;
+
+      void SetGrowFunction( TGrowFunction* f );
+      void SetInsideValue( const TOutput& v );
+      void SetOutsideValue( const TOutput& v );
+
     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 _UpdateValue(
+        _TQueueNode& v, const _TQueueNode& p
+        ) override;
+      virtual TOutput _GetInputValue( const _TQueueNode& v, const _TQueueNode& p ) override
+        {
+          TOutput res = this->m_InitResult;
+          if( this->m_GrowFunction.IsNotNull( ) )
+            res = this->m_GrowFunction->Evaluate( v.Vertex, p.Vertex );
+          return( res );
+        }
 
-      virtual bool _CheckMembership( const _TNode& n ) const = 0;
 
     private:
-      RegionGrow( const Self& );     // Not impl.
-      void operator=( const Self& ); // Not impl.
+      // Purposely not defined
+      RegionGrow( const Self& other );
+      Self& operator=( const Self& other );
 
     protected:
-      _TQueue m_Queue;
+      typename TGrowFunction::Pointer m_GrowFunction;
     };
 
   } // ecapseman
 
 } // ecapseman
 
-#include <fpa/Base/RegionGrow.hxx>
+#ifndef ITK_MANUAL_INSTANTIATION
+#  include <fpa/Base/RegionGrow.hxx>
+#endif // ITK_MANUAL_INSTANTIATION
 
-#endif // __FPA__BASE__REGIONGROW__H__
+#endif // __fpa__Base__RegionGrow__h__
 
 // eof - $RCSfile$