Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
RVD_callback.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_RVD_CALLBACK
41 #define GEOGRAM_VORONOI_RVD_CALLBACK
42 
43 #include <geogram/basic/common.h>
45 #include <geogram/mesh/mesh.h>
46 #include <geogram/basic/numeric.h>
49 
50 namespace GEOGen {
51  class SymbolicVertex;
52  class Polygon;
53  class ConvexCell;
54 }
55 
56 namespace GEO {
57  class RVDVertexMap;
58  class Mesh;
59 }
60 
67 namespace GEO {
68 
69  /***************************************************************/
70 
76  class GEOGRAM_API RVDCallback {
77  public:
78 
83 
87  virtual ~RVDCallback();
88 
92  virtual void begin();
93 
97  virtual void end();
98 
107  index_t seed() const {
108  return seed_;
109  }
110 
120  index_t simplex() const {
121  return simplex_;
122  }
123 
132  spinlocks_ = spinlocks;
133  }
134 
135  protected:
136  index_t seed_;
137  index_t simplex_;
138  Process::SpinLockArray* spinlocks_;
139  };
140 
141  /***************************************************************/
142 
153  class GEOGRAM_API RVDPolygonCallback : public RVDCallback {
154  public:
155 
160 
165 
169  void begin() override;
170 
174  void end() override;
175 
183  virtual void operator() (
184  index_t v,
185  index_t t,
186  const GEOGen::Polygon& C
187  ) const;
188 
189  };
190 
191  /***************************************************************/
192 
202  class GEOGRAM_API RVDPolyhedronCallback : public RVDCallback {
203  public:
204 
209 
214 
218  void begin() override;
219 
223  void end() override;
224 
225 
238  virtual void operator() (
239  index_t v,
240  index_t t,
241  const GEOGen::ConvexCell& C
242  ) const;
243 
244 
252  virtual void begin_polyhedron(index_t seed, index_t tetrahedron);
253 
266  virtual void begin_facet(index_t facet_seed, index_t facet_tet);
267 
273  virtual void vertex(
274  const double* geometry, const GEOGen::SymbolicVertex& symb
275  );
276 
280  virtual void end_facet();
281 
285  virtual void end_polyhedron();
286 
295  index_t tet() const {
296  return simplex();
297  }
298 
308  index_t facet_seed() const {
309  return facet_seed_;
310  }
311 
322  index_t facet_tet() const {
323  return facet_tet_;
324  }
325 
337  simplify_internal_tet_facets_ = x;
338  }
339 
351  simplify_voronoi_facets_ = x;
352  if(x) {
353  set_simplify_internal_tet_facets(true);
354  set_use_mesh(true);
355  }
356  }
357 
372  void set_simplify_boundary_facets(bool x, double angle_threshold=45.0) {
373  simplify_boundary_facets_ = x;
374  if(x) {
375  set_simplify_voronoi_facets(true);
376  simplify_boundary_facets_angle_threshold_ = angle_threshold;
377  } else {
378  simplify_boundary_facets_angle_threshold_ = 0.0;
379  }
380  }
381 
389  tessellate_non_convex_facets_ = x;
390  }
391 
392 
400  void set_use_mesh(bool x);
401 
408  void set_dimension(index_t dim) {
409  if(use_mesh_) {
410  mesh_.vertices.set_dimension(dim);
411  }
412  }
413 
414  protected:
422  index_t seed, index_t tetrahedron
423  );
424 
431  virtual void begin_facet_internal(
432  index_t facet_seed, index_t facet_tet
433  );
434 
441  virtual void vertex_internal(
442  const double* geometry, const GEOGen::SymbolicVertex& symb
443  );
444 
451  virtual void end_facet_internal();
452 
459  virtual void end_polyhedron_internal();
460 
471  virtual void process_polyhedron_mesh();
472 
473  protected:
474 
475  index_t facet_seed_;
476  index_t facet_tet_;
477  index_t last_seed_;
478 
479  bool simplify_internal_tet_facets_;
480  bool simplify_voronoi_facets_;
481  bool simplify_boundary_facets_;
482  double simplify_boundary_facets_angle_threshold_;
483  bool tessellate_non_convex_facets_;
484 
485  bool use_mesh_;
486  bool facet_is_skipped_;
487 
488  Mesh mesh_;
489  Attribute<GEOGen::SymbolicVertex> mesh_vertex_sym_;
490  Attribute<index_t> mesh_facet_seed_;
491  Attribute<index_t> mesh_facet_tet_;
492  RVDVertexMap* vertex_map_;
493  vector<index_t> base_current_facet_;
494  };
495 
496  /***************************************************************/
497 
505  class GEOGRAM_API BuildRVDMesh : public RVDPolyhedronCallback {
506  public:
507 
512  BuildRVDMesh(Mesh& output_mesh);
513 
517  ~BuildRVDMesh() override;
518 
530  void set_generate_ids(bool x);
531 
537  void set_shrink(double x);
538 
542  void begin() override;
543 
547  void end() override;
548 
555  void begin_polyhedron(index_t seed, index_t tetrahedron) override;
556 
560  void begin_facet(index_t facet_seed, index_t facet_tet_facet) override;
561 
565  void vertex(
566  const double* geometry, const GEOGen::SymbolicVertex& symb
567  ) override;
568 
572  void end_facet() override;
573 
577  void end_polyhedron() override;
578 
582  void process_polyhedron_mesh() override;
583 
584  private:
585  vector<index_t> current_facet_;
586  Mesh& output_mesh_;
587  RVDVertexMap* global_vertex_map_;
588  RVDVertexMap* cell_vertex_map_;
589  double shrink_;
590  bool generate_ids_;
591  Attribute<int> cell_id_;
592  Attribute<int> seed_id_;
593  Attribute<int> vertex_id_;
594  Attribute<int> facet_seed_id_;
595  index_t current_cell_id_;
596  };
597 
598 
599  /***************************************************************/
600 
601 }
602 
603 #endif
Generic mechanism for attributes.
Computes the intersection between a set of halfspaces.
Internal representation of polygons for GenericVoronoiDiagram.
A set of three integers that encodes the equation of a vertex in GenericVoronoiDiagram.
Constructs a polyhedral mesh from a restricted Voronoi diagram.
Definition: RVD_callback.h:505
void end() override
Called at the end of RVD traversal.
void begin_facet(index_t facet_seed, index_t facet_tet_facet) override
Called at the beginning of each facet of each intersection polyhedron.
void end_polyhedron() override
Called at the end of each polyhedron.
BuildRVDMesh(Mesh &output_mesh)
BuildRVDMesh constructor.
void begin() override
Called at the beginning of RVD traversal.
void set_generate_ids(bool x)
Specifies whether ids should be generated.
void begin_polyhedron(index_t seed, index_t tetrahedron) override
Called at the beginning of each RVD polyhedron.
~BuildRVDMesh() override
BuildRVDMesh destructor.
void end_facet() override
Called at the end of each polyhedron facet.
void set_shrink(double x)
Defines the optional shrink factor for cells.
void vertex(const double *geometry, const GEOGen::SymbolicVertex &symb) override
Called for each vertex of the current facet.
void process_polyhedron_mesh() override
If use_mesh is set, then this function is called for each generated mesh.
Represents a mesh.
Definition: mesh.h:2693
An array of light-weight synchronisation primitives (spinlocks).
Definition: thread_sync.h:301
Baseclass for user functions called for each element (polygon or polyhedron) of a restricted Voronoi ...
Definition: RVD_callback.h:76
index_t simplex() const
Gets the index of the simplex that corresponds to the current polygon/polyhedron.
Definition: RVD_callback.h:120
void set_spinlocks(Process::SpinLockArray *spinlocks)
Sets the spinlocks array.
Definition: RVD_callback.h:131
virtual ~RVDCallback()
RVDCallback destructor.
virtual void end()
Called at the end of the RVD traversal.
virtual void begin()
Called at the beginning of the RVD traversal.
index_t seed() const
Gets the index of the seed that corresponds to the current polygon/polyhedron.
Definition: RVD_callback.h:107
RVDCallback()
RVDCallback constructor.
Baseclass for user functions called for each polygon of a surfacic restricted Voronoi diagram.
Definition: RVD_callback.h:153
void end() override
Called at the end of the RVD traversal.
RVDPolygonCallback()
PolyhedronCallback constructor.
void begin() override
Called at the beginning of the RVD traversal.
~RVDPolygonCallback() override
PolyhedronCallback destructor.
Baseclass for user functions called for each polyhedron of a volumetric restricted Voronoi diagram.
Definition: RVD_callback.h:202
~RVDPolyhedronCallback() override
PolyhedronCallback destructor.
virtual void vertex(const double *geometry, const GEOGen::SymbolicVertex &symb)
Called for each vertex of the current facet.
void set_simplify_boundary_facets(bool x, double angle_threshold=45.0)
Specifies whether boundary facets should be simplified.
Definition: RVD_callback.h:372
virtual void begin_facet(index_t facet_seed, index_t facet_tet)
Called at the beginning of each facet of each intersection polyhedron.
RVDPolyhedronCallback()
PolyhedronCallback constructor.
void begin() override
Called at the beginning of the RVD traversal.
virtual void end_polyhedron()
Called at the end of each polyhedron.
void set_simplify_voronoi_facets(bool x)
Specifies whether Voronoi facets should be simplified.
Definition: RVD_callback.h:350
void set_use_mesh(bool x)
Specifies whether a mesh should be built for each traversed polyhedron.
index_t tet() const
Gets the index of the tetrahedron that corresponds to the current polyhedron.
Definition: RVD_callback.h:295
virtual void end_facet_internal()
Filters callbacks between operator() and client callbacks.
void set_simplify_internal_tet_facets(bool x)
Specifies whether internal tetrahedron facets should be removed.
Definition: RVD_callback.h:336
void end() override
Called at the end of the RVD traversal.
virtual void end_polyhedron_internal()
Filters callbacks between operator() and client callbacks.
virtual void begin_facet_internal(index_t facet_seed, index_t facet_tet)
Filters callbacks between operator() and client callbacks.
virtual void begin_polyhedron_internal(index_t seed, index_t tetrahedron)
Filters callbacks between operator() and client callbacks.
index_t facet_tet() const
Gets the index of the tetrahedron adjacent to the current facet or index_t(-1) if there is no such fa...
Definition: RVD_callback.h:322
virtual void begin_polyhedron(index_t seed, index_t tetrahedron)
Called at the beginning of each intersection polyhedron.
index_t facet_seed() const
Gets the index of the seed that defines the bisector on which the current facet lies,...
Definition: RVD_callback.h:308
void set_dimension(index_t dim)
Sets the dimension of the internal mesh if need be.
Definition: RVD_callback.h:408
void set_tessellate_non_convex_facets(bool x)
Specifies whether non-convex facets should be tessellated.
Definition: RVD_callback.h:388
virtual void vertex_internal(const double *geometry, const GEOGen::SymbolicVertex &symb)
Filters callbacks between operator() and client callbacks.
virtual void process_polyhedron_mesh()
If use_mesh is set, then this function is called for each generated mesh.
virtual void end_facet()
Called at the end of each polyhedron facet.
RVDVertexMap maps symbolic vertices to unique ids.
Types and utilities for manipulating vertices in geometric and symbolic forms in restricted Voronoi d...
Common include file, providing basic definitions. Should be included before anything else by all head...
The class that represents a mesh.
Global Vorpaline namespace.
Definition: basic.h:55
GEOGen::SymbolicVertex SymbolicVertex
Symbolic representation of a RestrictedVoronoiDiagram vertex.
Definition: generic_RVD.h:2520
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
Types and functions for numbers manipulation.
Functions and classes for process manipulation.