From a45828d3d3c785c473d8496ea4144ac8d3720ba1 Mon Sep 17 00:00:00 2001 From: Basile Sauvage Date: Fri, 7 Sep 2012 11:04:05 +0200 Subject: [PATCH] diag centroidaux --- include/Algo/Geometry/voronoiDiagrams.h | 12 +++- include/Algo/Geometry/voronoiDiagrams.hpp | 69 +++++++++++++++++++++-- 2 files changed, 74 insertions(+), 7 deletions(-) diff --git a/include/Algo/Geometry/voronoiDiagrams.h b/include/Algo/Geometry/voronoiDiagrams.h index b73b36ca9..3eb6ead0a 100644 --- a/include/Algo/Geometry/voronoiDiagrams.h +++ b/include/Algo/Geometry/voronoiDiagrams.h @@ -68,17 +68,25 @@ private : VertexAttribute& distances; // distances from the seed VertexAttribute& pathOrigins; // previous vertex on the shortest path from origin + VertexAttribute& areaElts; // area element attached to each vertex public : - CentroidalVoronoiDiagram (typename PFP::MAP& m, const EdgeAttribute& c, VertexAttribute& r, VertexAttribute& d, VertexAttribute& o); + CentroidalVoronoiDiagram (typename PFP::MAP& m, + const EdgeAttribute& c, + VertexAttribute& r, + VertexAttribute& d, + VertexAttribute& o, + VertexAttribute& a); ~CentroidalVoronoiDiagram (); void cumulateDistancesOnPaths(); + unsigned int moveSeeds(); // returns the number of seeds that did move protected : void clear(); void collectVertexFromFront(Dart e); - void cumulateDistancesFromSeed(Dart e); + REAL cumulateDistancesFromRoot(Dart e); + unsigned int moveSeed(unsigned int i); }; diff --git a/include/Algo/Geometry/voronoiDiagrams.hpp b/include/Algo/Geometry/voronoiDiagrams.hpp index 284bc90c1..acede028c 100644 --- a/include/Algo/Geometry/voronoiDiagrams.hpp +++ b/include/Algo/Geometry/voronoiDiagrams.hpp @@ -143,8 +143,8 @@ void VoronoiDiagram::computeDiagram () ***********************************************************/ template -CentroidalVoronoiDiagram::CentroidalVoronoiDiagram (typename PFP::MAP& m, const EdgeAttribute& c, VertexAttribute& r, VertexAttribute& d, VertexAttribute& o) : - VoronoiDiagram(m,c,r), distances(d), pathOrigins(o) +CentroidalVoronoiDiagram::CentroidalVoronoiDiagram (typename PFP::MAP& m, const EdgeAttribute& c, VertexAttribute& r, VertexAttribute& d, VertexAttribute& o, VertexAttribute& a) : + VoronoiDiagram(m,c,r), distances(d), pathOrigins(o), areaElts(a) { } @@ -172,21 +172,80 @@ template void CentroidalVoronoiDiagram::cumulateDistancesOnPaths(){ for (unsigned int i = 0; i < this->seeds.size(); i++) { - cumulateDistancesFromSeed(this->seeds[i]); + cumulateDistancesFromRoot(this->seeds[i]); } } template -void CentroidalVoronoiDiagram::cumulateDistancesFromSeed(Dart e){ +unsigned int CentroidalVoronoiDiagram::moveSeeds(){ + unsigned int m = 0; + for (unsigned int i = 0; i < this->seeds.size(); i++) + { + m += moveSeed(i); + } + return m; +} + + +template +typename PFP::REAL CentroidalVoronoiDiagram::cumulateDistancesFromRoot(Dart e){ + REAL area = areaElts[e]; + distances[e] *= areaElts[e]; + Traversor2VVaE tv (this->map, e); for (Dart f = tv.begin(); f != tv.end(); f=tv.next()) { if ( pathOrigins[f] == this->map.phi2(f)) { - cumulateDistancesFromSeed(f); + area += cumulateDistancesFromRoot(f); distances[e] += distances[f]; } } + return area; +} + +template +unsigned int CentroidalVoronoiDiagram::moveSeed(unsigned int i){ + Dart e = this->seeds[i]; + unsigned int res = 0; + + std::vector v; + v.reserve(8); + + std::vector a; + a.reserve(8); + + float regionArea = areaElts[e]; + distances[e] = 0.0; + + Traversor2VVaE tv (this->map, e); + for (Dart f = tv.begin(); f != tv.end(); f=tv.next()) + { + if ( pathOrigins[f] == this->map.phi2(f)) + { + float area = cumulateDistancesFromRoot(f); + distances[e] += distances[f]; + v.push_back(f); + a.push_back(area); + regionArea += area; + } + } + + float minDE = 0.0; + for (unsigned int j = 0; jedgeCost[v[j]]; + float de = regionArea * c * c; + de += 2 * c *( distances[e] - 2*distances[v[j]] ); + if (de < minDE) + { + minDE = de; + res = 1; + this->seeds[i] = v[j]; + } + } + + return res; } }// end namespace Geometry -- GitLab