From fe01e92d9bce3519fa2a0936b6180ca7b057a87a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leonardo=20Fl=C3=B3rez-Valencia?= Date: Thu, 22 Jun 2017 07:35:50 -0500 Subject: [PATCH] ... --- lib/fpa/Base/Algorithm.h | 1 + lib/fpa/Base/Algorithm.hxx | 8 ++- lib/fpa/Base/Dijkstra.h | 2 + lib/fpa/Base/Dijkstra.hxx | 25 ++++--- lib/fpa/Base/DijkstraBase.h | 3 +- lib/fpa/Base/DijkstraBase.hxx | 22 +++--- lib/fpa/Base/RegionGrow.h | 3 +- lib/fpa/Base/RegionGrow.hxx | 22 +++--- lib/fpa/Base/SeedsInterface.h | 24 +++++-- lib/fpa/Base/SeedsInterface.hxx | 86 +++++++----------------- lib/fpa/Image/Algorithm.h | 4 ++ lib/fpa/Image/Algorithm.hxx | 48 +++++++++++-- lib/fpa/Image/Dijkstra.h | 5 +- lib/fpa/Image/LabelledSeedsInterface.h | 8 ++- lib/fpa/Image/LabelledSeedsInterface.hxx | 38 ++++++++--- lib/fpa/Image/RandomWalker.h | 9 ++- lib/fpa/Image/RandomWalker.hxx | 27 +++++--- lib/fpa/Image/RegionGrow.h | 8 ++- 18 files changed, 204 insertions(+), 139 deletions(-) diff --git a/lib/fpa/Base/Algorithm.h b/lib/fpa/Base/Algorithm.h index e5b6f2b..8750c5f 100644 --- a/lib/fpa/Base/Algorithm.h +++ b/lib/fpa/Base/Algorithm.h @@ -35,6 +35,7 @@ namespace fpa typedef typename _TSeedsInterface::TInputValue TInputValue; typedef typename _TSeedsInterface::TOutputValue TOutputValue; typedef typename _TSeedsInterface::TNode TNode; + typedef typename _TSeedsInterface::TNodes TNodes; typedef typename _TSeedsInterface::TSeeds TSeeds; typedef typename _TSeedsInterface::TVertex TVertex; diff --git a/lib/fpa/Base/Algorithm.hxx b/lib/fpa/Base/Algorithm.hxx index 383db74..44d2520 100644 --- a/lib/fpa/Base/Algorithm.hxx +++ b/lib/fpa/Base/Algorithm.hxx @@ -117,12 +117,14 @@ GenerateData( ) // Init objects this->_BeforeGenerateData( ); this->_ConfigureOutput( this->m_InitValue ); - this->_InitMarks( this->GetNumberOfSeeds( ) ); + this->_InitMarks( this->GetSeeds( ).size( ) ); + TNodes seeds = this->_UnifySeeds( ); + this->_PrepareSeeds( seeds ); // Init queue this->_QueueInit( ); - typename TSeeds::const_iterator sIt = this->BeginSeeds( ); - for( ; sIt != this->EndSeeds( ); ++sIt ) + typename TNodes::const_iterator sIt = seeds.begin( ); + for( ; sIt != seeds.end( ); ++sIt ) { this->_QueuePush( *sIt ); this->InvokeEvent( TEvent( sIt->Vertex, sIt->FrontId, true ) ); diff --git a/lib/fpa/Base/Dijkstra.h b/lib/fpa/Base/Dijkstra.h index 10489db..c93d575 100644 --- a/lib/fpa/Base/Dijkstra.h +++ b/lib/fpa/Base/Dijkstra.h @@ -27,10 +27,12 @@ namespace fpa typedef _TMST TMST; typedef typename Superclass::TNode TNode; + typedef typename Superclass::TNodes TNodes; typedef typename Superclass::TInputValue TInputValue; typedef typename Superclass::TOutputValue TOutputValue; typedef typename Superclass::TFrontId TFrontId; typedef typename Superclass::TVertex TVertex; + typedef typename Superclass::TSeeds TSeeds; typedef typename Superclass::TQueue TQueue; typedef typename Superclass::TQueueOrder TQueueOrder; diff --git a/lib/fpa/Base/Dijkstra.hxx b/lib/fpa/Base/Dijkstra.hxx index 40058e1..be35981 100644 --- a/lib/fpa/Base/Dijkstra.hxx +++ b/lib/fpa/Base/Dijkstra.hxx @@ -12,8 +12,10 @@ typename fpa::Base::Dijkstra< _TAlgorithm, _TMST >:: TMST* fpa::Base::Dijkstra< _TAlgorithm, _TMST >:: GetMinimumSpanningTree( ) { - dynamic_cast< TMST* >( - this->itk::ProcessObject::GetOutput( this->m_MSTIdx ) + return( + dynamic_cast< TMST* >( + this->itk::ProcessObject::GetOutput( this->m_MSTIdx ) + ) ); } @@ -23,8 +25,10 @@ const typename fpa::Base::Dijkstra< _TAlgorithm, _TMST >:: TMST* fpa::Base::Dijkstra< _TAlgorithm, _TMST >:: GetMinimumSpanningTree( ) const { - dynamic_cast< const TMST* >( - this->itk::ProcessObject::GetOutput( this->m_MSTIdx ) + return( + dynamic_cast< const TMST* >( + this->itk::ProcessObject::GetOutput( this->m_MSTIdx ) + ) ); } @@ -51,15 +55,20 @@ template< class _TAlgorithm, class _TMST > void fpa::Base::Dijkstra< _TAlgorithm, _TMST >:: _AfterGenerateData( ) { - typedef typename Superclass::TSeedsInterface::TSeeds::iterator _TIt; - this->Superclass::_AfterGenerateData( ); TMST* mst = this->GetMinimumSpanningTree( ); mst->ClearSeeds( ); mst->SetCollisions( this->m_Collisions ); - for( _TIt sIt = this->BeginSeeds( ); sIt != this->EndSeeds( ); ++sIt ) - mst->AddSeed( sIt->Vertex ); + + TSeeds seeds = this->GetSeeds( ); + typename TSeeds::const_iterator sIt = seeds.begin( ); + for( ; sIt != seeds.end( ); ++sIt ) + { + if( sIt->IsUnified ) + mst->AddSeed( sIt->Vertex ); + + } // rof } // ------------------------------------------------------------------------- diff --git a/lib/fpa/Base/DijkstraBase.h b/lib/fpa/Base/DijkstraBase.h index fd36890..8878bb7 100644 --- a/lib/fpa/Base/DijkstraBase.h +++ b/lib/fpa/Base/DijkstraBase.h @@ -28,6 +28,7 @@ namespace fpa typedef itk::SmartPointer< const Self > ConstPointer; typedef typename _TAlgorithm::TNode TNode; + typedef typename _TAlgorithm::TNodes TNodes; typedef typename _TAlgorithm::TInputValue TInputValue; typedef typename _TAlgorithm::TOutputValue TOutputValue; typedef typename _TAlgorithm::TVertex TVertex; @@ -60,11 +61,11 @@ namespace fpa virtual ~DijkstraBase( ); virtual TOutputValue _ComputeOutputValue( const TNode& n ) override; - virtual void _QueueInit( ) override; virtual void _QueueClear( ) override; virtual TNode _QueuePop( ) override; virtual void _QueuePush( const TNode& node ) override; virtual unsigned long _QueueSize( ) const override; + virtual void _PrepareSeeds( TNodes& nodes ) override; private: // Purposely not implemented. diff --git a/lib/fpa/Base/DijkstraBase.hxx b/lib/fpa/Base/DijkstraBase.hxx index a78554b..6f4937e 100644 --- a/lib/fpa/Base/DijkstraBase.hxx +++ b/lib/fpa/Base/DijkstraBase.hxx @@ -50,18 +50,6 @@ _ComputeOutputValue( const TNode& n ) return( c + this->_GetOutputValue( n.Parent ) ); } -// ------------------------------------------------------------------------- -template< class _TAlgorithm > -void fpa::Base::DijkstraBase< _TAlgorithm >:: -_QueueInit( ) -{ - typedef typename Superclass::TSeedsInterface::TSeeds::iterator _TIt; - - this->Superclass::_QueueInit( ); - for( _TIt sIt = this->BeginSeeds( ); sIt != this->EndSeeds( ); ++sIt ) - sIt->Value = TOutputValue( 0 ); -} - // ------------------------------------------------------------------------- template< class _TAlgorithm > void fpa::Base::DijkstraBase< _TAlgorithm >:: @@ -109,6 +97,16 @@ _QueueSize( ) const return( this->m_Queue.size( ) ); } +// ------------------------------------------------------------------------- +template< class _TAlgorithm > +void fpa::Base::DijkstraBase< _TAlgorithm >:: +_PrepareSeeds( TNodes& nodes ) +{ + typename TNodes::iterator nIt = nodes.begin( ); + for( ; nIt != nodes.end( ); ++nIt ) + nIt->Value = TOutputValue( 0 ); +} + #endif // __fpa__Base__DijkstraBase__hxx__ // eof - $RCSfile$ diff --git a/lib/fpa/Base/RegionGrow.h b/lib/fpa/Base/RegionGrow.h index 796c90b..34bb085 100644 --- a/lib/fpa/Base/RegionGrow.h +++ b/lib/fpa/Base/RegionGrow.h @@ -28,6 +28,7 @@ namespace fpa typedef itk::SmartPointer< const Self > ConstPointer; typedef typename _TAlgorithm::TNode TNode; + typedef typename _TAlgorithm::TNodes TNodes; typedef typename _TAlgorithm::TInputValue TInputValue; typedef typename _TAlgorithm::TOutputValue TOutputValue; typedef typename _TAlgorithm::TFrontId TFrontId; @@ -63,11 +64,11 @@ namespace fpa virtual ~RegionGrow( ); virtual TOutputValue _ComputeOutputValue( const TNode& n ) override; - virtual void _QueueInit( ) override; virtual void _QueueClear( ) override; virtual TNode _QueuePop( ) override; virtual void _QueuePush( const TNode& node ) override; virtual unsigned long _QueueSize( ) const override; + virtual void _PrepareSeeds( TNodes& nodes ) override; private: // Purposely not implemented. diff --git a/lib/fpa/Base/RegionGrow.hxx b/lib/fpa/Base/RegionGrow.hxx index 18bb132..247cf94 100644 --- a/lib/fpa/Base/RegionGrow.hxx +++ b/lib/fpa/Base/RegionGrow.hxx @@ -103,18 +103,6 @@ _ComputeOutputValue( const TNode& n ) return( ( inside )? this->m_InsideValue: this->m_InitValue ); } -// ------------------------------------------------------------------------- -template< class _TAlgorithm > -void fpa::Base::RegionGrow< _TAlgorithm >:: -_QueueInit( ) -{ - typedef typename Superclass::TSeedsInterface::TSeeds::iterator _TIt; - - this->Superclass::_QueueInit( ); - for( _TIt sIt = this->BeginSeeds( ); sIt != this->EndSeeds( ); ++sIt ) - sIt->Value = this->m_InsideValue; -} - // ------------------------------------------------------------------------- template< class _TAlgorithm > void fpa::Base::RegionGrow< _TAlgorithm >:: @@ -150,6 +138,16 @@ _QueueSize( ) const return( this->m_Queue.size( ) ); } +// ------------------------------------------------------------------------- +template< class _TAlgorithm > +void fpa::Base::RegionGrow< _TAlgorithm >:: +_PrepareSeeds( TNodes& nodes ) +{ + typename TNodes::iterator nIt = nodes.begin( ); + for( ; nIt != nodes.end( ); ++nIt ) + nIt->Value = this->m_InsideValue; +} + #endif // __fpa__Base__RegionGrow__hxx__ // eof - $RCSfile$ diff --git a/lib/fpa/Base/SeedsInterface.h b/lib/fpa/Base/SeedsInterface.h index e9c67c3..493b4db 100644 --- a/lib/fpa/Base/SeedsInterface.h +++ b/lib/fpa/Base/SeedsInterface.h @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -18,7 +19,7 @@ namespace fpa { /** */ - template< class _TVertex, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare = std::greater< _TVertex > > + template< class _TVertex, class _TPoint, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare = std::greater< _TVertex > > class SeedsInterface { public: @@ -29,12 +30,23 @@ namespace fpa public: typedef _TVertex TVertex; + typedef _TPoint TPoint; typedef _TInputValue TInputValue; typedef _TOutputValue TOutputValue; typedef _TFrontId TFrontId; typedef _TCompare TCompare; typedef SeedsInterface Self; + struct TSeed + { + TVertex Vertex; + TPoint Point; + bool IsPoint; + bool IsUnified; + TSeed( ) : IsUnified( false ) { } + }; + typedef std::vector< TSeed > TSeeds; + struct TNode { TVertex Vertex; @@ -52,22 +64,22 @@ namespace fpa return( cmp( a.Vertex, b.Vertex ) ); } }; - typedef std::set< TNode, TNodeCompare > TSeeds; + typedef std::set< TNode, TNodeCompare > TNodes; public: - unsigned int GetNumberOfSeeds( ) const; const TSeeds& GetSeeds( ) const; - typename TSeeds::const_iterator BeginSeeds( ) const; - typename TSeeds::const_iterator EndSeeds( ) const; virtual void AddSeed( const TVertex& seed ); - virtual void RemoveSeed( const TVertex& seed ); + virtual void AddSeed( const TPoint& seed ); virtual void ClearSeeds( ); protected: SeedsInterface( itk::ProcessObject* filter ); virtual ~SeedsInterface( ); + virtual TNodes _UnifySeeds( ) = 0; + virtual void _PrepareSeeds( TNodes& nodes ) = 0; + protected: TSeeds m_Seeds; itk::ProcessObject* m_Filter; diff --git a/lib/fpa/Base/SeedsInterface.hxx b/lib/fpa/Base/SeedsInterface.hxx index 5c27216..5dd666e 100644 --- a/lib/fpa/Base/SeedsInterface.hxx +++ b/lib/fpa/Base/SeedsInterface.hxx @@ -7,84 +7,48 @@ #define __fpa__Base__SeedsInterface__hxx__ // ------------------------------------------------------------------------- -template< class _TVertex, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > -unsigned int -fpa::Base::SeedsInterface< _TVertex, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: -GetNumberOfSeeds( ) const -{ - return( this->m_Seeds.size( ) ); -} - -// ------------------------------------------------------------------------- -template< class _TVertex, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > +template< class _TVertex, class _TPoint, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > const typename -fpa::Base::SeedsInterface< _TVertex, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: +fpa::Base::SeedsInterface< _TVertex, _TPoint, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: TSeeds& -fpa::Base::SeedsInterface< _TVertex, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: +fpa::Base::SeedsInterface< _TVertex, _TPoint, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: GetSeeds( ) const { return( this->m_Seeds ); } // ------------------------------------------------------------------------- -template< class _TVertex, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > -typename -fpa::Base::SeedsInterface< _TVertex, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: -TSeeds::const_iterator -fpa::Base::SeedsInterface< _TVertex, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: -BeginSeeds( ) const -{ - return( this->m_Seeds.begin( ) ); -} - -// ------------------------------------------------------------------------- -template< class _TVertex, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > -typename -fpa::Base::SeedsInterface< _TVertex, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: -TSeeds::const_iterator -fpa::Base::SeedsInterface< _TVertex, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: -EndSeeds( ) const -{ - return( this->m_Seeds.end( ) ); -} - -// ------------------------------------------------------------------------- -template< class _TVertex, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > +template< class _TVertex, class _TPoint, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > void -fpa::Base::SeedsInterface< _TVertex, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: +fpa::Base::SeedsInterface< _TVertex, _TPoint, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: AddSeed( const TVertex& seed ) { - TNode node; - node.Vertex = seed; - node.Parent = seed; - node.FrontId = TFrontId( this->m_Seeds.size( ) + 1 ); - if( this->m_Seeds.insert( node ).second && this->m_Filter != NULL ) + TSeed s; + s.Vertex = seed; + s.IsPoint = false; + this->m_Seeds.push_back( s ); + if( this->m_Filter != NULL ) this->m_Filter->Modified( ); } // ------------------------------------------------------------------------- -template< class _TVertex, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > +template< class _TVertex, class _TPoint, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > void -fpa::Base::SeedsInterface< _TVertex, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: -RemoveSeed( const TVertex& seed ) +fpa::Base::SeedsInterface< _TVertex, _TPoint, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: +AddSeed( const TPoint& seed ) { - TNode node; - node.Vertex = seed; - node.Parent = seed; - typename TSeeds::const_iterator i = this->m_Seeds.find( node ); - if( i != this->m_Seeds.end( ) ) - { - this->m_Seeds.erase( i ); - if( this->m_Filter != NULL ) - this->m_Filter->Modified( ); - - } // fi + TSeed s; + s.Point = seed; + s.IsPoint = true; + this->m_Seeds.push_back( s ); + if( this->m_Filter != NULL ) + this->m_Filter->Modified( ); } // ------------------------------------------------------------------------- -template< class _TVertex, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > +template< class _TVertex, class _TPoint, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > void -fpa::Base::SeedsInterface< _TVertex, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: +fpa::Base::SeedsInterface< _TVertex, _TPoint, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: ClearSeeds( ) { if( this->m_Seeds.size( ) > 0 ) @@ -97,16 +61,16 @@ ClearSeeds( ) } // ------------------------------------------------------------------------- -template< class _TVertex, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > -fpa::Base::SeedsInterface< _TVertex, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: +template< class _TVertex, class _TPoint, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > +fpa::Base::SeedsInterface< _TVertex, _TPoint, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: SeedsInterface( itk::ProcessObject* filter ) : m_Filter( filter ) { } // ------------------------------------------------------------------------- -template< class _TVertex, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > -fpa::Base::SeedsInterface< _TVertex, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: +template< class _TVertex, class _TPoint, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > +fpa::Base::SeedsInterface< _TVertex, _TPoint, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: ~SeedsInterface( ) { this->m_Seeds.clear( ); diff --git a/lib/fpa/Image/Algorithm.h b/lib/fpa/Image/Algorithm.h index 5547ff0..12a2f91 100644 --- a/lib/fpa/Image/Algorithm.h +++ b/lib/fpa/Image/Algorithm.h @@ -38,7 +38,10 @@ namespace fpa typedef typename Superclass::TFrontId TFrontId; typedef typename Superclass::TNeighborhood TNeighborhood; typedef typename Superclass::TNode TNode; + typedef typename Superclass::TNodes TNodes; + typedef typename Superclass::TSeeds TSeeds; typedef typename Superclass::TVertex TVertex; + typedef typename Superclass::TPoint TPoint; typedef itk::Image< TFrontId, TInputImage::ImageDimension > TMarks; @@ -56,6 +59,7 @@ namespace fpa Algorithm( ); virtual ~Algorithm( ); + virtual TNodes _UnifySeeds( ) override; virtual void _ConfigureOutput( const TOutputValue& v ) override; virtual TNeighborhood _GetNeighbors( const TVertex& v ) const override; virtual TInputValue _GetInputValue( const TVertex& v ) const override; diff --git a/lib/fpa/Image/Algorithm.hxx b/lib/fpa/Image/Algorithm.hxx index 0ae9b90..98592f6 100644 --- a/lib/fpa/Image/Algorithm.hxx +++ b/lib/fpa/Image/Algorithm.hxx @@ -14,8 +14,10 @@ TMarks* fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >:: GetMarks( ) { - dynamic_cast< TMarks* >( - this->itk::ProcessObject::GetOutput( this->m_MarksIdx ) + return( + dynamic_cast< TMarks* >( + this->itk::ProcessObject::GetOutput( this->m_MarksIdx ) + ) ); } @@ -27,8 +29,10 @@ TMarks* fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >:: GetMarks( ) const { - dynamic_cast< const TMarks* >( - this->itk::ProcessObject::GetOutput( this->m_MarksIdx ) + return( + dynamic_cast< const TMarks* >( + this->itk::ProcessObject::GetOutput( this->m_MarksIdx ) + ) ); } @@ -51,6 +55,42 @@ fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInt { } +// ------------------------------------------------------------------------- +template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface > +typename +fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >:: +TNodes fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >:: +_UnifySeeds( ) +{ + const TInputImage* input = this->GetInput( ); + typename TInputImage::RegionType region = input->GetRequestedRegion( ); + TSeeds seeds = this->GetSeeds( ); + TNodes nodes; + + typename TSeeds::iterator sIt = seeds.begin( ); + for( ; sIt != seeds.end( ); ++sIt ) + { + TNode node; + if( sIt->IsPoint ) + input->TransformPhysicalPointToIndex( sIt->Point, sIt->Vertex ); + else + input->TransformIndexToPhysicalPoint( sIt->Vertex, sIt->Point ); + if( region.IsInside( sIt->Vertex ) ) + { + sIt->IsUnified = true; + node.Vertex = sIt->Vertex; + node.Parent = node.Vertex; + node.FrontId = nodes.size( ) + 1; + nodes.insert( node ); + } + else + sIt->IsUnified = false; + + } // rof + + return( nodes ); +} + // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface > void diff --git a/lib/fpa/Image/Dijkstra.h b/lib/fpa/Image/Dijkstra.h index d5a1bb9..6882bfe 100644 --- a/lib/fpa/Image/Dijkstra.h +++ b/lib/fpa/Image/Dijkstra.h @@ -21,7 +21,7 @@ namespace fpa */ template< class _TInputImage, class _TOutputImage, class _TFrontId = unsigned char > class Dijkstra - : public fpa::Base::Dijkstra< fpa::Image::Algorithm< _TInputImage, _TOutputImage, fpa::Base::MarksInterfaceWithCollisions< typename _TInputImage::IndexType >, fpa::Base::SeedsInterface< typename _TInputImage::IndexType, typename _TInputImage::PixelType, typename _TOutputImage::PixelType, _TFrontId, typename _TInputImage::IndexType::LexicographicCompare > >, fpa::Image::MinimumSpanningTree< _TInputImage::ImageDimension > > + : public fpa::Base::Dijkstra< fpa::Image::Algorithm< _TInputImage, _TOutputImage, fpa::Base::MarksInterfaceWithCollisions< typename _TInputImage::IndexType >, fpa::Base::SeedsInterface< typename _TInputImage::IndexType, typename _TInputImage::PointType, typename _TInputImage::PixelType, typename _TOutputImage::PixelType, _TFrontId, typename _TInputImage::IndexType::LexicographicCompare > >, fpa::Image::MinimumSpanningTree< _TInputImage::ImageDimension > > { public: typedef _TInputImage TInputImage; @@ -29,12 +29,13 @@ namespace fpa typedef _TFrontId TFrontId; typedef typename TInputImage::IndexType TVertex; + typedef typename TInputImage::PointType TPoint; typedef typename TVertex::LexicographicCompare TVertexCompare; typedef typename TInputImage::PixelType TInputValue; typedef typename TOutputImage::PixelType TOutputValue; typedef fpa::Base::MarksInterfaceWithCollisions< TVertex > TMarksInterface; - typedef fpa::Base::SeedsInterface< TVertex, TInputValue, TOutputValue, TFrontId, TVertexCompare > TSeedsInterface; + typedef fpa::Base::SeedsInterface< TVertex, TPoint, TInputValue, TOutputValue, TFrontId, TVertexCompare > TSeedsInterface; typedef fpa::Image::Algorithm< TInputImage, TOutputImage, TMarksInterface, TSeedsInterface > TAlgorithm; typedef fpa::Image::MinimumSpanningTree< TInputImage::ImageDimension > TMST; diff --git a/lib/fpa/Image/LabelledSeedsInterface.h b/lib/fpa/Image/LabelledSeedsInterface.h index 2492b84..74ec756 100644 --- a/lib/fpa/Image/LabelledSeedsInterface.h +++ b/lib/fpa/Image/LabelledSeedsInterface.h @@ -16,18 +16,19 @@ namespace fpa { /** */ - template< class _TVertex, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare = std::greater< _TVertex > > + template< class _TVertex, class _TPoint, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare = std::greater< _TVertex > > class LabelledSeedsInterface - : public fpa::Base::SeedsInterface< _TVertex, _TInputValue, _TOutputValue, _TFrontId, _TCompare > + : public fpa::Base::SeedsInterface< _TVertex, _TPoint, _TInputValue, _TOutputValue, _TFrontId, _TCompare > { public: typedef _TVertex TVertex; + typedef _TPoint TPoint; typedef _TInputValue TInputValue; typedef _TOutputValue TOutputValue; typedef _TFrontId TFrontId; typedef _TCompare TCompare; typedef LabelledSeedsInterface Self; - typedef fpa::Base::SeedsInterface< TVertex, TInputValue, TOutputValue, TFrontId, TCompare > Superclass; + typedef fpa::Base::SeedsInterface< TVertex, TPoint, TInputValue, TOutputValue, TFrontId, TCompare > Superclass; typedef typename Superclass::TNode TNode; typedef typename Superclass::TNodeCompare TNodeCompare; @@ -37,6 +38,7 @@ namespace fpa public: virtual void AddSeed( const TVertex& seed ) override; + virtual void AddSeed( const TPoint& seed ) override; const TLabelImage* GetLabels( ) const; void SetLabels( const TLabelImage* image ); diff --git a/lib/fpa/Image/LabelledSeedsInterface.hxx b/lib/fpa/Image/LabelledSeedsInterface.hxx index a9a73c9..98cc334 100644 --- a/lib/fpa/Image/LabelledSeedsInterface.hxx +++ b/lib/fpa/Image/LabelledSeedsInterface.hxx @@ -10,9 +10,9 @@ #include // ------------------------------------------------------------------------- -template< class _TVertex, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > +template< class _TVertex, class _TPoint, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > void -fpa::Image::LabelledSeedsInterface< _TVertex, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: +fpa::Image::LabelledSeedsInterface< _TVertex, _TPoint, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: AddSeed( const TVertex& seed ) { std::ostringstream msg; @@ -26,35 +26,51 @@ AddSeed( const TVertex& seed ) } // ------------------------------------------------------------------------- -template< class _TVertex, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > +template< class _TVertex, class _TPoint, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > +void +fpa::Image::LabelledSeedsInterface< _TVertex, _TPoint, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: +AddSeed( const TPoint& seed ) +{ + std::ostringstream msg; + msg << "itk::ERROR: fpa::Image::LabelledSeedsInterface (" << this + << "): \"AddSeed( const TPoint& seed )\" is not valid for this class. " + << "Use \"SetLabels( TLabelImage* labels )\" instead."; + ::itk::ExceptionObject e( + __FILE__, __LINE__, msg.str( ).c_str( ), ITK_LOCATION + ); + throw e; +} + +// ------------------------------------------------------------------------- +template< class _TVertex, class _TPoint, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > const typename -fpa::Image::LabelledSeedsInterface< _TVertex, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: +fpa::Image::LabelledSeedsInterface< _TVertex, _TPoint, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: TLabelImage* -fpa::Image::LabelledSeedsInterface< _TVertex, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: +fpa::Image::LabelledSeedsInterface< _TVertex, _TPoint, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: GetLabels( ) const { return( this->m_LabelImage ); } // ------------------------------------------------------------------------- -template< class _TVertex, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > -void fpa::Image::LabelledSeedsInterface< _TVertex, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: +template< class _TVertex, class _TPoint, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > +void fpa::Image::LabelledSeedsInterface< _TVertex, _TPoint, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: SetLabels( const TLabelImage* image ) { this->m_LabelImage = image; } // ------------------------------------------------------------------------- -template< class _TVertex, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > -fpa::Image::LabelledSeedsInterface< _TVertex, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: +template< class _TVertex, class _TPoint, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > +fpa::Image::LabelledSeedsInterface< _TVertex, _TPoint, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: LabelledSeedsInterface( itk::ProcessObject* filter ) : Superclass( filter ) { } // ------------------------------------------------------------------------- -template< class _TVertex, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > -fpa::Image::LabelledSeedsInterface< _TVertex, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: +template< class _TVertex, class _TPoint, class _TInputValue, class _TOutputValue, class _TFrontId, class _TCompare > +fpa::Image::LabelledSeedsInterface< _TVertex, _TPoint, _TInputValue, _TOutputValue, _TFrontId, _TCompare >:: ~LabelledSeedsInterface( ) { } diff --git a/lib/fpa/Image/RandomWalker.h b/lib/fpa/Image/RandomWalker.h index 9e41147..5438f00 100644 --- a/lib/fpa/Image/RandomWalker.h +++ b/lib/fpa/Image/RandomWalker.h @@ -22,20 +22,21 @@ namespace fpa */ template< class _TInputImage, class _TLabelImage, class _TScalar > class RandomWalker - : public fpa::Base::DijkstraBase< fpa::Image::Algorithm< _TInputImage, itk::Image< _TScalar, _TInputImage::ImageDimension >, fpa::Base::MarksInterface< typename _TInputImage::IndexType >, fpa::Image::LabelledSeedsInterface< typename _TInputImage::IndexType, typename _TInputImage::PixelType, _TScalar, typename _TLabelImage::PixelType, typename _TInputImage::IndexType::LexicographicCompare > > > + : public fpa::Base::DijkstraBase< fpa::Image::Algorithm< _TInputImage, itk::Image< _TScalar, _TInputImage::ImageDimension >, fpa::Base::MarksInterface< typename _TInputImage::IndexType >, fpa::Image::LabelledSeedsInterface< typename _TInputImage::IndexType, typename _TInputImage::PointType, typename _TInputImage::PixelType, _TScalar, typename _TLabelImage::PixelType, typename _TInputImage::IndexType::LexicographicCompare > > > { public: typedef _TInputImage TInputImage; typedef _TLabelImage TLabelImage; typedef _TScalar TScalar; typedef typename TInputImage::IndexType TVertex; + typedef typename TInputImage::PointType TPoint; typedef typename TVertex::LexicographicCompare TVertexCompare; typedef typename TInputImage::PixelType TInputValue; typedef typename TLabelImage::PixelType TFrontId; typedef itk::Image< TScalar, _TInputImage::ImageDimension > TOutputImage; typedef fpa::Base::MarksInterface< TVertex > TMarksInterface; - typedef fpa::Image::LabelledSeedsInterface< TVertex, TInputValue, _TScalar, TFrontId, TVertexCompare > TSeedsInterface; + typedef fpa::Image::LabelledSeedsInterface< TVertex, TPoint, TInputValue, _TScalar, TFrontId, TVertexCompare > TSeedsInterface; typedef fpa::Image::Algorithm< _TInputImage, TOutputImage, TMarksInterface, TSeedsInterface > TAlgorithm; typedef RandomWalker Self; @@ -44,6 +45,8 @@ namespace fpa typedef itk::SmartPointer< const Self > ConstPointer; typedef fpa::Image::Functors::Dijkstra::Function< TInputImage, TScalar > TWeightFunction; + typedef typename TSeedsInterface::TNode TNode; + typedef typename TSeedsInterface::TNodes TNodes; public: itkNewMacro( Self ); @@ -57,7 +60,7 @@ namespace fpa virtual ~RandomWalker( ); virtual void _BeforeGenerateData( ) override; - virtual void _QueueInit( ) override; + virtual TNodes _UnifySeeds( ) override; private: // Purposely not implemented. diff --git a/lib/fpa/Image/RandomWalker.hxx b/lib/fpa/Image/RandomWalker.hxx index 9016e97..acaa60a 100644 --- a/lib/fpa/Image/RandomWalker.hxx +++ b/lib/fpa/Image/RandomWalker.hxx @@ -61,8 +61,9 @@ _BeforeGenerateData( ) // ------------------------------------------------------------------------- template< class _TInputImage, class _TLabelImage, class _TScalar > -void fpa::Image::RandomWalker< _TInputImage, _TLabelImage, _TScalar >:: -_QueueInit( ) +typename fpa::Image::RandomWalker< _TInputImage, _TLabelImage, _TScalar >:: +TNodes fpa::Image::RandomWalker< _TInputImage, _TLabelImage, _TScalar >:: +_UnifySeeds( ) { this->m_Seeds.clear( ); const TLabelImage* lbl = this->GetLabels( ); @@ -98,25 +99,31 @@ _QueueInit( ) } // rof - typename TSeedsInterface::TNode node; - node.Vertex = lIt.GetIndex( ); - node.Parent = lIt.GetIndex( ); - node.FrontId = lIt.Get( ); - node.Value = TScalar( 0 ); if( !is_seed ) { - this->_Mark( lIt.GetIndex( ), lIt.Get( ) ); + typename TSeedsInterface::TNode node; + node.Vertex = lIt.GetIndex( ); + node.Parent = lIt.GetIndex( ); + node.FrontId = lIt.Get( ); + node.Value = TScalar( 0 ); + this->_Mark( node.Vertex, node.FrontId ); this->_UpdateOutputValue( node ); } else - this->m_Seeds.insert( node ); + { + typename TSeedsInterface::TSeed seed; + seed.Vertex = lIt.GetIndex( ); + seed.IsPoint = false; + this->m_Seeds.push_back( seed ); + + } // fi } // fi } // rof // Ok, finish initialization - this->Superclass::_QueueInit( ); + return( this->Superclass::_UnifySeeds( ) ); } #endif // __fpa__Image__RandomWalker__hxx__ diff --git a/lib/fpa/Image/RegionGrow.h b/lib/fpa/Image/RegionGrow.h index 6a09487..2deff2f 100644 --- a/lib/fpa/Image/RegionGrow.h +++ b/lib/fpa/Image/RegionGrow.h @@ -19,7 +19,7 @@ namespace fpa */ template< class _TInputImage, class _TOutputImage, class _TFrontId = unsigned char > class RegionGrow - : public fpa::Base::RegionGrow< fpa::Image::Algorithm< _TInputImage, _TOutputImage, fpa::Base::MarksInterfaceWithCollisions< typename _TInputImage::IndexType >, fpa::Base::SeedsInterface< typename _TInputImage::IndexType, typename _TInputImage::PixelType, typename _TOutputImage::PixelType, _TFrontId, typename _TInputImage::IndexType::LexicographicCompare > > > + : public fpa::Base::RegionGrow< fpa::Image::Algorithm< _TInputImage, _TOutputImage, fpa::Base::MarksInterfaceWithCollisions< typename _TInputImage::IndexType >, fpa::Base::SeedsInterface< typename _TInputImage::IndexType, typename _TInputImage::PointType, typename _TInputImage::PixelType, typename _TOutputImage::PixelType, _TFrontId, typename _TInputImage::IndexType::LexicographicCompare > > > { public: typedef _TInputImage TInputImage; @@ -27,12 +27,13 @@ namespace fpa typedef _TFrontId TFrontId; typedef typename TInputImage::IndexType TVertex; + typedef typename TInputImage::PointType TPoint; typedef typename TVertex::LexicographicCompare TVertexCompare; typedef typename TInputImage::PixelType TInputValue; typedef typename TOutputImage::PixelType TOutputValue; typedef fpa::Base::MarksInterfaceWithCollisions< TVertex > TMarksInterface; - typedef fpa::Base::SeedsInterface< TVertex, TInputValue, TOutputValue, TFrontId, TVertexCompare > TSeedsInterface; + typedef fpa::Base::SeedsInterface< TVertex, TPoint, TInputValue, TOutputValue, TFrontId, TVertexCompare > TSeedsInterface; typedef fpa::Image::Algorithm< TInputImage, TOutputImage, TMarksInterface, TSeedsInterface > TAlgorithm; typedef RegionGrow Self; @@ -40,6 +41,9 @@ namespace fpa typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; + typedef typename TSeedsInterface::TNode TNode; + typedef typename TSeedsInterface::TNodes TNodes; + public: itkNewMacro( Self ); itkTypeMacro( fpa::Image::RegionGrow, fpa::Base::RegionGrow ); -- 2.47.1