From cbbaa4c7ee6a9c1ce8c1dc0eb5a46fdba01fc899 Mon Sep 17 00:00:00 2001 From: Basile Sauvage Date: Wed, 5 Sep 2012 10:47:28 +0200 Subject: [PATCH] =?UTF-8?q?am=C3=A9lioration=20des=20diag=20de=20Voronoi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/Algo/Geometry/voronoiDiagrams.h | 7 ++- include/Algo/Geometry/voronoiDiagrams.hpp | 70 ++++++++++++++--------- 2 files changed, 47 insertions(+), 30 deletions(-) diff --git a/include/Algo/Geometry/voronoiDiagrams.h b/include/Algo/Geometry/voronoiDiagrams.h index f204cbae4..c19028424 100644 --- a/include/Algo/Geometry/voronoiDiagrams.h +++ b/include/Algo/Geometry/voronoiDiagrams.h @@ -25,14 +25,14 @@ private : { typename std::multimap::iterator it ; bool valid ; - unsigned int region; +// unsigned int region; + Dart pathOrigin; static std::string CGoGNnameOfType() { return "VoronoiVertexInfo" ; } } VoronoiVertexInfo ; typedef NoMathIOAttribute VertexInfo ; typename PFP::MAP& map; const EdgeAttribute& edgeCost; // weights on the graph edges -// const VertexAttribute& position; // positions VertexAttribute& regions; // region labels std::vector border; std::vector seeds; @@ -56,6 +56,9 @@ public : private : void clear (); void initFrontWithSeeds(); + void collectVertexFromFront(Dart e); + void addVertexToFront(Dart f, float d); + void updateVertexInFront(Dart f, float d); }; }// end namespace Geometry diff --git a/include/Algo/Geometry/voronoiDiagrams.hpp b/include/Algo/Geometry/voronoiDiagrams.hpp index 98160e935..8de9751c6 100644 --- a/include/Algo/Geometry/voronoiDiagrams.hpp +++ b/include/Algo/Geometry/voronoiDiagrams.hpp @@ -66,7 +66,9 @@ void VoronoiDiagram::initFrontWithSeeds () vmReached.mark(d); vertexInfo[d].it = front.insert(std::pair(0.0, d)); vertexInfo[d].valid = true; - vertexInfo[d].region = i; +// vertexInfo[d].region = i; + regions[d] = i; + vertexInfo[d].pathOrigin = d; } } @@ -75,6 +77,36 @@ void VoronoiDiagram::setCost (const EdgeAttribute& c){ edgeCost = c; } +template +void VoronoiDiagram::collectVertexFromFront(Dart e){ + front.erase(vertexInfo[e].it); + vertexInfo[e].valid=false; +// regions[e] = vertexInfo[e].region; + regions[e] = regions[vertexInfo[e].pathOrigin]; +} + +template +void VoronoiDiagram::addVertexToFront(Dart f, float d){ + VertexInfo& vi (vertexInfo[f]); + vi.it = front.insert(std::pair(d + edgeCost[f], f)); + vi.valid=true; +// vi.region = regions[map.phi2(f)]; + vi.pathOrigin = map.phi2(f); + vmReached.mark(f); +} + +template +void VoronoiDiagram::updateVertexInFront(Dart f, float d){ + VertexInfo& vi (vertexInfo[f]); + float dist = d + edgeCost[f]; + if (dist < vi.it->first) + { + front.erase(vi.it); + vi.it = front.insert(std::pair(dist, f)); +// vi.region = regions[map.phi2(f)]; + vi.pathOrigin = map.phi2(f); + } +} template void VoronoiDiagram::computeDiagram () @@ -85,40 +117,22 @@ void VoronoiDiagram::computeDiagram () { Dart e = front.begin()->second; float d = front.begin()->first; - front.erase(vertexInfo[e].it); - vertexInfo[e].valid=false; - regions[e] = vertexInfo[e].region; + + collectVertexFromFront(e); Traversor2VVaE tv (map, e); for (Dart f = tv.begin(); f != tv.end(); f=tv.next()) { - VertexInfo& vi (vertexInfo[f]); if (vmReached.isMarked(f)) - { - if (vi.valid) // probably useless (because of distance test) but faster - { -// float dist = d + Algo::Geometry::edgeLength(map,f,position); - float dist = d + edgeCost[f]; - if (dist < vi.it->first) - { - front.erase(vi.it); - vi.it = front.insert(std::pair(dist, f)); - vi.region = regions[e]; - } - } - else - { - if ( regions[f] != regions[e] ) - border.push_back(f); - } + { // f has been reached + if (vertexInfo[f].valid) // f is in the front : update + updateVertexInFront(f,d); + else // f is not in the front any more (already collected) : detect a border edge + if ( regions[f] != regions[e] ) border.push_back(f); } else - { -// vi.it = front.insert(std::pair(d + Algo::Geometry::edgeLength(map,f,position), f)); - vi.it = front.insert(std::pair(d + edgeCost[f], f)); - vi.valid=true; - vi.region = regions[e]; - vmReached.mark(f); + { // f has not been reached : add it to the front + addVertexToFront(f,d); } } } -- GitLab