From fa473b0493ad1f4b6e2fb15b180fc32c67e9c712 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leonardo=20Fl=C3=B3rez-Valencia?= Date: Tue, 21 Mar 2017 17:55:50 -0500 Subject: [PATCH] ... --- libs/fpa/Base/SeedsInterface.h | 56 +++++++++++++++++ libs/fpa/Base/SeedsInterface.hxx | 100 +++++++++++++++++++++++++++++++ libs/fpa/Image/RegionGrow.h | 24 ++++---- libs/fpa/Image/RegionGrow.hxx | 12 +--- 4 files changed, 170 insertions(+), 22 deletions(-) create mode 100644 libs/fpa/Base/SeedsInterface.h create mode 100644 libs/fpa/Base/SeedsInterface.hxx diff --git a/libs/fpa/Base/SeedsInterface.h b/libs/fpa/Base/SeedsInterface.h new file mode 100644 index 0000000..a994125 --- /dev/null +++ b/libs/fpa/Base/SeedsInterface.h @@ -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 +#include + +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 +#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 index 0000000..4e20760 --- /dev/null +++ b/libs/fpa/Base/SeedsInterface.hxx @@ -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$ diff --git a/libs/fpa/Image/RegionGrow.h b/libs/fpa/Image/RegionGrow.h index 6981f75..e21bbb9 100644 --- a/libs/fpa/Image/RegionGrow.h +++ b/libs/fpa/Image/RegionGrow.h @@ -8,7 +8,7 @@ #include #include -#include +#include 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; }; diff --git a/libs/fpa/Image/RegionGrow.hxx b/libs/fpa/Image/RegionGrow.hxx index 0cf74de..facd9f8 100644 --- a/libs/fpa/Image/RegionGrow.hxx +++ b/libs/fpa/Image/RegionGrow.hxx @@ -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 -- 2.45.0