Geogram Version 1.10.2
A programming library of geometric algorithms
Loading...
Searching...
No Matches
CVT.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2000-2022 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the ALICE Project-Team nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contact: Bruno Levy
30 *
31 * https://www.inria.fr/fr/bruno-levy
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39
40#ifndef GEOGRAM_VORONOI_CVT
41#define GEOGRAM_VORONOI_CVT
42
44#include <geogram/voronoi/RVD.h>
46#include <geogram/mesh/mesh.h>
48
49
54
55namespace GEO {
56
58 class ProgressTask;
59
69 class GEOGRAM_API CentroidalVoronoiTesselation {
70
72 typedef CentroidalVoronoiTesselation thisclass;
73
74 public:
88 Mesh* mesh,
90 const std::string& delaunay = "default"
91 );
92
109 Mesh* mesh,
111 const std::string& delaunay = "default"
112 );
113
118
129 bool compute_initial_sampling(index_t nb_samples, bool verbose=false);
130
139 void set_points(index_t nb_points, const double* points);
140
147
164 virtual void Lloyd_iterations(index_t nb_iter, bool safe_mode = false);
165
171 virtual void Newton_iterations(index_t nb_iter, index_t m = 7);
172
179 void compute_surface(Mesh* mesh, bool multinerve = true);
180
187
192 void set_show_iterations(bool x) {
193 show_iterations_ = x;
194 }
195
203 use_RVC_centroids_ = x;
204 }
205
211 void set_constrained_cvt(bool x) {
212 constrained_cvt_ = x;
213 }
214
219 return mesh_;
220 }
221
226 return delaunay_;
227 }
228
233 return RVD_;
234 }
235
243 void set_facets_range(index_t facets_begin, index_t facets_end) {
244 RVD_->set_facets_range(facets_begin, facets_end);
245 }
246
257 geo_assert(instance_ == nullptr);
258 instance_ = this;
259 }
260
271 geo_assert(instance_ == this);
272 instance_ = nullptr;
273 }
274
275 public:
284 static void funcgrad_CB(
285 index_t n, double* x, double& f, double* g
286 );
287
297 static void newiteration_CB(
298 index_t n, const double* x, double f, const double* g, double gnorm
299 );
300
306 progress_ = progress;
307 }
308
314 return dimension_;
315 }
316
321 return index_t(points_.size() / dimension_);
322 }
323
330 const vec3& R3_embedding(index_t p) const {
331 return RVD_->R3_embedding(p);
332 }
333
340 double* embedding(index_t p) {
342 return &(points_[0]) + dimension_ * p;
343 }
344
348 bool volumetric() const {
349 return RVD_->volumetric();
350 }
351
357 void set_volumetric(bool x) {
358 RVD_->set_volumetric(x);
359 }
360
368 bool point_is_locked(index_t i) const {
370 point_is_locked_.size() == 0 || i < point_is_locked_.size()
371 );
372 return point_is_locked_.size() != 0 && point_is_locked_[i];
373 }
374
384 if(point_is_locked_.size() != nb_points()) {
385 point_is_locked_.resize(nb_points(), false);
386 }
387 point_is_locked_[i] = true;
388 }
389
399 if(
400 point_is_locked_.size() != nb_points()
401 ) {
402 point_is_locked_.resize(nb_points(), false);
403 }
404 point_is_locked_[i] = false;
405 }
406
413 point_is_locked_.clear();
414 }
415
416 protected:
421 virtual void newiteration();
422
430 virtual void funcgrad(index_t n, double* x, double& f, double* g);
431
438 void constrain_points(double* g) const;
439
446
447 static CentroidalVoronoiTesselation* instance_;
448 bool show_iterations_;
449 coord_index_t dimension_;
450 Delaunay_var delaunay_;
452 Mesh* mesh_;
453
454 vector<double> points_;
455 vector<vec3> points_R3_;
456 vector<bool> point_is_locked_;
457
458 ProgressTask* progress_;
459 index_t cur_iter_;
460 index_t nb_iter_;
461
463 bool constrained_cvt_;
464 bool use_RVC_centroids_;
465
466 IntegrationSimplex_var simplex_func_;
468
469 private:
471 CentroidalVoronoiTesselation(const thisclass& rhs);
472
474 thisclass& operator= (const thisclass& rhs);
475 };
476}
477
478#endif
Class and functions to compute restricted Voronoi diagrams and extract information from them.
#define geo_assert(x)
Verifies that a condition is met.
Definition assert.h:155
#define geo_debug_assert(x)
Verifies that a condition is met.
Definition assert.h:202
virtual ~CentroidalVoronoiTesselation()
Destructor.
void done_current()
Resets the current CentroidalVoronoiTesselation to nullptr.
Definition CVT.h:270
virtual void funcgrad(index_t n, double *x, double &f, double *g)
Computes the objective function and its gradient.
void set_volumetric(bool x)
Sets volumetric mode.
Definition CVT.h:357
double * embedding(index_t p)
Returns the representation of a point in embedding space.
Definition CVT.h:340
void resize_points(index_t nb_points)
Changes the number of points.
void unlock_point(index_t i)
Unlocks a point.
Definition CVT.h:397
CentroidalVoronoiTesselation(Mesh *mesh, const vector< vec3 > &R3_embedding, coord_index_t dimension=0, const std::string &delaunay="default")
Constructs a new CentroidalVoronoiTesselation.
void constrain_points(double *g) const
Constrains the locked points.
bool compute_initial_sampling(index_t nb_samples, bool verbose=false)
Computes a random initial sampling of the surface in nD.
void set_use_RVC_centroids(bool x)
Specifies whether centroids of Voronoi cells should be used.
Definition CVT.h:202
void compute_volume(Mesh *mesh)
Computes the volumetric mesh (using the current points).
const vec3 & R3_embedding(index_t p) const
Gets the representation of a point in R3.
Definition CVT.h:330
CentroidalVoronoiTesselation(Mesh *mesh, coord_index_t dimension=0, const std::string &delaunay="default")
Constructs a new CentroidalVoronoiTesselation.
void make_current()
Makes this CentroidalVoronoiTesselation the current one.
Definition CVT.h:256
void compute_R3_embedding()
Computes the 3d representation of the Nd points.
virtual void newiteration()
Callback for the numerical solver.
virtual void Lloyd_iterations(index_t nb_iter, bool safe_mode=false)
Relaxes the points with Lloyd's algorithm.
static void funcgrad_CB(index_t n, double *x, double &f, double *g)
Callback for the numerical solver.
coord_index_t dimension() const
Gets the dimension of the points.
Definition CVT.h:313
virtual void Newton_iterations(index_t nb_iter, index_t m=7)
Relaxes the points with Newton-Lloyd's algorithm.
bool point_is_locked(index_t i) const
Tests whether a point is locked.
Definition CVT.h:368
IntegrationSimplex_var simplex_func_
Integration simplex used by custom codes, e.g. LpCVT.
Definition CVT.h:466
void set_points(index_t nb_points, const double *points)
Initializes the points with a user-specified vector.
index_t nb_points() const
Gets the number of points to be optimized.
Definition CVT.h:320
void compute_surface(Mesh *mesh, bool multinerve=true)
Computes the surfacic mesh (using the current points).
void lock_point(index_t i)
Locks a point.
Definition CVT.h:382
static void newiteration_CB(index_t n, const double *x, double f, const double *g, double gnorm)
Callback for the numerical solver.
void unlock_all_points()
Unlocks all the points.
Definition CVT.h:412
void set_constrained_cvt(bool x)
Specifies whether constrained mode should be used.
Definition CVT.h:211
bool volumetric() const
Tests whether volumetric mode is used.
Definition CVT.h:348
void set_show_iterations(bool x)
Specifies whether a progress bar should be used.
Definition CVT.h:192
RestrictedVoronoiDiagram * RVD()
Definition CVT.h:232
void set_progress_logger(ProgressTask *progress)
Sets a client for the progress bars.
Definition CVT.h:305
void set_facets_range(index_t facets_begin, index_t facets_end)
Restricts computation to a part of the input mesh.
Definition CVT.h:243
Abstract interface for Delaunay triangulation in Nd.
Definition delaunay.h:71
Represents a mesh.
Definition mesh.h:3178
Tracks the progress of a task.
Definition progress.h:240
Computes a Restricted Voronoi Diagram (RVD).
Definition RVD.h:89
Vector with aligned memory allocation.
Definition memory.h:703
Abstract interface for Delaunay.
Common include file, providing basic definitions. Should be included before anything else by all head...
base classes for computing integrals over the cells of a restricted Voronoi diagram
The class that represents a mesh.
Global Vorpaline namespace.
Definition basic.h:55
vecng< 3, Numeric::float64 > vec3
Represents points and vectors in 3d.
Definition geometry.h:65
geo_index_t index_t
The type for storing and manipulating indices.
Definition numeric.h:341
SmartPointer< RestrictedVoronoiDiagram > RestrictedVoronoiDiagram_var
Smart pointer to a RestrictedVoronoiDiagram object.
Definition RVD.h:737
geo_coord_index_t coord_index_t
The type for storing coordinate indices, and iterating on the coordinates of a point.
Definition numeric.h:375