+ // Init objects
+ this->_ConfigureOutputs( std::numeric_limits< TOutputValue >::max( ) );
+ this->_InitMarks( this->GetNumberOfSeeds( ) );
+ TMST* mst = this->GetMinimumSpanningTree( );
+
+ // Init queue
+ std::vector< _TNode > q;
+ unsigned long frontId = 1;
+ typename TSeedsInterface::TSeeds::const_iterator sIt = this->BeginSeeds( );
+ for( ; sIt != this->EndSeeds( ); ++sIt )
+ q.push_back( _TNode( *sIt, *sIt, 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 );
+ typename TVertices::const_iterator neighIt = neighbors.begin( );
+ bool coll = false;
+ while( neighIt != neighbors.end( ) && !coll )
+ {
+ TVertex neigh = *neighIt;
+ 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( );
+ coll = true;
+
+ } // fi
+ }
+ 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
+ ++neighIt;
+
+ } // elihw
+
+ } // elihw
+ this->_FreeMarks( );
+
+ // Complete data into minimum spanning tree
+ mst->ClearSeeds( );
+ mst->SetCollisions( this->m_Collisions );
+ for( sIt = this->BeginSeeds( ); sIt != this->EndSeeds( ); ++sIt )
+ mst->AddSeed( *sIt );