From: Leonardo Flórez-Valencia Date: Fri, 3 Feb 2017 22:25:32 +0000 (-0500) Subject: Mori is alivegit status! X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=6585142e69f2ff5e4fceb21320ab3795c3e82218;p=FrontAlgorithms.git Mori is alivegit status! --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 667002b..811b889 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ SET(prj_NAME FrontAlgorithms) SET(prj_MAJOR_VERSION 0) SET(prj_MINOR_VERSION 1) SET(prj_RELEASE_VERSION 0) -SET(_subdirs lib plugins) +SET(_subdirs lib plugins examples) SET(_policies CMP0015 CMP0020 CMP0042) ## ========================== diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..24e670a --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,18 @@ +OPTION(BUILD_Examples "Build simple examples?" OFF) + +IF(BUILD_Examples) + SET( + _examples + RegionGrow_00 + ) + INCLUDE_DIRECTORIES( + ${PROJECT_SOURCE_DIR}/lib + ${PROJECT_BINARY_DIR}/lib + ) + FOREACH(_example ${_examples}) + ADD_EXECUTABLE(fpa_example_${_example} ${_example}.cxx) + TARGET_LINK_LIBRARIES(fpa_example_${_example} ${ITK_LIBRARIES}) + ENDFOREACH(_example) +ENDIF(BUILD_Examples) + +## eof - $RCSfile$ diff --git a/examples/RegionGrow_00.cxx b/examples/RegionGrow_00.cxx new file mode 100644 index 0000000..eab6d41 --- /dev/null +++ b/examples/RegionGrow_00.cxx @@ -0,0 +1,100 @@ +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +typedef itk::Image< unsigned char, 2 > TImage; +typedef fpa::Image::RegionGrow< TImage, TImage > TFilter; +typedef itk::ImageFileWriter< TImage > TWriter; + +// ------------------------------------------------------------------------- +/** + */ +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 + { + 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[] ) +{ + TImage::SizeType size; + size.Fill( 10 ); + + TImage::Pointer input = TImage::New( ); + input->SetRegions( size ); + input->Allocate( ); + input->FillBuffer( 0 ); + + TImage::RegionType region = input->GetLargestPossibleRegion( ); + TImage::PointType p0, p1, p2; + input->TransformIndexToPhysicalPoint( region.GetIndex( ), p0 ); + input->TransformIndexToPhysicalPoint( + region.GetIndex( ) + region.GetSize( ), p1 + ); + p2 = ( p0.GetVectorFromOrigin( ) + p1.GetVectorFromOrigin( ) ) * 0.5; + TImage::IndexType seed; + input->TransformPhysicalPointToIndex( p2, seed ); + + TFilter::Pointer filter = TFilter::New( ); + filter->SetInput( input ); + filter->SetInsideValue( 255 ); + filter->SetOutsideValue( 0 ); + filter->AddSeed( seed, filter->GetInsideValue( ) ); + + MyObserver::Pointer obs = MyObserver::New( ); + filter->AddObserver( itk::AnyEvent( ), obs ); + filter->Update( ); + + TWriter::Pointer writer = TWriter::New( ); + writer->SetInput( filter->GetOutput( ) ); + writer->SetFileName( "RegionGrow_00.png" ); + writer->Update( ); + + return( 0 ); +} + +// eof - $RCSfile$ diff --git a/lib/fpa/Base/Algorithm.h b/lib/fpa/Base/Algorithm.h index 662bdf1..297727a 100644 --- a/lib/fpa/Base/Algorithm.h +++ b/lib/fpa/Base/Algorithm.h @@ -78,6 +78,7 @@ namespace fpa virtual void GenerateData( ) fpa_OVERRIDE; // Particular methods + virtual bool _ContinueGenerateData( ); virtual void _Loop( ); virtual void _BeforeGenerateData( ); diff --git a/lib/fpa/Base/Algorithm.hxx b/lib/fpa/Base/Algorithm.hxx index 4ad828c..30f42b7 100644 --- a/lib/fpa/Base/Algorithm.hxx +++ b/lib/fpa/Base/Algorithm.hxx @@ -95,13 +95,23 @@ GenerateData( ) this->_InitResults( this->m_InitResult ); // Main loop - this->_Loop( ); + do + this->_Loop( ); + while( this->_ContinueGenerateData( ) ); } // fi this->_AfterGenerateData( ); this->InvokeEvent( TEndEvent( ) ); } +// ------------------------------------------------------------------------- +template < class _TFilter, class _TVertex, class _TOutput > +bool fpa::Base::Algorithm< _TFilter, _TVertex, _TOutput >:: +_ContinueGenerateData( ) +{ + return( false ); +} + // ------------------------------------------------------------------------- template < class _TFilter, class _TVertex, class _TOutput > void fpa::Base::Algorithm< _TFilter, _TVertex, _TOutput >:: diff --git a/lib/fpa/Base/Functors/RegionGrow/Base.h b/lib/fpa/Base/Functors/RegionGrow/Base.h new file mode 100644 index 0000000..7daf46e --- /dev/null +++ b/lib/fpa/Base/Functors/RegionGrow/Base.h @@ -0,0 +1,60 @@ +#ifndef __fpa__Base__Functors__RegionGrow__Base__h__ +#define __fpa__Base__Functors__RegionGrow__Base__h__ + +#include +#include + +namespace fpa +{ + namespace Base + { + namespace Functors + { + namespace RegionGrow + { + /** + */ + template< class _TVertex > + class Base + : public itk::Object + { + public: + typedef Base Self; + typedef itk::Object Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + typedef _TVertex TVertex; + + public: + itkTypeMacro( Base, itk::Object ); + + public: + virtual bool Evaluate( + const TVertex& a, const TVertex& b + ) const = 0; + + protected: + Base( ) + : Superclass( ) + { } + virtual ~Base( ) + { } + + private: + // Purposely not defined + Base( const Self& other ); + Self& operator=( const Self& other ); + }; + + } // ecapseman + + } // ecapseman + + } // ecapseman + +} // ecapseman + +#endif // __fpa__Base__Functors__RegionGrow__Base__h__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Base/Functors/RegionGrow/Tautology.h b/lib/fpa/Base/Functors/RegionGrow/Tautology.h new file mode 100644 index 0000000..744d618 --- /dev/null +++ b/lib/fpa/Base/Functors/RegionGrow/Tautology.h @@ -0,0 +1,63 @@ +#ifndef __fpa__Base__Functors__RegionGrow__Tautology__h__ +#define __fpa__Base__Functors__RegionGrow__Tautology__h__ + +#include + +namespace fpa +{ + namespace Base + { + namespace Functors + { + namespace RegionGrow + { + /** + */ + template< class _TVertex > + class Tautology + : public Base< _TVertex > + { + public: + typedef Tautology Self; + typedef Base< _TVertex > Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + typedef typename Superclass::TVertex TVertex; + + public: + itkNewMacro( Self ); + itkTypeMacro( Tautology, Base ); + + public: + virtual bool Evaluate( + const TVertex& a, const TVertex& b + ) const override + { + return( true ); + } + + protected: + Tautology( ) + : Superclass( ) + { } + virtual ~Tautology( ) + { } + + private: + // Purposely not defined + Tautology( const Self& other ); + Self& operator=( const Self& other ); + }; + + } // ecapseman + + } // ecapseman + + } // ecapseman + +} // ecapseman + +#endif // __fpa__Base__Functors__RegionGrow__Tautology__h__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Base/MoriRegionGrow.h b/lib/fpa/Base/MoriRegionGrow.h new file mode 100644 index 0000000..40f59cd --- /dev/null +++ b/lib/fpa/Base/MoriRegionGrow.h @@ -0,0 +1,61 @@ +#ifndef __fpa__Base__MoriRegionGrow__h__ +#define __fpa__Base__MoriRegionGrow__h__ + +#include +#include +#include + +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 +#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 new file mode 100644 index 0000000..9e1c300 --- /dev/null +++ b/lib/fpa/Base/MoriRegionGrow.hxx @@ -0,0 +1,33 @@ +#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$ diff --git a/lib/fpa/Base/RegionGrow.h b/lib/fpa/Base/RegionGrow.h index 5cd36de..2ef0703 100644 --- a/lib/fpa/Base/RegionGrow.h +++ b/lib/fpa/Base/RegionGrow.h @@ -3,7 +3,7 @@ #include #include -#include +#include namespace fpa { @@ -24,7 +24,7 @@ namespace fpa typedef typename Superclass::TOutput TOutput; typedef typename Superclass::TVertex TVertex; - typedef fpa::Base::RegionGrowFunctionBase< TVertex > TGrowFunction; + typedef fpa::Base::Functors::RegionGrow::Base< TVertex > TGrowFunction; protected: typedef typename Superclass::_TQueueNode _TQueueNode; diff --git a/lib/fpa/Base/RegionGrow.hxx b/lib/fpa/Base/RegionGrow.hxx index b0beaf2..e7dba1f 100644 --- a/lib/fpa/Base/RegionGrow.hxx +++ b/lib/fpa/Base/RegionGrow.hxx @@ -1,6 +1,8 @@ #ifndef __fpa__Base__RegionGrow__hxx__ #define __fpa__Base__RegionGrow__hxx__ +#include + // ------------------------------------------------------------------------- template< class _TSuperclass > fpa::Base::RegionGrow< _TSuperclass >:: @@ -10,6 +12,9 @@ RegionGrow( ) m_OutsideValue( TOutput( 0 ) ) { this->m_InitResult = TOutput( 0 ); + this->SetGrowFunction( + fpa::Base::Functors::RegionGrow::Tautology< TVertex >::New( ) + ); } // ------------------------------------------------------------------------- diff --git a/lib/fpa/Base/RegionGrowFunctionBase.h b/lib/fpa/Base/RegionGrowFunctionBase.h deleted file mode 100644 index 5c2ef52..0000000 --- a/lib/fpa/Base/RegionGrowFunctionBase.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef __fpa__Base__RegionGrowFunctionBase__h__ -#define __fpa__Base__RegionGrowFunctionBase__h__ - -#include -#include - -namespace fpa -{ - namespace Base - { - /** - */ - template< class _TVertex > - class RegionGrowFunctionBase - : public itk::Object - { - public: - typedef RegionGrowFunctionBase Self; - typedef itk::Object Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - - typedef _TVertex TVertex; - - public: - itkTypeMacro( RegionGrowFunctionBase, itk::Object ); - - public: - virtual bool Evaluate( const TVertex& a, const TVertex& b ) const = 0; - - protected: - RegionGrowFunctionBase( ) - : Superclass( ) - { } - virtual ~RegionGrowFunctionBase( ) - { } - - private: - // Purposely not defined - RegionGrowFunctionBase( const Self& other ); - Self& operator=( const Self& other ); - }; - - } // ecapseman - -} // ecapseman - -#endif // __fpa__Base__RegionGrowFunctionBase__h__ - -// eof - $RCSfile$ diff --git a/lib/fpa/Image/Functors/RegionGrow/BinaryThreshold.h b/lib/fpa/Image/Functors/RegionGrow/BinaryThreshold.h new file mode 100644 index 0000000..78c42a7 --- /dev/null +++ b/lib/fpa/Image/Functors/RegionGrow/BinaryThreshold.h @@ -0,0 +1,74 @@ +#ifndef __fpa__Image__Functors__RegionGrow__BinaryThreshold__h__ +#define __fpa__Image__Functors__RegionGrow__BinaryThreshold__h__ + +#include +#include + +namespace fpa +{ + namespace Image + { + namespace Functors + { + namespace RegionGrow + { + /** + */ + template< class _TImage > + class BinaryThreshold + : public fpa::Image::Functors::Base< _TImage, fpa::Base::Functors::RegionGrow::Base< typename _TImage::IndexType > > + { + public: + typedef _TImage TImage; + typedef typename TImage::IndexType TIndex; + typedef typename TImage::PixelType TPixel; + + typedef fpa::Base::Functors::RegionGrow::Base< TIndex > TBase; + typedef fpa::Image::Functors::Base< TImage, TBase > Superclass; + typedef BinaryThreshold Self; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + public: + itkNewMacro( Self ); + itkTypeMacro( BinaryThreshold, Base ); + + itkGetConstMacro( Lower, TPixel ); + itkGetConstMacro( Upper, TPixel ); + itkSetMacro( Lower, TPixel ); + itkSetMacro( Upper, TPixel ); + + public: + virtual bool Evaluate( + const TIndex& a, const TIndex& b + ) const override; + + protected: + BinaryThreshold( ); + virtual ~BinaryThreshold( ); + + private: + // Purposely not implemented + BinaryThreshold( const Self& other ); + Self& operator=( const Self& other ); + + protected: + TPixel m_Lower; + TPixel m_Upper; + }; + + } // ecapseman + + } // ecapseman + + } // ecapseman + +} // ecapseman + +#ifndef ITK_MANUAL_INSTANTIATION +# include +#endif // ITK_MANUAL_INSTANTIATION + +#endif // __fpa__Image__Functors__RegionGrow__BinaryThreshold__h__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Image/Functors/RegionGrow/BinaryThreshold.hxx b/lib/fpa/Image/Functors/RegionGrow/BinaryThreshold.hxx new file mode 100644 index 0000000..97cf465 --- /dev/null +++ b/lib/fpa/Image/Functors/RegionGrow/BinaryThreshold.hxx @@ -0,0 +1,44 @@ +#ifndef __fpa__Image__Functors__RegionGrow__BinaryThreshold__hxx__ +#define __fpa__Image__Functors__RegionGrow__BinaryThreshold__hxx__ + +#include + +// ------------------------------------------------------------------------- +template< class _TImage > +bool fpa::Image::Functors::RegionGrow::BinaryThreshold< _TImage >:: +Evaluate( const TIndex& a, const TIndex& b ) const +{ + const _TImage* im = + dynamic_cast< const _TImage* >( this->m_Image.GetPointer( ) ); + if( im != NULL ) + { + TPixel v = im->GetPixel( b ); + return( this->m_Lower <= v && v <= this->m_Upper ); + } + else + return( false ); +} + +// ------------------------------------------------------------------------- +template< class _TImage > +fpa::Image::Functors::RegionGrow::BinaryThreshold< _TImage >:: +BinaryThreshold( ) + : Superclass( ) +{ + 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; +} + +// ------------------------------------------------------------------------- +template< class _TImage > +fpa::Image::Functors::RegionGrow::BinaryThreshold< _TImage >:: +~BinaryThreshold( ) +{ +} + +#endif // __fpa__Image__Functors__RegionGrow__BinaryThreshold__hxx__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Image/Functors/RegionGrowBinaryThreshold.h b/lib/fpa/Image/Functors/RegionGrowBinaryThreshold.h deleted file mode 100644 index 201e3d8..0000000 --- a/lib/fpa/Image/Functors/RegionGrowBinaryThreshold.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef __fpa__Image__Functors__RegionGrowBinaryThreshold__h__ -#define __fpa__Image__Functors__RegionGrowBinaryThreshold__h__ - -#include -#include - -namespace fpa -{ - namespace Image - { - namespace Functors - { - /** - */ - template< class _TImage > - class RegionGrowBinaryThreshold - : public fpa::Image::Functors::Base< _TImage, fpa::Base::RegionGrowFunctionBase< typename _TImage::IndexType > > - { - public: - typedef _TImage TImage; - typedef typename TImage::IndexType TIndex; - typedef typename TImage::PixelType TPixel; - - typedef fpa::Base::RegionGrowFunctionBase< TIndex > TBaseFunctor; - typedef fpa::Image::Functors::Base< TImage, TBaseFunctor > Superclass; - typedef RegionGrowBinaryThreshold Self; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - - public: - itkNewMacro( Self ); - itkTypeMacro( RegionGrowBinaryThreshold, Base ); - - itkGetConstMacro( LowerThreshold, TPixel ); - itkGetConstMacro( UpperThreshold, TPixel ); - itkSetMacro( LowerThreshold, TPixel ); - itkSetMacro( UpperThreshold, TPixel ); - - public: - virtual bool Evaluate( - const TIndex& a, const TIndex& b - ) const fpa_OVERRIDE; - - protected: - RegionGrowBinaryThreshold( ); - virtual ~RegionGrowBinaryThreshold( ); - - private: - // Purposely not implemented - RegionGrowBinaryThreshold( const Self& other ); - Self& operator=( const Self& other ); - - protected: - TPixel m_LowerThreshold; - TPixel m_UpperThreshold; - }; - - } // ecapseman - - } // ecapseman - -} // ecapseman - -#ifndef ITK_MANUAL_INSTANTIATION -# include -#endif // ITK_MANUAL_INSTANTIATION - -#endif // __fpa__Image__Functors__RegionGrowBinaryThreshold__h__ - -// eof - $RCSfile$ diff --git a/lib/fpa/Image/Functors/RegionGrowBinaryThreshold.hxx b/lib/fpa/Image/Functors/RegionGrowBinaryThreshold.hxx deleted file mode 100644 index 53e3b2e..0000000 --- a/lib/fpa/Image/Functors/RegionGrowBinaryThreshold.hxx +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef __fpa__Image__Functors__RegionGrowBinaryThreshold__hxx__ -#define __fpa__Image__Functors__RegionGrowBinaryThreshold__hxx__ - -// ------------------------------------------------------------------------- -template< class _TImage > -bool fpa::Image::Functors::RegionGrowBinaryThreshold< _TImage >:: -Evaluate( const TIndex& a, const TIndex& b ) const -{ - const _TImage* im = - dynamic_cast< const _TImage* >( this->m_Image.GetPointer( ) ); - TPixel v = im->GetPixel( b ); - return( this->m_LowerThreshold <= v && v <= this->m_UpperThreshold ); -} - -// ------------------------------------------------------------------------- -template< class _TImage > -fpa::Image::Functors::RegionGrowBinaryThreshold< _TImage >:: -RegionGrowBinaryThreshold( ) - : Superclass( ), - m_LowerThreshold( TPixel( 0 ) ), - m_UpperThreshold( std::numeric_limits< TPixel >::max( ) ) -{ -} - -// ------------------------------------------------------------------------- -template< class _TImage > -fpa::Image::Functors::RegionGrowBinaryThreshold< _TImage >:: -~RegionGrowBinaryThreshold( ) -{ -} - -#endif // __fpa__Image__Functors__RegionGrowBinaryThreshold__hxx__ - -// eof - $RCSfile$ diff --git a/lib/fpa/Image/MoriRegionGrow.h b/lib/fpa/Image/MoriRegionGrow.h new file mode 100644 index 0000000..5708582 --- /dev/null +++ b/lib/fpa/Image/MoriRegionGrow.h @@ -0,0 +1,55 @@ +#ifndef __fpa__Image__MoriRegionGrow__h__ +#define __fpa__Image__MoriRegionGrow__h__ + +#include +#include + +namespace fpa +{ + namespace Image + { + /** + */ + template< class _TInputImage, class _TOutputImage > + class MoriRegionGrow + : public fpa::Base::MoriRegionGrow< fpa::Image::Algorithm< _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 typename Superclass::TOutput TOutput; + typedef typename Superclass::TVertex TVertex; + + typedef fpa::Image::Functors::Base< _TInputImage, typename Superclass::TGrowFunction > TGrowFunction; + + public: + itkNewMacro( Self ); + itkTypeMacro( fpa::Image::MoriRegionGrow, fpa::Base::MoriRegionGrow ); + + protected: + MoriRegionGrow( ); + virtual ~MoriRegionGrow( ); + + virtual void _BeforeGenerateData( ) fpa_OVERRIDE; + + private: + // Purposely not defined + MoriRegionGrow( const Self& other ); + Self& operator=( const Self& other ); + }; + + } // ecapseman + +} // ecapseman + +#ifndef ITK_MANUAL_INSTANTIATION +# include +#endif // ITK_MANUAL_INSTANTIATION + +#endif // __fpa__Image__MoriRegionGrow__h__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Image/MoriRegionGrow.hxx b/lib/fpa/Image/MoriRegionGrow.hxx new file mode 100644 index 0000000..29f46ac --- /dev/null +++ b/lib/fpa/Image/MoriRegionGrow.hxx @@ -0,0 +1,34 @@ +#ifndef __fpa__Image__MoriRegionGrow__hxx__ +#define __fpa__Image__MoriRegionGrow__hxx__ + +// ------------------------------------------------------------------------- +template< class _TInputImage, class _TOutputImage > +fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >:: +MoriRegionGrow( ) + : Superclass( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TInputImage, class _TOutputImage > +fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >:: +~MoriRegionGrow( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TInputImage, class _TOutputImage > +void fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >:: +_BeforeGenerateData( ) +{ + this->Superclass::_BeforeGenerateData( ); + + TGrowFunction* grow = + dynamic_cast< TGrowFunction* >( this->GetGrowFunction( ) ); + if( grow != NULL ) + grow->SetImage( this->GetInput( ) ); +} + +#endif // __fpa__Image__MoriRegionGrow__hxx__ + +// eof - $RCSfile$ diff --git a/plugins/ImageAlgorithms/ImageAlgorithms.i b/plugins/ImageAlgorithms/ImageAlgorithms.i index 9655ca3..9f44dd1 100644 --- a/plugins/ImageAlgorithms/ImageAlgorithms.i +++ b/plugins/ImageAlgorithms/ImageAlgorithms.i @@ -4,9 +4,12 @@ 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 instances fpa::Image::RegionGrow< itk::Image< #scalar_types#, #pdims# >, itk::Image< #all_int_types#, #pdims# > > +instances fpa::Image::MoriRegionGrow< itk::Image< #scalar_types#, #pdims# >, itk::Image< #all_int_types#, #pdims# > > cinclude fpa/Base/Dijkstra.hxx tinclude fpa/Image/Dijkstra:h|hxx diff --git a/plugins/ImageAlgorithms/MoriRegionGrow.cxx b/plugins/ImageAlgorithms/MoriRegionGrow.cxx new file mode 100644 index 0000000..c12e855 --- /dev/null +++ b/plugins/ImageAlgorithms/MoriRegionGrow.cxx @@ -0,0 +1,74 @@ +#include +#include + +#include + +// ------------------------------------------------------------------------- +fpaPluginsImageAlgorithms::MoriRegionGrow:: +MoriRegionGrow( ) + : Superclass( ) +{ + typedef cpPlugins::Pipeline::DataObject _TData; + + this->_ConfigureInput< _TData >( "GrowFunction", true, false ); + this->m_Parameters.ConfigureAsInt( "InsideValue", 1 ); + this->m_Parameters.ConfigureAsInt( "OutsideValue", 0 ); + this->m_Parameters.ConfigureAsInt( "Step", 1 ); + this->m_Parameters.ConfigureAsReal( "LowerThreshold", 1 ); + this->m_Parameters.ConfigureAsReal( "UpperThreshold", 1 ); + this->m_Parameters.ConfigureAsIntTypesChoices( "ResultType" ); +} + +// ------------------------------------------------------------------------- +fpaPluginsImageAlgorithms::MoriRegionGrow:: +~MoriRegionGrow( ) +{ +} + +// ------------------------------------------------------------------------- +void fpaPluginsImageAlgorithms::MoriRegionGrow:: +_GenerateData( ) +{ + auto o = this->GetInputData( "Input" ); + cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 ) + this->_Error( "Invalid input image." ); +} + +// ------------------------------------------------------------------------- +template< class _TImage > +void fpaPluginsImageAlgorithms::MoriRegionGrow:: +_GD0( _TImage* image ) +{ + auto rtype = this->m_Parameters.GetSelectedChoice( "ResultType" ); + if( rtype == "char" ) this->_GD1< _TImage, char >( image ); + else if( rtype == "uchar" ) this->_GD1< _TImage, unsigned char >( image ); + else if( rtype == "short" ) this->_GD1< _TImage, short >( image ); + else if( rtype == "ushort" ) this->_GD1< _TImage, unsigned short >( image ); + else if( rtype == "int" ) this->_GD1< _TImage, int >( image ); + else if( rtype == "uint" ) this->_GD1< _TImage, unsigned int >( image ); + else if( rtype == "long" ) this->_GD1< _TImage, long >( image ); + else if( rtype == "ulong" ) this->_GD1< _TImage, unsigned long >( image ); + else this->_GD1< _TImage, char >( image ); +} + +// ------------------------------------------------------------------------- +template< class _TInputImage, class _TOutputPixel > +void fpaPluginsImageAlgorithms::MoriRegionGrow:: +_GD1( _TInputImage* image ) +{ + typedef + itk::Image< _TOutputPixel, _TInputImage::ImageDimension > + _TOutputImage; + typedef fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage > _TFilter; + typedef typename _TFilter::TGrowFunction _TGrow; + + auto filter = this->_CreateITK< _TFilter >( ); + this->_ConfigureFilter( filter, image ); + filter->SetGrowFunction( this->GetInputData< _TGrow >( "GrowFunction" ) ); + filter->SetInsideValue( this->m_Parameters.GetInt( "InsideValue" ) ); + filter->SetOutsideValue( this->m_Parameters.GetInt( "OutsideValue" ) ); + filter->Update( ); + this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); +} + +// eof - $RCSfile$ diff --git a/plugins/ImageAlgorithms/MoriRegionGrow.h b/plugins/ImageAlgorithms/MoriRegionGrow.h new file mode 100644 index 0000000..653bd3d --- /dev/null +++ b/plugins/ImageAlgorithms/MoriRegionGrow.h @@ -0,0 +1,27 @@ +#ifndef __fpaPluginsImageAlgorithms__MoriRegionGrow__h__ +#define __fpaPluginsImageAlgorithms__MoriRegionGrow__h__ + +#include + +namespace fpaPluginsImageAlgorithms +{ + /** + */ + class fpaPluginsImageAlgorithms_EXPORT MoriRegionGrow + : public BaseFilter + { + cpPluginsObject( MoriRegionGrow, BaseFilter, fpaImageAlgorithms ); + + protected: + template< class _TImage > + inline void _GD0( _TImage* image ); + + template< class _TInputImage, class _TOutputPixel > + inline void _GD1( _TInputImage* image ); + }; + +} // ecapseman + +#endif // __fpaPluginsImageAlgorithms__MoriRegionGrow__h__ + +// eof - $RCSfile$ diff --git a/plugins/RegionGrowFunctors/BinaryThreshold.cxx b/plugins/RegionGrowFunctors/BinaryThreshold.cxx index 9ed2db6..f385e4a 100644 --- a/plugins/RegionGrowFunctors/BinaryThreshold.cxx +++ b/plugins/RegionGrowFunctors/BinaryThreshold.cxx @@ -1,7 +1,7 @@ #include #include -#include +#include #include #include @@ -18,8 +18,8 @@ BinaryThreshold( ) this->_ConfigureOutput< _TData >( "Output" ); this->m_Parameters.ConfigureAsUint( "Radius", 1 ); - this->m_Parameters.ConfigureAsReal( "LowerThreshold", 0 ); - this->m_Parameters.ConfigureAsReal( "UpperThreshold", 0 ); + this->m_Parameters.ConfigureAsReal( "Lower", 0 ); + this->m_Parameters.ConfigureAsReal( "Upper", 0 ); } // ------------------------------------------------------------------------- @@ -44,7 +44,7 @@ _GD0( _TImage* image ) { typedef itk::ConstNeighborhoodIterator< _TImage > _TInIt; typedef - fpa::Image::Functors::RegionGrowBinaryThreshold< _TImage > + fpa::Image::Functors::RegionGrow::BinaryThreshold< _TImage > _TFunctor; auto out = this->GetOutput( "Output" ); auto f = out->GetITK< _TFunctor >( ); @@ -107,15 +107,15 @@ _GD0( _TImage* image ) s = std::sqrt( s ); v_min = m - s; v_max = m + s; - f->SetLowerThreshold( v_min ); - f->SetUpperThreshold( v_max ); - this->m_Parameters.SetReal( "LowerThreshold", f->GetLowerThreshold( ) ); - this->m_Parameters.SetReal( "UpperThreshold", f->GetUpperThreshold( ) ); + f->SetLower( v_min ); + f->SetUpper( v_max ); + this->m_Parameters.SetReal( "Lower", f->GetLower( ) ); + this->m_Parameters.SetReal( "Upper", f->GetUpper( ) ); } else { - f->SetLowerThreshold( this->m_Parameters.GetReal( "LowerThreshold" ) ); - f->SetUpperThreshold( this->m_Parameters.GetReal( "UpperThreshold" ) ); + f->SetLower( this->m_Parameters.GetReal( "Lower" ) ); + f->SetUpper( this->m_Parameters.GetReal( "Upper" ) ); } // fi } diff --git a/plugins/RegionGrowFunctors/RegionGrowFunctors.i b/plugins/RegionGrowFunctors/RegionGrowFunctors.i index c310a00..e43240d 100644 --- a/plugins/RegionGrowFunctors/RegionGrowFunctors.i +++ b/plugins/RegionGrowFunctors/RegionGrowFunctors.i @@ -1,7 +1,7 @@ header #define ITK_MANUAL_INSTANTIATION cinclude itkImage.h -tinclude fpa/Image/Functors/RegionGrowBinaryThreshold:h|hxx -instances fpa::Image::Functors::RegionGrowBinaryThreshold< itk::Image< #scalar_types#, #pdims# > > +tinclude fpa/Image/Functors/RegionGrow/BinaryThreshold:h|hxx +instances fpa::Image::Functors::RegionGrow::BinaryThreshold< itk::Image< #scalar_types#, #pdims# > > ** eof - $RCSfile$