Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
RVD_mesh_builder.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_MESH_BUILDER
41 #define GEOGRAM_VORONOI_RVD_MESH_BUILDER
42 
43 #include <geogram/basic/common.h>
45 #include <geogram/mesh/mesh.h>
46 #include <geogram/mesh/index.h>
48 #include <geogram/basic/argused.h>
49 
50 #include <vector>
51 #include <map>
52 
61 namespace GEO {
62 
72  class GEOGRAM_API RVDVertexMap {
73  public:
78 
91  index_t center_vertex_id, const SymbolicVertex& sym
92  );
93 
100  nb_vertices_ = i;
101  }
102 
103  protected:
108  index_t result = nb_vertices_;
109  nb_vertices_++;
110  return result;
111  }
112 
117  index_t nb_bisectors(const signed_trindex& sym) const {
118  index_t result = 0;
119  for(index_t i = 0; i < 3; i++) {
120  if(sym.indices[i] >= 0) {
121  result++;
122  }
123  }
124  return result;
125  }
126 
127  private:
128  // Maps (+++)-center vertex id quadruples to unique vertex id
129  // +++ encodes a Voronoi vertex
130  std::map<quadindex, index_t> ppp_to_id_;
131 
132  // Maps (++-)-center vertex id quadruples to unique vertex id
133  // ++- encodes the intersection between a Voronoi edge (++) and
134  // a facet of the boundary (-).
135  std::map<signed_quadindex, index_t> ppm_to_id_;
136 
137  // Maps (+--)-center vertex id quadruples to unique vertex id
138  // +-- encodes the intersection between a Voronoi facet (+) and
139  // an edge of the boundary (--).
140  std::map<signed_quadindex, index_t> pmm_to_id_;
141 
142  // Maps boundary vertex index to unique vertex id.
143  vector<signed_index_t> bv_to_id_;
144  index_t nb_vertices_;
145  };
146 
147  /************************************************************************/
148 
158  public:
166  Mesh* target, Mesh* reference,
167  Delaunay*
168  ) :
169  target_(target),
170  nb_vertices_(0)
171  {
172  dim_ = coord_index_t(reference->vertices.dimension());
173  current_seed_ = max_index_t();
174  }
175 
179  void begin_surface() {
180  target_->clear();
181  target_->vertices.set_dimension(dim_);
182  facet_region_.bind(target_->facets.attributes(),"region");
183  }
184 
191  void begin_reference_facet(index_t ref_facet) {
192  geo_argused(ref_facet);
193  }
194 
201  void begin_facet(index_t seed) {
202  current_seed_ = seed;
203  facet_vertices_.resize(0);
204  }
205 
212  const double* point, const SymbolicVertex& sym
213  ) {
214  index_t id = vertex_map_.find_or_create_vertex(
215  current_seed_, sym
216  );
217  if(id >= nb_vertices_) {
218  index_t v = target_->vertices.create_vertex();
219  for(index_t c=0; c<dim_; ++c) {
220  target_->vertices.point_ptr(v)[c] = point[c];
221  }
222  nb_vertices_ = id + 1;
223  }
224  facet_vertices_.push_back(id);
225  }
226 
232  void end_facet() {
233  index_t f = target_->facets.create_polygon(facet_vertices_.size());
234  for(index_t lv=0; lv<facet_vertices_.size(); ++lv) {
235  target_->facets.set_vertex(f,lv,facet_vertices_[lv]);
236  }
237  facet_region_[f] = current_seed_;
238  }
239 
245  }
246 
250  void end_surface() {
251  target_->facets.connect();
252  facet_region_.unbind();
253  }
254 
261  geo_argused(x);
262  // TODO - Not implemented yet
263  }
264 
265  private:
266  Mesh* target_;
267  Attribute<index_t> facet_region_;
268  RVDVertexMap vertex_map_;
269  coord_index_t dim_;
270  index_t current_seed_;
271  index_t nb_vertices_;
272  vector<index_t> facet_vertices_;
273  };
274 
275  /************************************************************************/
276 }
277 
278 #endif
A function to suppress unused parameters compilation warnings.
Generic mechanism for attributes.
A set of three integers that encodes the equation of a vertex in GenericVoronoiDiagram.
void unbind()
Unbinds this Attribute.
Definition: attributes.h:1147
void bind(AttributesManager &manager, const std::string &name)
Binds this Attribute to an AttributesManager.
Definition: attributes.h:1168
Abstract interface for Delaunay triangulation in Nd.
Definition: delaunay.h:71
void connect()
Connects the facets.
index_t create_polygon(index_t nb_vertices)
Creates a polygonal facet.
Definition: mesh.h:1300
void set_vertex(index_t f, index_t lv, index_t v)
Sets a vertex by facet and local vertex index.
Definition: mesh.h:1065
AttributesManager & attributes() const
Gets the attributes manager.
Definition: mesh.h:100
const double * point_ptr(index_t v) const
Gets a point.
Definition: mesh.h:455
void set_dimension(index_t dim)
Sets the dimension of the vertices.
Definition: mesh.h:440
index_t dimension() const
Gets the dimension of the vertices.
Definition: mesh.h:427
index_t create_vertex()
Creates a new vertex.
Definition: mesh.h:344
Represents a mesh.
Definition: mesh.h:2693
void clear(bool keep_attributes=true, bool keep_memory=false)
Removes all the elements and attributes of this mesh.
Builds a Mesh using the symbolic information in the vertices computed by a RestrictedVoronoiDiagram.
RVDMeshBuilder(Mesh *target, Mesh *reference, Delaunay *)
Constructs a new RVDMeshBuilder.
void begin_surface()
Starts to build a new surface.
void add_vertex_to_facet(const double *point, const SymbolicVertex &sym)
Adds a vertex to the current facet.
void begin_facet(index_t seed)
Starts a new facet of the restricted Voronoi diagram.
void end_surface()
Terminates the current surface.
void begin_reference_facet(index_t ref_facet)
Starts a new reference facet.
void end_facet()
Terminates the current facet.
void set_dimension(coord_index_t x)
Specifies the dimension to be used.
void end_reference_facet()
Terminates the current reference facet.
RVDVertexMap maps symbolic vertices to unique ids.
index_t nb_bisectors(const signed_trindex &sym) const
Gets the number of bisectors represented in a symbolic vertex.
void set_first_vertex_index(index_t i)
Defines the index of the first created vertex.
RVDVertexMap()
Constructs an empty map.
index_t new_vertex()
Allocates a new vertex.
index_t find_or_create_vertex(index_t center_vertex_id, const SymbolicVertex &sym)
Maps the symbolic information of a vertex into a unique identifier.
index_t size() const
Gets the number of elements.
Definition: memory.h:674
Generic implementation of restricted Voronoi diagrams.
Common include file, providing basic definitions. Should be included before anything else by all head...
Classes for managing tuples of indices.
basic_trindex< signed_index_t > signed_trindex
A basic_trindex made of 3 signed integers.
Definition: index.h:429
The class that represents a mesh.
Global Vorpaline namespace.
Definition: basic.h:55
index_t max_index_t()
Gets the maximum positive value of type index_t.
Definition: numeric.h:334
void geo_argused(const T &)
Suppresses compiler warnings about unused parameters.
Definition: argused.h:60
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
geo_coord_index_t coord_index_t
The type for storing coordinate indices, and iterating on the coordinates of a point.
Definition: numeric.h:363