]> Creatis software - FrontAlgorithms.git/commitdiff
...
authorLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Tue, 21 Mar 2017 22:55:50 +0000 (17:55 -0500)
committerLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Tue, 21 Mar 2017 22:55:50 +0000 (17:55 -0500)
libs/fpa/Base/SeedsInterface.h [new file with mode: 0644]
libs/fpa/Base/SeedsInterface.hxx [new file with mode: 0644]
libs/fpa/Image/RegionGrow.h
libs/fpa/Image/RegionGrow.hxx

diff --git a/libs/fpa/Base/SeedsInterface.h b/libs/fpa/Base/SeedsInterface.h
new file mode 100644 (file)
index 0000000..a994125
--- /dev/null
@@ -0,0 +1,56 @@
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
+
+#ifndef __fpa__Base__SeedsInterface__h__
+#define __fpa__Base__SeedsInterface__h__
+
+#include <itkProcessObject.h>
+#include <set>
+
+namespace fpa
+{
+  namespace Base
+  {
+    /**
+     */
+    template< class _TVertex, class _TCompare >
+    class SeedsInterface
+    {
+    public:
+      typedef _TVertex  TVertex;
+      typedef _TCompare TCompare;
+      typedef SeedsInterface Self;
+      typedef std::set< TVertex, TCompare > TSeeds;
+
+    public:
+      unsigned int GetNumberOfSeeds( ) const;
+      const TSeeds& GetSeeds( ) const;
+      typename TSeeds::const_iterator BeginSeeds( ) const;
+      typename TSeeds::const_iterator EndSeeds( ) const;
+
+      void AddSeed( const TVertex& seed );
+      void RemoveSeed( const TVertex& seed );
+      void ClearSeeds( );
+
+    protected:
+      SeedsInterface( itk::ProcessObject* filter );
+      virtual ~SeedsInterface( );
+
+    private:
+      TSeeds m_Seeds;
+      itk::ProcessObject* m_Filter;
+    };
+
+  } // ecapseman
+
+} // ecapseman
+
+#ifndef ITK_MANUAL_INSTANTIATION
+#  include <fpa/Base/SeedsInterface.hxx>
+#endif // ITK_MANUAL_INSTANTIATION
+
+#endif // __fpa__Base__SeedsInterface__h__
+
+// eof - $RCSfile$
diff --git a/libs/fpa/Base/SeedsInterface.hxx b/libs/fpa/Base/SeedsInterface.hxx
new file mode 100644 (file)
index 0000000..4e20760
--- /dev/null
@@ -0,0 +1,100 @@
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
+
+#ifndef __fpa__Base__SeedsInterface__hxx__
+#define __fpa__Base__SeedsInterface__hxx__
+
+// -------------------------------------------------------------------------
+template< class _TVertex, class _TCompare >
+unsigned int fpa::Base::SeedsInterface< _TVertex, _TCompare >::
+GetNumberOfSeeds( ) const
+{
+  return( this->m_Seeds.size( ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TVertex, class _TCompare >
+const typename fpa::Base::SeedsInterface< _TVertex, _TCompare >::
+TSeeds& fpa::Base::SeedsInterface< _TVertex, _TCompare >::
+GetSeeds( ) const
+{
+  return( this->m_Seeds );
+}
+
+// -------------------------------------------------------------------------
+template< class _TVertex, class _TCompare >
+typename fpa::Base::SeedsInterface< _TVertex, _TCompare >::
+TSeeds::const_iterator fpa::Base::SeedsInterface< _TVertex, _TCompare >::
+BeginSeeds( ) const
+{
+  return( this->m_Seeds.begin( ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TVertex, class _TCompare >
+typename fpa::Base::SeedsInterface< _TVertex, _TCompare >::
+TSeeds::const_iterator fpa::Base::SeedsInterface< _TVertex, _TCompare >::
+EndSeeds( ) const
+{
+  return( this->m_Seeds.end( ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TVertex, class _TCompare >
+void fpa::Base::SeedsInterface< _TVertex, _TCompare >::
+AddSeed( const TVertex& seed )
+{
+  if( this->m_Seeds.insert( seed ).second && this->m_Filter != NULL )
+    this->m_Filter->Modified( );
+}
+
+// -------------------------------------------------------------------------
+template< class _TVertex, class _TCompare >
+void fpa::Base::SeedsInterface< _TVertex, _TCompare >::
+RemoveSeed( const TVertex& seed )
+{
+  typename TSeeds::const_iterator i = this->m_Seeds.find( seed );
+  if( i != this->m_Seeds.end( ) )
+  {
+    this->m_Seeds.erase( i );
+    if( this->m_Filter != NULL )
+      this->m_Filter->Modified( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+template< class _TVertex, class _TCompare >
+void fpa::Base::SeedsInterface< _TVertex, _TCompare >::
+ClearSeeds( )
+{
+  if( this->m_Seeds.size( ) > 0 )
+  {
+    this->m_Seeds.clear( );
+    if( this->m_Filter != NULL )
+      this->m_Filter->Modified( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+template< class _TVertex, class _TCompare >
+fpa::Base::SeedsInterface< _TVertex, _TCompare >::
+SeedsInterface( itk::ProcessObject* filter )
+  : m_Filter( filter )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TVertex, class _TCompare >
+fpa::Base::SeedsInterface< _TVertex, _TCompare >::
+~SeedsInterface( )
+{
+  this->m_Seeds.clear( );
+}
+
+#endif // __fpa__Base__SeedsInterface__hxx__
+
+// eof - $RCSfile$
index 6981f756f124dcc1d997bc423cbbbee1e1664fca..e21bbb91ce6e0015abe84fb5e57a453725455f81 100644 (file)
@@ -8,7 +8,7 @@
 
 #include <itkImageToImageFilter.h>
 #include <itkFunctionBase.h>
-#include <set>
+#include <fpa/Base/SeedsInterface.h>
 
 namespace fpa
 {
@@ -18,26 +18,26 @@ namespace fpa
      */
     template< class _TInputImage, class _TOutputImage >
     class RegionGrow
-      : public itk::ImageToImageFilter< _TInputImage, _TOutputImage >
+      : public itk::ImageToImageFilter< _TInputImage, _TOutputImage >,
+        public fpa::Base::SeedsInterface< typename _TInputImage::IndexType, typename _TInputImage::IndexType::LexicographicCompare >
     {
     public:
       typedef _TInputImage  TInputImage;
       typedef _TOutputImage TOutputImage;
+      typedef typename TInputImage::IndexType  TIndex;
+      typedef typename TInputImage::RegionType TRegion;
+      typedef typename TInputImage::PixelType  TInputPixel;
+      typedef typename TOutputImage::PixelType TOutputPixel;
+      typedef typename TIndex::LexicographicCompare TIndexCompare;
 
       typedef RegionGrow                                                 Self;
       typedef itk::ImageToImageFilter< TInputImage, TOutputImage > Superclass;
       typedef itk::SmartPointer< Self >                               Pointer;
       typedef itk::SmartPointer< const Self >                    ConstPointer;
 
-      typedef typename TInputImage::IndexType  TIndex;
-      typedef typename TInputImage::RegionType TRegion;
-      typedef typename TInputImage::PixelType  TInputPixel;
-      typedef typename TOutputImage::PixelType TOutputPixel;
-
+      typedef fpa::Base::SeedsInterface< TIndex, TIndexCompare > TSeedsInterface;
       typedef itk::FunctionBase< TInputPixel, bool > TIntensityFunctor;
 
-      typedef std::set< TIndex, typename TIndex::LexicographicCompare > TSeeds;
-
     public:
       itkNewMacro( Self );
       itkTypeMacro( fpa::Image::RegionGrow, itk::ImageToImageFilter );
@@ -51,8 +51,6 @@ namespace fpa
     public:
       void SetPredicate( TIntensityFunctor* functor );
 
-      void AddSeed( const TIndex& seed );
-
     protected:
       RegionGrow( );
       virtual ~RegionGrow( );
@@ -70,7 +68,9 @@ namespace fpa
 
     protected:
       typename TIntensityFunctor::Pointer m_IntensityFunctor;
-      TSeeds m_Seeds;
+      /* TODO
+         TSeeds m_Seeds;
+      */
       TOutputPixel m_InsideValue;
       TOutputPixel m_OutsideValue;
     };
index 0cf74deca72c5af32a8834e34fa38e525357b4a2..facd9f80956f7da34923a8ff7f84fe80e5db4ca5 100644 (file)
@@ -21,20 +21,12 @@ SetPredicate( TIntensityFunctor* functor )
   } // fi
 }
 
-// -------------------------------------------------------------------------
-template< class _TInputImage, class _TOutputImage >
-void fpa::Image::RegionGrow< _TInputImage, _TOutputImage >::
-AddSeed( const TIndex& seed )
-{
-  if( this->m_Seeds.insert( seed ).second )
-    this->Modified( );
-}
-
 // -------------------------------------------------------------------------
 template< class _TInputImage, class _TOutputImage >
 fpa::Image::RegionGrow< _TInputImage, _TOutputImage >::
 RegionGrow( )
   : Superclass( ),
+    TSeedsInterface( this ),
     m_InsideValue( TInputPixel( 0 ) ),
     m_OutsideValue( TInputPixel( 0 ) )
 {
@@ -96,7 +88,7 @@ GenerateData( )
 
   // Init queue
   std::queue< TIndex > q;
-  for( TIndex seed: this->m_Seeds )
+  for( TIndex seed: this->GetSeeds( ) )
     q.push( seed );
 
   // Main loop