]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/Base/Dijkstra.hxx
...
[FrontAlgorithms.git] / lib / fpa / Base / Dijkstra.hxx
index 149363d64128543dd1bfa29de9edd04cf2b8cac3..9de7912d2597427ed381279679432b659115f72a 100644 (file)
 #define __fpa__Base__Dijkstra__hxx__
 
 // -------------------------------------------------------------------------
-template< class _TFilter, class _TMarksInterface, class _TSeedsInterface, class _TMST >
-typename
-fpa::Base::Dijkstra< _TFilter, _TMarksInterface, _TSeedsInterface, _TMST >::
-TMST* fpa::Base::Dijkstra< _TFilter, _TMarksInterface, _TSeedsInterface, _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 )
+      this->itk::ProcessObject::GetOutput( this->m_MSTIdx )
       )
     );
 }
 
 // -------------------------------------------------------------------------
-template< class _TFilter, class _TMarksInterface, class _TSeedsInterface, class _TMST >
-const typename
-fpa::Base::Dijkstra< _TFilter, _TMarksInterface, _TSeedsInterface, _TMST >::
-TMST* fpa::Base::Dijkstra< _TFilter, _TMarksInterface, _TSeedsInterface, _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 )
+      this->itk::ProcessObject::GetOutput( this->m_MSTIdx )
       )
     );
 }
 
 // -------------------------------------------------------------------------
-template< class _TFilter, class _TMarksInterface, class _TSeedsInterface, class _TMST >
-const typename
-fpa::Base::Dijkstra< _TFilter, _TMarksInterface, _TSeedsInterface, _TMST >::
-TIntensityFunctor*
-fpa::Base::Dijkstra< _TFilter, _TMarksInterface, _TSeedsInterface, _TMST >::
-GetIntensityFunctor( ) const
+template< class _TAlgorithm, class _TMST >
+fpa::Base::Dijkstra< _TAlgorithm, _TMST >::
+Dijkstra( )
+  : Superclass( )
 {
-  return( this->m_IntensityFunctor );
+  this->m_MSTIdx = this->GetNumberOfRequiredOutputs( );
+  this->itk::ProcessObject::SetNumberOfRequiredOutputs( this->m_MSTIdx + 1 );
+  this->SetNthOutput( this->m_MSTIdx, TMST::New( ) );
 }
 
 // -------------------------------------------------------------------------
-template< class _TFilter, class _TMarksInterface, class _TSeedsInterface, class _TMST >
-const typename
-fpa::Base::Dijkstra< _TFilter, _TMarksInterface, _TSeedsInterface, _TMST >::
-TVertexFunctor*
-fpa::Base::Dijkstra< _TFilter, _TMarksInterface, _TSeedsInterface, _TMST >::
-GetVertexFunctor( ) const
+template< class _TAlgorithm, class _TMST >
+fpa::Base::Dijkstra< _TAlgorithm, _TMST >::
+~Dijkstra( )
 {
-  return( this->m_VertexFunctor );
 }
 
 // -------------------------------------------------------------------------
-template< class _TFilter, class _TMarksInterface, class _TSeedsInterface, class _TMST >
-void fpa::Base::Dijkstra< _TFilter, _TMarksInterface, _TSeedsInterface, _TMST >::
-SetFunctor( TIntensityFunctor* functor )
+template< class _TAlgorithm, class _TMST >
+void fpa::Base::Dijkstra< _TAlgorithm, _TMST >::
+_AfterGenerateData( )
 {
-  if( this->m_IntensityFunctor.GetPointer( ) != functor )
-  {
-    this->m_IntensityFunctor = functor;
-    this->Modified( );
+  this->Superclass::_AfterGenerateData( );
 
-  } // fi
-}
+  TMST* mst = this->GetMinimumSpanningTree( );
+  mst->ClearSeeds( );
+  mst->SetCollisions( this->m_Collisions );
 
-// -------------------------------------------------------------------------
-template< class _TFilter, class _TMarksInterface, class _TSeedsInterface, class _TMST >
-void fpa::Base::Dijkstra< _TFilter, _TMarksInterface, _TSeedsInterface, _TMST >::
-SetFunctor( TVertexFunctor* functor )
-{
-  if( this->m_VertexFunctor.GetPointer( ) != functor )
+  const TSeeds& seeds = this->GetSeeds( );
+  typename TSeeds::const_iterator sIt = seeds.begin( );
+  for( ; sIt != seeds.end( ); ++sIt )
   {
-    this->m_VertexFunctor = functor;
-    this->Modified( );
+    if( sIt->IsUnified )
+      mst->AddSeed( sIt->Vertex );
 
-  } // fi
+  } // rof
 }
 
 // -------------------------------------------------------------------------
