SET(
_examples
RegionGrow_00
+ MoriRegionGrow_00
)
INCLUDE_DIRECTORIES(
${PROJECT_SOURCE_DIR}/lib
--- /dev/null
+#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$
+++ /dev/null
-#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$
+++ /dev/null
-#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$
#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
{
*/
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
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 );
}
// -------------------------------------------------------------------------
{
}
+// -------------------------------------------------------------------------
+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 >::
{
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__
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 )
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