diff --git a/include/Algo/Geometry/voronoiDiagrams.h b/include/Algo/Geometry/voronoiDiagrams.h index c19028424899ec668a7f4d896551dc8e8be5a33f..24fd96556ea3fd9a041c51b5f4e87c4f32e09349 100644 --- a/include/Algo/Geometry/voronoiDiagrams.h +++ b/include/Algo/Geometry/voronoiDiagrams.h @@ -17,9 +17,8 @@ namespace Geometry template class VoronoiDiagram { -private : +protected : typedef typename PFP::REAL REAL; - typedef typename PFP::VEC3 VEC3; typedef struct { @@ -53,7 +52,7 @@ public : void computeDiagram (); -private : +protected : void clear (); void initFrontWithSeeds(); void collectVertexFromFront(Dart e); @@ -61,6 +60,25 @@ private : void updateVertexInFront(Dart f, float d); }; + +template +class CentroidalVoronoiDiagram : public VoronoiDiagram { +private : + typedef typename PFP::REAL REAL; + + VertexAttribute& distances; // distances from the seed + VertexAttribute& pathOrigins; // previous vertex on the shortest path from origin + +public : + CentroidalVoronoiDiagram (typename PFP::MAP& m, const EdgeAttribute& c, VertexAttribute& r, VertexAttribute& d, VertexAttribute& o); + ~CentroidalVoronoiDiagram (); + +protected : + void clear(); + void collectVertexFromFront(Dart e); +}; + + }// end namespace Geometry }// end namespace Algo }// end namespace CGoGN diff --git a/include/Algo/Geometry/voronoiDiagrams.hpp b/include/Algo/Geometry/voronoiDiagrams.hpp index 8de9751c6c4611a061152912092412dfbe89c7c3..4862d56f178d5f4ee446c380fdc0392664fa66f5 100644 --- a/include/Algo/Geometry/voronoiDiagrams.hpp +++ b/include/Algo/Geometry/voronoiDiagrams.hpp @@ -7,6 +7,10 @@ namespace Algo namespace Geometry { +/*********************************************************** + * class VoronoiDiagram + ***********************************************************/ + template VoronoiDiagram::VoronoiDiagram (typename PFP::MAP& m, const EdgeAttribute& p, VertexAttribute& r) : map(m), edgeCost (p), regions (r), vmReached(m) { @@ -79,10 +83,10 @@ void VoronoiDiagram::setCost (const EdgeAttribute& 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]; + front.erase(vertexInfo[e].it); + vertexInfo[e].valid=false; } template @@ -138,6 +142,37 @@ void VoronoiDiagram::computeDiagram () } } +/*********************************************************** + * class CentroidalVoronoiDiagram + ***********************************************************/ + +template +CentroidalVoronoiDiagram::CentroidalVoronoiDiagram (typename PFP::MAP& m, const EdgeAttribute& c, VertexAttribute& r, VertexAttribute& d, VertexAttribute& o) : + VoronoiDiagram(m,c,r), distances(d), pathOrigins(o) +{ +} + +template +CentroidalVoronoiDiagram::~CentroidalVoronoiDiagram () +{ +} + +template +void CentroidalVoronoiDiagram::clear () +{ + VoronoiDiagram::clear(); + distances.setAllValues(0.0); +} + +template +void CentroidalVoronoiDiagram::collectVertexFromFront(Dart e){ + distances[e] = this->vertexInfo[e].it->first(); + pathOrigins[e] = this->vertexInfo[e].pathOrigin; + + VoronoiDiagram::collectVertexFromFront(e); +} + + }// end namespace Geometry }// end namespace Algo }// end namespace CGoGN