-template< class _TFilter, class _TMarksInterface, class _TSeedsInterface, class _TMST >
-fpa::Base::Dijkstra< _TFilter, _TMarksInterface, _TSeedsInterface, _TMST >::
-Dijkstra( )
-  : Superclass( ),
-    _TMarksInterface( this ),
-    _TSeedsInterface( this )
-{
-  this->m_MSTIndex = this->GetNumberOfRequiredOutputs( );
-  this->SetNumberOfRequiredOutputs( this->m_MSTIndex + 1 );
-  this->itk::ProcessObject::SetNthOutput( this->m_MSTIndex, TMST::New( ) );
-}
-
-// -------------------------------------------------------------------------
-template< class _TFilter, class _TMarksInterface, class _TSeedsInterface, class _TMST >
-fpa::Base::Dijkstra< _TFilter, _TMarksInterface, _TSeedsInterface, _TMST >::
-~Dijkstra( )
+template< class _TAlgorithm, class _TMST >
+void fpa::Base::Dijkstra< _TAlgorithm, _TMST >::
+_UpdateOutputValue( TNode& n )
 {
-}
-
-// -------------------------------------------------------------------------
-template< class _TFilter, class _TMarksInterface, class _TSeedsInterface, class _TMST >
-void fpa::Base::Dijkstra< _TFilter, _TMarksInterface, _TSeedsInterface, _TMST >::
-GenerateData( )
-{
-  // Init objects
-  this->_ConfigureOutputs( TOutputValue( 0 ) );
-  this->_InitMarks( this->GetNumberOfSeeds( ) );
-  TMST* mst = this->GetMinimumSpanningTree( );
-
-  // Init queue
-  std::vector< _TNode > q;
-  unsigned long frontId = 1;
-  for( TVertex seed: this->GetSeeds( ) )
-    q.push_back( _TNode( seed, seed, frontId++ ) );
-
-  // Main loop
-  while( q.size( ) > 0 )
-  {
-    // Get next candidate
-    std::pop_heap( q.begin( ), q.end( ) );
-    _TNode node = q.back( );
-    q.pop_back( );
-    if( this->_IsMarked( node.Vertex ) )
-      continue;
-    this->_Mark( node.Vertex, node.FrontId );
-
-    // Ok, pixel lays inside region
-    this->_SetOutputValue( node.Vertex, node.Cost );
-    mst->SetParent( node.Vertex, node.Parent );
-
-    // Add neighborhood
-    TVertices neighbors = this->_GetNeighbors( node.Vertex );
-    for( TVertex neigh: neighbors )
-    {
-      if( this->_IsMarked( neigh ) )
-      {
-        // Invoke stop at collisions
-        unsigned long nColl = this->_Collisions( node.Vertex, neigh );
-        if(
-          this->StopAtOneFront( ) &&
-          this->GetNumberOfSeeds( ) > 1 &&
-          nColl == 1
-          )
-          q.clear( );
-      }
-      else
-      {
-        // Compute new cost
-        TOutputValue ncost =
-          this->m_VertexFunctor->Evaluate( neigh, node.Vertex );
-        if( this->m_IntensityFunctor.IsNotNull( ) )
-          ncost = this->m_IntensityFunctor->Evaluate( ncost );
-
-        // This algorithm only supports positive values
-        if( ncost >= TOutputValue( 0 ) )
-        {
-          // Insert new node
-          _TNode nn( neigh, node.Vertex, node.FrontId );
-          nn.Cost = node.Cost + ncost;
-          q.push_back( nn );
-          std::push_heap( q.begin( ), q.end( ) );
-
-        } // fi
-
-      } // fi
-
-    } // rof
-
-  } // elihw
-  this->_FreeMarks( );
-
-  // Complete data into minimum spanning tree
-  mst->ClearSeeds( );
-  mst->SetCollisions( this->m_Collisions );
-  for( TVertex seed: this->GetSeeds( ) )
-    mst->AddSeed( seed );
+  this->Superclass::_UpdateOutputValue( n );
+  this->GetMinimumSpanningTree( )->SetParent( n.Vertex, n.Parent );
 }
 
 #endif // __fpa__Base__Dijkstra__hxx__