// ========================================================================= // @author Leonardo Florez Valencia // @email florez-l@javeriana.edu.co // ========================================================================= #ifndef __fpa__Filters__DijkstraBase__hxx__ #define __fpa__Filters__DijkstraBase__hxx__ #include #include // ------------------------------------------------------------------------- template< class _TTraits > void fpa::Filters::DijkstraBase< _TTraits >:: SetWeightFunction( TScalarWeight* w ) { if( this->m_ScalarWeight.GetPointer( ) != w ) { this->_Deassociate( this->m_ScalarWeight ); this->m_ScalarWeight = w; this->_Associate( this->m_ScalarWeight ); this->Modified( ); } // fi } // ------------------------------------------------------------------------- template< class _TTraits > void fpa::Filters::DijkstraBase< _TTraits >:: SetWeightFunction( TVertexWeight* w ) { if( this->m_VertexWeight.GetPointer( ) != w ) { this->_Deassociate( this->m_VertexWeight ); this->m_VertexWeight = w; this->_Associate( this->m_VertexWeight ); this->Modified( ); } // fi } // ------------------------------------------------------------------------- template< class _TTraits > fpa::Filters::DijkstraBase< _TTraits >:: DijkstraBase( ) : Superclass( ) { this->SetInitValue( TOutputValue( 0 ) ); } // ------------------------------------------------------------------------- template< class _TTraits > fpa::Filters::DijkstraBase< _TTraits >:: ~DijkstraBase( ) { } // ------------------------------------------------------------------------- template< class _TTraits > void fpa::Filters::DijkstraBase< _TTraits >:: _UpdateOutputValue( TNode& n ) { // Do nothing } // ------------------------------------------------------------------------- template< class _TTraits > void fpa::Filters::DijkstraBase< _TTraits >:: _QueueClear( ) { this->m_Queue.clear( ); } // ------------------------------------------------------------------------- template< class _TTraits > typename fpa::Filters::DijkstraBase< _TTraits >:: TNode fpa::Filters::DijkstraBase< _TTraits >:: _QueuePop( ) { std::pop_heap( this->m_Queue.begin( ), this->m_Queue.end( ), this->m_QueueOrder ); TNode n = this->m_Queue.back( ); this->m_Queue.pop_back( ); return( n ); } // ------------------------------------------------------------------------- template< class _TTraits > void fpa::Filters::DijkstraBase< _TTraits >:: _QueuePush( const TNode& n ) { bool push_needed = ( n.Parent == n.Vertex ); push_needed |= !( n.Value < this->_GetOutputValue( n.Parent ) ); if( push_needed ) { this->m_Queue.push_back( n ); std::push_heap( this->m_Queue.begin( ), this->m_Queue.end( ), this->m_QueueOrder ); } // fi } // ------------------------------------------------------------------------- template< class _TTraits > unsigned long fpa::Filters::DijkstraBase< _TTraits >:: _QueueSize( ) const { return( this->m_Queue.size( ) ); } // ------------------------------------------------------------------------- template< class _TTraits > void fpa::Filters::DijkstraBase< _TTraits >:: _ComputeOutputValue( TNode& n ) { if( this->m_VertexWeight.IsNotNull( ) ) { TOutputValue c = this->m_VertexWeight->Evaluate( n.Vertex, n.Parent ); if( this->m_ScalarWeight.IsNotNull( ) ) c = this->m_ScalarWeight->Evaluate( c ); n.Value = c + this->_GetOutputValue( n.Parent ); } else n.Value = TOutputValue( -1 ); } #endif // __fpa__Filters__DijkstraBase__hxx__ // eof - $RCSfile$