]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/Base/Dijkstra.hxx
...
[FrontAlgorithms.git] / lib / fpa / Base / Dijkstra.hxx
index 849ff6c981a9676c0c469734534ea58faad307a3..9de7912d2597427ed381279679432b659115f72a 100644 (file)
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
+
 #ifndef __fpa__Base__Dijkstra__hxx__
 #define __fpa__Base__Dijkstra__hxx__
 
-#include <algorithm>
-#include <limits>
-
 // -------------------------------------------------------------------------
-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( );
 
-  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 );
-}
-
-// -------------------------------------------------------------------------
-template< class _TSuperclass, class _TMST >
-void fpa::Base::Dijkstra< _TSuperclass, _TMST >::
-_UpdateResult( const _TQueueNode& n )
-{
-  this->Superclass::_UpdateResult( 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
+  const TSeeds& seeds = this->GetSeeds( );
+  typename TSeeds::const_iterator sIt = seeds.begin( );
+  for( ; sIt != seeds.end( ); ++sIt )
   {
-    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( );
-}
+    if( sIt->IsUnified )
+      mst->AddSeed( sIt->Vertex );
 
-// -------------------------------------------------------------------------
-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 );
+  } // rof
 }
 
 // -------------------------------------------------------------------------
-template< class _TSuperclass, class _TMST >
-typename fpa::Base::Dijkstra< _TSuperclass, _TMST >::
-_TQueueNode fpa::Base::Dijkstra< _TSuperclass, _TMST >::
-_QueuePop( )
+template< class _TAlgorithm, class _TMST >
+void fpa::Base::Dijkstra< _TAlgorithm, _TMST >::
+_UpdateOutputValue( TNode& n )
 {
-  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 );
+  this->Superclass::_UpdateOutputValue( n );
+  this->GetMinimumSpanningTree( )->SetParent( n.Vertex, n.Parent );
 }
 
 #endif // __fpa__Base__Dijkstra__hxx__