]> Creatis software - FrontAlgorithms.git/commitdiff
...
authorLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Mon, 6 Feb 2017 22:47:37 +0000 (17:47 -0500)
committerLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Mon, 6 Feb 2017 22:47:37 +0000 (17:47 -0500)
data/test_mori_2D.png [new file with mode: 0644]
examples/CMakeLists.txt
examples/MoriRegionGrow_00.cxx [new file with mode: 0644]
lib/fpa/Base/MoriRegionGrow.h [deleted file]
lib/fpa/Base/MoriRegionGrow.hxx [deleted file]
lib/fpa/Image/MoriRegionGrow.h
lib/fpa/Image/MoriRegionGrow.hxx
lib/fpa/Image/RegionGrow.hxx
plugins/ImageAlgorithms/ImageAlgorithms.i

diff --git a/data/test_mori_2D.png b/data/test_mori_2D.png
new file mode 100644 (file)
index 0000000..943e9f0
Binary files /dev/null and b/data/test_mori_2D.png differ
index 24e670a39a26795a418a7f6947051ffc0ee43c5e..4a8ae35dc7fdca38df8861a05c558dffbc5df8d3 100644 (file)
@@ -4,6 +4,7 @@ IF(BUILD_Examples)
   SET(
     _examples
     RegionGrow_00
+    MoriRegionGrow_00
     )
   INCLUDE_DIRECTORIES(
     ${PROJECT_SOURCE_DIR}/lib
diff --git a/examples/MoriRegionGrow_00.cxx b/examples/MoriRegionGrow_00.cxx
new file mode 100644 (file)
index 0000000..d0dabff
--- /dev/null
@@ -0,0 +1,110 @@
+#include <itkCommand.h>
+#include <itkImage.h>
+#include <itkImageFileReader.h>
+#include <itkImageFileWriter.h>
+#include <fpa/Image/MoriRegionGrow.h>
+
+// -------------------------------------------------------------------------
+typedef itk::Image< unsigned char, 2 >               TImage;
+typedef itk::ImageFileReader< TImage >               TReader;
+typedef itk::ImageFileWriter< TImage >               TWriter;
+typedef fpa::Image::MoriRegionGrow< TImage, TImage > TFilter;
+
+// -------------------------------------------------------------------------
+/**
+ */
+class MyObserver
+  : public itk::Command
+{
+public:
+  typedef TFilter::TStartEvent     TStartEvent;
+  typedef TFilter::TEndEvent       TEndEvent;
+  typedef TFilter::TStartLoopEvent TStartLoopEvent;
+  typedef TFilter::TEndLoopEvent   TEndLoopEvent;
+  typedef TFilter::TPushEvent      TPushEvent;
+  typedef TFilter::TPopEvent       TPopEvent;
+  typedef TFilter::TMarkEvent      TMarkEvent;
+
+public:
+  itkNewMacro( MyObserver );
+
+public:
+  virtual void Execute(
+    itk::Object* caller, const itk::EventObject& event
+    ) override
+    {
+      this->Execute( const_cast< const itk::Object* >( caller ), event );
+    }
+  virtual void Execute(
+    const itk::Object* object, const itk::EventObject& event
+    ) override
+    {
+      /* TODO
+         if( TStartEvent( ).CheckEvent( &event ) )
+         std::cout << "Start" << std::endl;
+         else if( TEndEvent( ).CheckEvent( &event ) )
+         std::cout << "End" << std::endl;
+         else if( TStartLoopEvent( ).CheckEvent( &event ) )
+         std::cout << "StartLoop" << std::endl;
+         else if( TEndLoopEvent( ).CheckEvent( &event ) )
+         std::cout << "EndLoop" << std::endl;
+         else if( TMarkEvent( ).CheckEvent( &event ) )
+         {
+         const TMarkEvent* mark = dynamic_cast< const TMarkEvent* >( &event );
+         std::cout << "Mark: " << mark->Vertex << std::endl;
+
+         } // fi
+      */
+      /* TODO
+         TPushEvent;
+         TPopEvent;
+      */
+    }
+};
+
+// -------------------------------------------------------------------------
+int main( int argc, char* argv[] )
+{
+  if( argc < 3 )
+  {
+    std::cerr
+      << "Usage: " << argv[ 0 ]
+      << " input_filename output_filename" << std::endl;
+    return( 1 );
+
+  } // fi
+  std::string in_fname = argv[ 1 ];
+  std::string out_fname = argv[ 2 ];
+  int seed_x = 111;
+  int seed_y = 91;
+
+  TReader::Pointer reader = TReader::New( );
+  reader->SetFileName( in_fname );
+
+  TImage::IndexType seed;
+  seed[ 0 ] = seed_x;
+  seed[ 1 ] = seed_y;
+
+  TFilter::Pointer filter = TFilter::New( );
+  filter->SetInput( reader->GetOutput( ) );
+  filter->SetLower( 0 );
+  filter->SetUpper( 255 );
+  filter->SetStep( 1 );
+  filter->SetInsideValue( 255 );
+  filter->SetOutsideValue( 0 );
+  filter->AddSeed( seed, filter->GetInsideValue( ) );
+
+  /* TODO
+     MyObserver::Pointer obs = MyObserver::New( );
+     filter->AddObserver( itk::AnyEvent( ), obs );
+  */
+
+  TWriter::Pointer writer = TWriter::New( );
+  writer->SetInput( filter->GetOutput( ) );
+  writer->SetFileName( out_fname );
+  writer->Update( );
+
+  return( 0 );
+}
+
+// eof - $RCSfile$
diff --git a/lib/fpa/Base/MoriRegionGrow.h b/lib/fpa/Base/MoriRegionGrow.h
deleted file mode 100644 (file)
index 40f59cd..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-#ifndef __fpa__Base__MoriRegionGrow__h__
-#define __fpa__Base__MoriRegionGrow__h__
-
-#include <queue>
-#include <fpa/Config.h>
-#include <fpa/Base/RegionGrow.h>
-
-namespace fpa
-{
-  namespace Base
-  {
-    /**
-     */
-    template< class _TSuperclass >
-    class MoriRegionGrow
-      : public fpa::Base::RegionGrow< _TSuperclass >
-    {
-    public:
-      typedef MoriRegionGrow                        Self;
-      typedef fpa::Base::RegionGrow< _TSuperclass > Superclass;
-      typedef itk::SmartPointer< Self >             Pointer;
-      typedef itk::SmartPointer< const Self >       ConstPointer;
-
-      typedef typename Superclass::TOutput TOutput;
-      typedef typename Superclass::TVertex TVertex;
-
-    protected:
-      typedef typename Superclass::_TQueueNode _TQueueNode;
-      typedef typename Superclass::_TQueue     _TQueue;
-
-    public:
-      itkTypeMacro( MoriRegionGrow, Algorithm );
-
-    protected:
-      MoriRegionGrow( );
-      virtual ~MoriRegionGrow( );
-
-      virtual bool _UpdateValue(
-        _TQueueNode& v, const _TQueueNode& p
-        ) override;
-
-    private:
-      // Purposely not defined
-      MoriRegionGrow( const Self& other );
-      Self& operator=( const Self& other );
-
-    protected:
-      _TQueue m_AuxilaryQueue;
-    };
-
-  } // ecapseman
-
-} // ecapseman
-
-#ifndef ITK_MANUAL_INSTANTIATION
-#  include <fpa/Base/MoriRegionGrow.hxx>
-#endif // ITK_MANUAL_INSTANTIATION
-
-#endif // __fpa__Base__MoriRegionGrow__h__
-
-// eof - $RCSfile$
diff --git a/lib/fpa/Base/MoriRegionGrow.hxx b/lib/fpa/Base/MoriRegionGrow.hxx
deleted file mode 100644 (file)
index 9e1c300..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-#ifndef __fpa__Base__MoriRegionGrow__hxx__
-#define __fpa__Base__MoriRegionGrow__hxx__
-
-// -------------------------------------------------------------------------
-template< class _TSuperclass >
-fpa::Base::MoriRegionGrow< _TSuperclass >::
-MoriRegionGrow( )
-  : Superclass( )
-{
-}
-
-// -------------------------------------------------------------------------
-template< class _TSuperclass >
-fpa::Base::MoriRegionGrow< _TSuperclass >::
-~MoriRegionGrow( )
-{
-}
-
-// -------------------------------------------------------------------------
-template< class _TSuperclass >
-bool fpa::Base::MoriRegionGrow< _TSuperclass >::
-_UpdateValue( _TQueueNode& v, const _TQueueNode& p )
-{
-  bool ret = this->Superclass::_UpdateValue( v, p );
-  if( !ret )
-    this->m_AuxilaryQueue.push( v );
-  return( ret );
-}
-
-
-#endif // __fpa__Base__MoriRegionGrow__hxx__
-
-// eof - $RCSfile$
index 57085825705893cf0cfd7c710d157d888a9b518a..50e8bb1e3cc1769b260bfbfa4fbe4a24c00ac5bc 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef __fpa__Image__MoriRegionGrow__h__
 #define __fpa__Image__MoriRegionGrow__h__
 
-#include <fpa/Base/MoriRegionGrow.h>
-#include <fpa/Image/Algorithm.h>
+#include <fpa/Image/RegionGrow.h>
+#include <fpa/Image/Functors/RegionGrow/BinaryThreshold.h>
 
 namespace fpa
 {
@@ -12,34 +12,62 @@ namespace fpa
      */
     template< class _TInputImage, class _TOutputImage >
     class MoriRegionGrow
-      : public fpa::Base::MoriRegionGrow< fpa::Image::Algorithm< _TInputImage, _TOutputImage > >
+      : public fpa::Image::RegionGrow< _TInputImage, _TOutputImage >
     {
     public:
-      typedef fpa::Image::Algorithm< _TInputImage, _TOutputImage > TAlgorithm;
-      typedef MoriRegionGrow                          Self;
-      typedef fpa::Base::MoriRegionGrow< TAlgorithm > Superclass;
-      typedef itk::SmartPointer< Self >           Pointer;
-      typedef itk::SmartPointer< const Self >     ConstPointer;
+      typedef MoriRegionGrow                                        Self;
+      typedef fpa::Image::RegionGrow< _TInputImage, _TOutputImage > Superclass;
+      typedef itk::SmartPointer< Self >                             Pointer;
+      typedef itk::SmartPointer< const Self >                       ConstPointer;
 
-      typedef typename Superclass::TOutput TOutput;
-      typedef typename Superclass::TVertex TVertex;
+      typedef typename Superclass::TOutput       TOutput;
+      typedef typename Superclass::TVertex       TVertex;
+      typedef typename Superclass::TGrowFunction TGrowFunction;
+      typedef
+      fpa::Image::Functors::RegionGrow::BinaryThreshold< _TInputImage >
+      TBinThresholdFunction;
+      typedef typename _TInputImage::PixelType TPixel;
 
-      typedef fpa::Image::Functors::Base< _TInputImage, typename Superclass::TGrowFunction > TGrowFunction;
+    protected:
+      typedef typename Superclass::_TQueueNode _TQueueNode;
+      typedef typename Superclass::_TQueue     _TQueue;
 
     public:
       itkNewMacro( Self );
-      itkTypeMacro( fpa::Image::MoriRegionGrow, fpa::Base::MoriRegionGrow );
+      itkTypeMacro( fpa::Image::MoriRegionGrow, fpa::Image::RegionGrow );
+
+      itkGetConstMacro( Lower, TPixel );
+      itkGetConstMacro( Upper, TPixel );
+      itkGetConstMacro( Step, TPixel );
+
+      itkSetMacro( Lower, TPixel );
+      itkSetMacro( Upper, TPixel );
+      itkSetMacro( Step, TPixel );
 
     protected:
       MoriRegionGrow( );
       virtual ~MoriRegionGrow( );
 
-      virtual void _BeforeGenerateData( ) fpa_OVERRIDE;
+      virtual bool _ContinueGenerateData( ) override;
+      virtual void _BeforeGenerateData( ) override;
+      virtual void _AfterGenerateData( ) override;
+      virtual void _BeforeLoop( ) override;
+      virtual void _AfterLoop( ) override;
+      virtual bool _UpdateValue( _TQueueNode& v, const _TQueueNode& p ) override;
+      virtual void _UpdateResult( const _TQueueNode& n ) override;
 
     private:
       // Purposely not defined
       MoriRegionGrow( const Self& other );
       Self& operator=( const Self& other );
+
+    protected:
+      TPixel m_Lower;
+      TPixel m_Upper;
+      TPixel m_Step;
+
+      _TQueue m_NextQueue;
+      unsigned long m_ActualCount;
     };
 
   } // ecapseman
index 29f46ac74f6b3baa827c235079734323673aec5b..3b06e41cdd463dce08115f3e6cdf7eb8011442a8 100644 (file)
@@ -5,8 +5,17 @@
 template< class _TInputImage, class _TOutputImage >
 fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
 MoriRegionGrow( )
-  : Superclass( )
+  : Superclass( ),
+    m_Step( TPixel( 1 ) )
 {
+  this->m_Upper = std::numeric_limits< TPixel >::max( );
+  if( std::numeric_limits< TPixel >::is_integer )
+    this->m_Lower = std::numeric_limits< TPixel >::min( );
+  else
+    this->m_Lower = -this->m_Upper;
+  typename TBinThresholdFunction::Pointer functor =
+    TBinThresholdFunction::New( );
+  this->SetGrowFunction( functor );
 }
 
 // -------------------------------------------------------------------------
@@ -16,6 +25,32 @@ fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
 {
 }
 
+// -------------------------------------------------------------------------
+template< class _TInputImage, class _TOutputImage >
+bool fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
+_ContinueGenerateData( )
+{
+  TBinThresholdFunction* functor =
+    dynamic_cast< TBinThresholdFunction* >( this->GetGrowFunction( ) );
+  TPixel u = functor->GetUpper( );
+
+  std::cout << long( u ) << " " << this->m_ActualCount << std::endl;
+
+  if( u < this->m_Upper )
+  {
+    u += this->m_Step;
+    if( u > this->m_Upper )
+      u = this->m_Upper;
+    functor->SetUpper( u );
+    this->m_Queue = this->m_NextQueue;
+    while( this->m_NextQueue.size( ) > 0 )
+      this->m_NextQueue.pop( );
+    return( true );
+  }
+  else
+    return( false );
+}
+
 // -------------------------------------------------------------------------
 template< class _TInputImage, class _TOutputImage >
 void fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
@@ -23,10 +58,63 @@ _BeforeGenerateData( )
 {
   this->Superclass::_BeforeGenerateData( );
 
-  TGrowFunction* grow =
-    dynamic_cast< TGrowFunction* >( this->GetGrowFunction( ) );
-  if( grow != NULL )
-    grow->SetImage( this->GetInput( ) );
+  while( this->m_NextQueue.size( ) > 0 )
+    this->m_NextQueue.pop( );
+  this->m_ActualCount = 0;
+  TBinThresholdFunction* functor =
+    dynamic_cast< TBinThresholdFunction* >( this->GetGrowFunction( ) );
+  functor->SetLower( this->m_Lower );
+  functor->SetUpper( this->m_Lower + this->m_Step );
+}
+
+// -------------------------------------------------------------------------
+template< class _TInputImage, class _TOutputImage >
+void fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
+_AfterGenerateData( )
+{
+  this->Superclass::_AfterGenerateData( );
+  while( this->m_NextQueue.size( ) > 0 )
+    this->m_NextQueue.pop( );
+}
+
+// -------------------------------------------------------------------------
+template< class _TInputImage, class _TOutputImage >
+void fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
+_BeforeLoop( )
+{
+  this->Superclass::_BeforeLoop( );
+}
+
+// -------------------------------------------------------------------------
+template< class _TInputImage, class _TOutputImage >
+void fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
+_AfterLoop( )
+{
+  this->Superclass::_AfterLoop( );
+}
+
+// -------------------------------------------------------------------------
+template< class _TInputImage, class _TOutputImage >
+bool fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
+_UpdateValue( _TQueueNode& v, const _TQueueNode& p )
+{
+  bool ret = this->Superclass::_UpdateValue( v, p );
+  if( !ret )
+  {
+    v.Result = this->m_InsideValue;
+    this->m_NextQueue.push( v );
+
+  } // fi
+  return( ret );
+}
+
+// -------------------------------------------------------------------------
+template< class _TInputImage, class _TOutputImage >
+void fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
+_UpdateResult( const _TQueueNode& n )
+{
+  this->Superclass::_UpdateResult( n );
+  this->m_ActualCount += 1;
 }
 
 #endif // __fpa__Image__MoriRegionGrow__hxx__
index b1f5da02b5b775e10b157ed782b7a47cd1a1a71f..5c8b76e01a57852c5ff3ae0afcbbe33eb98b66e2 100644 (file)
@@ -21,8 +21,8 @@ template< class _TInputImage, class _TOutputImage >
 void fpa::Image::RegionGrow< _TInputImage, _TOutputImage >::
 _BeforeGenerateData( )
 {
+  this->m_InitResult = this->m_OutsideValue;
   this->Superclass::_BeforeGenerateData( );
-
   TGrowFunction* grow =
     dynamic_cast< TGrowFunction* >( this->GetGrowFunction( ) );
   if( grow != NULL )
index 9f44dd14d070960f68c63f4396d165df8827d78b..41cd37cdf5cfca304f61db86595bd577ea4d669b 100644 (file)
@@ -4,7 +4,6 @@ tinclude fpa/Image/Functors/SimpleNeighborhood:h|hxx
 instances fpa::Image::Functors::SimpleNeighborhood< itk::Image< #scalar_types#, #pdims# > >
 
 cinclude fpa/Base/RegionGrow.hxx
-cinclude fpa/Base/MoriRegionGrow.hxx
 define all_int_types=#int_types#;#uint_types#
 tinclude fpa/Image/RegionGrow:h|hxx
 tinclude fpa/Image/MoriRegionGrow:h|hxx