]> Creatis software - FrontAlgorithms.git/commitdiff
...
authorLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Wed, 7 Jun 2017 20:56:10 +0000 (15:56 -0500)
committerLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Wed, 7 Jun 2017 20:56:10 +0000 (15:56 -0500)
lib/fpa/Base/Algorithm.h [new file with mode: 0644]
lib/fpa/Base/Algorithm.hxx [new file with mode: 0644]

diff --git a/lib/fpa/Base/Algorithm.h b/lib/fpa/Base/Algorithm.h
new file mode 100644 (file)
index 0000000..b457b9e
--- /dev/null
@@ -0,0 +1,74 @@
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
+
+#ifndef __fpa__Base__Algorithm__h__
+#define __fpa__Base__Algorithm__h__
+
+#include <vector>
+
+namespace fpa
+{
+  namespace Base
+  {
+    /**
+     */
+    template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+    class Algorithm
+      : public _TFilter,
+        public _TMarksInterface,
+        public _TSeedsInterface
+    {
+    public:
+      typedef Algorithm                       Self;
+      typedef _TFilter                        Superclass;
+      typedef _TMarksInterface                TMarksInterface;
+      typedef _TSeedsInterface                TSeedsInterface;
+      typedef itk::SmartPointer< Self >       Pointer;
+      typedef itk::SmartPointer< const Self > ConstPointer;
+
+      typedef typename _TMarksInterface::TNode        TNode;
+      typedef typename _TMarksInterface::TOutputValue TOutputValue;
+      typedef typename _TSeedsInterface::TSeeds       TSeeds;
+
+      typedef std::vector< TNode > TNeighborhood;
+
+    public:
+      itkTypeMacro( Algorithm, TFilter );
+
+      itkGetConstMacro( InitValue, TOutputValue );
+      itkSetMacro( InitValue, TOutputValue );
+
+    protected:
+      Algorithm( );
+      virtual ~Algorithm( );
+
+      virtual void GenerateData( ) override;
+
+      virtual void _ConfigureOutput( const TOutputValue& v ) = 0;
+      virtual void _QueueInit( ) = 0;
+      virtual void _QueuePush( const TNode& node ) = 0;
+      virtual unsigned long _QueueSize( ) const = 0;
+      virtual TNode _QueuePop( ) = 0;
+
+    private:
+      // Purposely not implemented
+      Algorithm( const Self& other );
+      Self& operator=( const Self& other );
+
+    protected:
+      TOutputValue m_InitValue;
+    };
+
+  } // ecapseman
+
+} // ecapseman
+
+#ifndef ITK_MANUAL_INSTANTIATION
+#  include <fpa/Base/Algorithm.hxx>
+#endif // ITK_MANUAL_INSTANTIATION
+
+#endif // __fpa__Base__Algorithm__h__
+
+// eof - $RCSfile$
diff --git a/lib/fpa/Base/Algorithm.hxx b/lib/fpa/Base/Algorithm.hxx
new file mode 100644 (file)
index 0000000..3a52f78
--- /dev/null
@@ -0,0 +1,82 @@
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
+
+#ifndef __fpa__Base__Algorithm__hxx__
+#define __fpa__Base__Algorithm__hxx__
+
+// -------------------------------------------------------------------------
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::
+Algorithm( )
+  : Superclass( ),
+    _TMarksInterface( this ),
+    _TSeedsInterface( this )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::
+~Algorithm( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+void fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::
+GenerateData( )
+{
+  // Init objects
+  this->_ConfigureOutput( this->m_InitValue );
+  this->_InitMarks( );
+
+  // Init queue
+  this->_QueueInit( );
+  typename TSeeds::const_iterator sIt = this->BeginSeeds( );
+  for( ; sIt != this->EndSeeds( ); ++sIt )
+    this->_QueuePush( *sIt );
+
+  // Main loop
+  while( this->_QueueSize( ) > 0 )
+  {
+    // Get next candidate
+    TNode node = this->_QueuePop( );
+    if( !( this->_IsMarked( node ) ) )
+    {
+      // Mark it
+      if( this->_Mark( node ) )
+      {
+        // Add neighborhood
+        TNeighborhood neighbors = this->_GetNeighbors( node );
+        typename TNeighborhood::const_iterator nIt = neighbors.begin( );
+        bool coll = false;
+        while( nIt != neighbors.end( ) && !coll )
+        {
+          if( this->_IsMarked( *nIt ) )
+          {
+            // Invoke stop at collisions
+            if( this->_Collisions( node, *nIt ) )
+            {
+              this->_QueueClear( );
+              coll = true;
+
+            } // fi
+          }
+          else
+            this->_QueuePush( *nIt );
+          ++nIt;
+
+        } // elihw
+
+      } // fi
+
+    } // fi
+
+  } // elihw
+}
+
+#endif // __fpa__Base__Algorithm__hxx__
+
+// eof - $RCSfile$