From 02b92791a4540fa7a77e399daefdc18e6dcd64c7 Mon Sep 17 00:00:00 2001 From: Guido Ranzuglia granzuglia Date: Tue, 10 Jul 2012 11:27:31 +0000 Subject: [PATCH] - In Dijkstra algorithm I have not to compute the arches connecting vertices already visited. It leads to inconsistent priority_queue. --- .../edit_point/connectedComponent.h | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/meshlabplugins/edit_point/connectedComponent.h b/src/meshlabplugins/edit_point/connectedComponent.h index 84f691d50..10f2d9f43 100644 --- a/src/meshlabplugins/edit_point/connectedComponent.h +++ b/src/meshlabplugins/edit_point/connectedComponent.h @@ -95,7 +95,8 @@ public: this->distFromCenter = distFromCenter; } - bool operator() (const _MyVertexType* lhs, const _MyVertexType* rhs) const { + bool operator() (const _MyVertexType* lhs, const _MyVertexType* rhs) const + { return (*distFromCenter)[*lhs] > (*distFromCenter)[*rhs]; } }; @@ -151,21 +152,27 @@ void ComponentFinder<_MyMeshType, _MyVertexType>::Dijkstra(_MyMeshType& m, _MyVe element = prQueue.top(); prQueue.pop(); - for (it = neighboursVect[element]->begin(); it != neighboursVect[element]->end(); it++) { - distance = vcg::Distance((*it)->P(), element->P()); + for (it = neighboursVect[element]->begin(); it != neighboursVect[element]->end(); it++) + { + //I have not to compute the arches connecting vertices already visited. + if (!(*it)->IsV()) + { + distance = vcg::Distance((*it)->P(), element->P()); - // we take into account only the arcs with a distance less or equal to maxHopDist - if (distance <= maxHopDist) { - if (distFromCenter[*element] + distance < distFromCenter[*it]) - distFromCenter[*it] = distFromCenter[*element] + distance; + // we take into account only the arcs with a distance less or equal to maxHopDist + if (distance <= maxHopDist) + { + if ((distFromCenter[*element] + distance) < distFromCenter[*it]) + distFromCenter[*it] = distFromCenter[*element] + distance; - if (!(*it)->IsV()) { - prQueue.push(*it); - (*it)->SetV(); - } - } - // all the other are the notReachable arcs - else if (distance > maxHopDist) notReachableVect.push_back(element); + if (!(*it)->IsV()) { + prQueue.push(*it); + (*it)->SetV(); + } + } + // all the other are the notReachable arcs + else if (distance > maxHopDist) notReachableVect.push_back(element); + } } } }