X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2Ffpa%2FBase%2FDijkstra.hxx;h=93a102d2148729b8ca3aaf0af6a5fb99d1d3f17e;hb=e8b46a839b86641f48f593d021234566877ac683;hp=849ff6c981a9676c0c469734534ea58faad307a3;hpb=ea46079b5aef76c1782648ed23e70ea944649635;p=FrontAlgorithms.git diff --git a/lib/fpa/Base/Dijkstra.hxx b/lib/fpa/Base/Dijkstra.hxx index 849ff6c..93a102d 100644 --- a/lib/fpa/Base/Dijkstra.hxx +++ b/lib/fpa/Base/Dijkstra.hxx @@ -1,135 +1,74 @@ +// ========================================================================= +// @author Leonardo Florez Valencia +// @email florez-l@javeriana.edu.co +// ========================================================================= + #ifndef __fpa__Base__Dijkstra__hxx__ #define __fpa__Base__Dijkstra__hxx__ -#include -#include - // ------------------------------------------------------------------------- -template< class _TSuperclass, class _TMST > -_TMST* fpa::Base::Dijkstra< _TSuperclass, _TMST >:: +template< class _TAlgorithm, class _TMST > +typename fpa::Base::Dijkstra< _TAlgorithm, _TMST >:: +TMST* fpa::Base::Dijkstra< _TAlgorithm, _TMST >:: GetMinimumSpanningTree( ) { - return( - dynamic_cast< _TMST* >( - this->itk::ProcessObject::GetOutput( this->m_MSTIndex ) - ) + dynamic_cast< TMST* >( + this->itk::ProcessObject::GetOutput( this->m_MSTIdx ) ); } // ------------------------------------------------------------------------- -template< class _TSuperclass, class _TMST > -const _TMST* fpa::Base::Dijkstra< _TSuperclass, _TMST >:: +template< class _TAlgorithm, class _TMST > +const typename fpa::Base::Dijkstra< _TAlgorithm, _TMST >:: +TMST* fpa::Base::Dijkstra< _TAlgorithm, _TMST >:: GetMinimumSpanningTree( ) const { - return( - dynamic_cast< const _TMST* >( - this->itk::ProcessObject::GetOutput( this->m_MSTIndex ) - ) + dynamic_cast< const TMST* >( + this->itk::ProcessObject::GetOutput( this->m_MSTIdx ) ); } // ------------------------------------------------------------------------- -template< class _TSuperclass, class _TMST > -fpa::Base::Dijkstra< _TSuperclass, _TMST >:: +template< class _TAlgorithm, class _TMST > +fpa::Base::Dijkstra< _TAlgorithm, _TMST >:: Dijkstra( ) : Superclass( ) { - this->m_InitResult = TOutput( 0 ); - this->m_MSTIndex = this->GetNumberOfRequiredOutputs( ); - this->SetNumberOfRequiredOutputs( this->m_MSTIndex + 1 ); - this->itk::ProcessObject::SetNthOutput( this->m_MSTIndex, _TMST::New( ) ); + this->m_MSTIdx = this->GetNumberOfRequiredOutputs( ); + this->itk::ProcessObject::SetNumberOfRequiredOutputs( this->m_MSTIdx + 1 ); + this->SetNthOutput( this->m_MSTIdx, TMST::New( ) ); } // ------------------------------------------------------------------------- -template< class _TSuperclass, class _TMST > -fpa::Base::Dijkstra< _TSuperclass, _TMST >:: +template< class _TAlgorithm, class _TMST > +fpa::Base::Dijkstra< _TAlgorithm, _TMST >:: ~Dijkstra( ) { } // ------------------------------------------------------------------------- -template< class _TSuperclass, class _TMST > -void fpa::Base::Dijkstra< _TSuperclass, _TMST >:: +template< class _TAlgorithm, class _TMST > +void fpa::Base::Dijkstra< _TAlgorithm, _TMST >:: _AfterGenerateData( ) { - this->Superclass::_AfterGenerateData( ); + typedef typename Superclass::TSeedsInterface::TSeeds::iterator _TIt; - auto mst = this->GetMinimumSpanningTree( ); + TMST* mst = this->GetMinimumSpanningTree( ); mst->ClearSeeds( ); - for( auto s = this->m_Seeds.begin( ); s != this->m_Seeds.end( ); ++s ) - mst->AddSeed( s->Vertex ); mst->SetCollisions( this->m_Collisions ); + for( _TIt sIt = this->BeginSeeds( ); sIt != this->EndSeeds( ); ++sIt ) + mst->AddSeed( sIt->Vertex ); } // ------------------------------------------------------------------------- -template< class _TSuperclass, class _TMST > -void fpa::Base::Dijkstra< _TSuperclass, _TMST >:: -_UpdateResult( const _TQueueNode& n ) +template< class _TAlgorithm, class _TMST > +void fpa::Base::Dijkstra< _TAlgorithm, _TMST >:: +_UpdateOutputValue( const TNode& n ) { - this->Superclass::_UpdateResult( n ); + this->Superclass::_UpdateOutputValue( n ); this->GetMinimumSpanningTree( )->SetParent( n.Vertex, n.Parent ); } -// ------------------------------------------------------------------------- -template< class _TSuperclass, class _TMST > -bool fpa::Base::Dijkstra< _TSuperclass, _TMST >:: -_UpdateValue( _TQueueNode& v, const _TQueueNode& p ) -{ - v.Result = this->m_CostFunction->Evaluate( p.Vertex, v.Vertex ); - if( this->m_CostConversionFunction.IsNotNull( ) ) - v.Result = this->m_CostConversionFunction->Evaluate( v.Result ); - if( v.Result >= TOutput( 0 ) ) - { - v.Result += p.Result; - return( true ); - } - else - { - v.Result = this->m_InitResult; - return( false ); - - } // fi -} - -// ------------------------------------------------------------------------- -template< class _TSuperclass, class _TMST > -unsigned long fpa::Base::Dijkstra< _TSuperclass, _TMST >:: -_QueueSize( ) const -{ - return( this->m_Queue.size( ) ); -} - -// ------------------------------------------------------------------------- -template< class _TSuperclass, class _TMST > -void fpa::Base::Dijkstra< _TSuperclass, _TMST >:: -_QueueClear( ) -{ - this->m_Queue.clear( ); -} - -// ------------------------------------------------------------------------- -template< class _TSuperclass, class _TMST > -void fpa::Base::Dijkstra< _TSuperclass, _TMST >:: -_QueuePush( const _TQueueNode& node ) -{ - static _TQueueNodeCompare cmp; - this->m_Queue.push_back( node ); - std::push_heap( this->m_Queue.begin( ), this->m_Queue.end( ), cmp ); -} - -// ------------------------------------------------------------------------- -template< class _TSuperclass, class _TMST > -typename fpa::Base::Dijkstra< _TSuperclass, _TMST >:: -_TQueueNode fpa::Base::Dijkstra< _TSuperclass, _TMST >:: -_QueuePop( ) -{ - static _TQueueNodeCompare cmp; - std::pop_heap( this->m_Queue.begin( ), this->m_Queue.end( ), cmp ); - _TQueueNode f = this->m_Queue.back( ); - this->m_Queue.pop_back( ); - return( f ); -} - #endif // __fpa__Base__Dijkstra__hxx__ // eof - $RCSfile$