diff --git a/include/Algo/Geometry/voronoiDiagrams.h b/include/Algo/Geometry/voronoiDiagrams.h index f204cbae44ca1fcc7a7ea007c2f76433bc0a0f42..c19028424899ec668a7f4d896551dc8e8be5a33f 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 98160e9350c14661e07509f5ec8e7861b4484721..8de9751c6c4611a061152912092412dfbe89c7c3 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); } } }