diff --git a/include/Algo/Geometry/voronoiDiagrams.h b/include/Algo/Geometry/voronoiDiagrams.h index 3eb6ead0a6a72d5ab97008f0e88218b1cd78695d..e1f22066ea30d9118e30c4f9783975db2b357a59 100644 --- a/include/Algo/Geometry/voronoiDiagrams.h +++ b/include/Algo/Geometry/voronoiDiagrams.h @@ -65,6 +65,7 @@ template class CentroidalVoronoiDiagram : public VoronoiDiagram { private : typedef typename PFP::REAL REAL; + typedef typename PFP::VEC3 VEC3; VertexAttribute& distances; // distances from the seed VertexAttribute& pathOrigins; // previous vertex on the shortest path from origin @@ -86,7 +87,7 @@ protected : void clear(); void collectVertexFromFront(Dart e); REAL cumulateDistancesFromRoot(Dart e); - unsigned int moveSeed(unsigned int i); + unsigned int moveSeed(unsigned int numSeed); }; diff --git a/include/Algo/Geometry/voronoiDiagrams.hpp b/include/Algo/Geometry/voronoiDiagrams.hpp index acede028cec46b3a9ab8b90ed53621b018693480..4317e9d3409c87fa1408d7ebeb7f6af88228a261 100644 --- a/include/Algo/Geometry/voronoiDiagrams.hpp +++ b/include/Algo/Geometry/voronoiDiagrams.hpp @@ -29,7 +29,6 @@ void VoronoiDiagram::clear () border.clear(); regions.setAllValues(0); border.clear(); - seeds.clear(); front.clear(); vmReached.unmarkAll(); } @@ -37,14 +36,17 @@ void VoronoiDiagram::clear () template void VoronoiDiagram::setSeeds (const std::vector& s) { - clear(); + seeds.clear(); +// clear(); seeds = s; } template void VoronoiDiagram::setRandomSeeds (unsigned int nseeds) { - clear(); + seeds.clear(); +// clear(); + vmReached.unmarkAll(); srand ( time(NULL) ); unsigned int n = nseeds; @@ -63,7 +65,8 @@ void VoronoiDiagram::setRandomSeeds (unsigned int nseeds) template void VoronoiDiagram::initFrontWithSeeds () { - vmReached.unmarkAll(); +// vmReached.unmarkAll(); + clear(); for (unsigned int i = 0; i < seeds.size(); i++) { Dart d = seeds[i]; @@ -205,9 +208,9 @@ typename PFP::REAL CentroidalVoronoiDiagram::cumulateDistancesFromRoot(Dart } template -unsigned int CentroidalVoronoiDiagram::moveSeed(unsigned int i){ - Dart e = this->seeds[i]; - unsigned int res = 0; +unsigned int CentroidalVoronoiDiagram::moveSeed(unsigned int numSeed){ + Dart e = this->seeds[numSeed]; + unsigned int seedMoved = 0; std::vector v; v.reserve(8); @@ -231,6 +234,39 @@ unsigned int CentroidalVoronoiDiagram::moveSeed(unsigned int i){ } } + /* second attempt */ + VEC3 grad (0.0); + const VertexAttribute& pos = this->map.template getAttribute("position"); + + for (unsigned int j = 0; j(this->map,this->map.phi2(f),pos); + VEC3 edgeV = pos[f] - pos[this->map.phi2(f)]; + edgeV.normalize(); + grad += distances[f] * edgeV; + } + + float maxProj = 0.0; + for (unsigned int j = 0; j(this->map,this->map.phi2(f),pos); + VEC3 edgeV = pos[f] - pos[this->map.phi2(f)]; +// edgeV.normalize(); + float proj = edgeV * grad; + proj -= areaElts[e] * this->edgeCost[f] * this->edgeCost[f]; + if (proj > maxProj) + { + if (numSeed==1 && j==0) CGoGNout << edgeV * grad << "\t - \t" << areaElts[e] * this->edgeCost[f] * this->edgeCost[f] << CGoGNendl; + maxProj = proj; + seedMoved = 1; + this->seeds[numSeed] = v[j]; + } + } + /* end second attempt */ + +/* first attempt by approximating the energy change float minDE = 0.0; for (unsigned int j = 0; j::moveSeed(unsigned int i){ if (de < minDE) { minDE = de; - res = 1; - this->seeds[i] = v[j]; + seedMoved = 1; + this->seeds[numSeed] = v[j]; } } - - return res; +*/ + return seedMoved; } }// end namespace Geometry