Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
GLUP_marching_cells.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_GFX_GLUP_GLUP_MARCHING_CELLS
41 #define GEOGRAM_GFX_GLUP_GLUP_MARCHING_CELLS
42 
43 #include <geogram_gfx/GLUP/GLUP.h>
45 #include <geogram/basic/logger.h>
46 #include <geogram/mesh/mesh.h> // For cell descriptors / marching cells.
47 
54 namespace GLUP {
55  using namespace GEO;
56 
57  /**********************************************************************/
58 
66  class MarchingCell {
67  public:
68 
75 
80 
85  index_t nb_vertices() const {
86  return nb_vertices_;
87  }
88 
93  index_t nb_edges() const {
94  return nb_edges_;
95  }
96 
97 
102  index_t nb_configs() const {
103  return nb_configs_;
104  }
105 
113  geo_debug_assert(e < nb_edges());
114  geo_debug_assert(lv < 2);
115  return edge_[e*2+lv];
116  }
117 
125  index_t config_size(index_t config) const {
126  geo_debug_assert(config < nb_configs());
127  return config_size_[config];
128  }
129 
135  return max_config_size_;
136  }
137 
146  const index_t* config_edges(index_t config) const {
147  geo_debug_assert(config < nb_configs());
148  return config_ + config * nb_edges_;
149  }
150 
156  const char* GLSL_uniform_state_declaration() const {
157  return GLSL_uniform_state_declaration_.c_str();
158  }
159 
165  const char* GLSL_compute_intersections() const {
166  return GLSL_compute_intersections_.c_str();
167  }
168 
169 
175  GLuint uniform_binding_point() const {
176  return uniform_binding_point_;
177  }
178 
186  GLuint create_UBO();
187 
197 
202  void bind_uniform_state(GLuint program);
203 
204  protected:
205 
212  void compute_config(index_t config);
213 
221  void move_to_next(index_t& f, index_t& lv) {
222  lv = (lv+1) % desc_->nb_vertices_in_facet[f];
223  }
224 
234  return desc_->facet_vertex[f][lv];
235  }
236 
246  move_to_next(f, lv);
247  return origin_vertex(f, lv);
248  }
249 
259  index_t v1 = origin_vertex(f, lv);
260  index_t v2 = destination_vertex(f, lv);
261  index_t result = vv_to_e_[v1*desc_->nb_vertices+v2];
262  geo_debug_assert(result != index_t(-1));
263  return result;
264  }
265 
274 
288  index_t v1 = origin_vertex(f, lv);
289  index_t v2 = destination_vertex(f, lv);
290  bool v1_in = ((config & 1u<<v1) != 0);
291  bool v2_in = ((config & 1u<<v2) != 0);
292  return (v1_in != v2_in);
293  }
294 
307 
320  bool get_first_edge(index_t& f, index_t& lv, index_t config);
321 
322  private:
326  MarchingCell(const MarchingCell& rhs);
327 
331  MarchingCell& operator=(const MarchingCell& rhs);
332 
333  private:
334  const CellDescriptor* desc_;
335  index_t vv_to_e_[64];
336  index_t nb_vertices_;
337  index_t nb_configs_;
338  index_t* config_size_;
339  index_t max_config_size_;
340  index_t* config_;
341  index_t nb_edges_;
342  index_t* edge_;
343  std::string GLSL_uniform_state_declaration_;
344  std::string GLSL_compute_intersections_;
345  GLuint uniform_binding_point_;
346  GLuint UBO_;
347  GLuint elements_VBO_;
348  };
349 
350  /**********************************************************************/
351 
352 }
353 
354 #endif
GLUP: GL Useful Primitives.
GLUPprimitive
Symbolic values corresponding to GLUP primitive types.
Definition: GLUP.h:470
#define geo_debug_assert(x)
Verifies that a condition is met.
Definition: assert.h:196
Implements the MarchingCells algorithm.
GLuint create_UBO()
Creates a Uniform Buffer Object that contains the tables for the marching cell.
index_t nb_edges() const
Gets the number of edges.
index_t origin_vertex(index_t f, index_t lv)
Gets the origin vertex of a halfedge.
index_t nb_vertices() const
Gets the number of vertices.
void move_to_opposite(index_t &f, index_t &lv)
Moves from a given halfedge to the opposite halfege.
MarchingCell(GLUPprimitive prim)
MarchingCell constructor.
bool get_first_edge(index_t &f, index_t &lv, index_t config)
Gets the first intersected halfedge given a vertex configuration.
GLuint uniform_binding_point() const
Gets the binding point of the uniform buffer that contains the tables for the marching cell.
void move_to_next(index_t &f, index_t &lv)
Moves from a given halfedge to the next halfege.
index_t config_size(index_t config) const
Gets the number of intersected edges in a configuration.
GLuint create_elements_VBO()
Creates a Vertex Buffer Object with the indices for all configurations.
bool edge_is_intersected(index_t f, index_t lv, index_t config)
Tests whether a given edge is intersected.
const char * GLSL_uniform_state_declaration() const
Gets the GLSL declaration of marching cell uniform state.
index_t max_config_size() const
Gets the maximum configuration size.
index_t destination_vertex(index_t f, index_t lv)
Gets the destination vertex of a halfedge.
void bind_uniform_state(GLuint program)
Binds the uniform state marching cell variables to a given program.
const char * GLSL_compute_intersections() const
Gets the GLSL declaration of the function that computes the intersections.
index_t edge_vertex(index_t e, index_t lv) const
Gets a vertex by edge index and local vertex index.
index_t nb_configs() const
Gets the number of configurations.
index_t edge(index_t f, index_t lv)
Gets the edge index that corresponds to a given halfedge.
const index_t * config_edges(index_t config) const
Gets the list of intersected edges in a configuration.
~MarchingCell()
MarchingCell destructor.
bool config_is_ambiguous(index_t config)
Tests whether a vertex configuration bitcode is ambiguous.
void compute_config(index_t config)
Computes the intersection polygon for a configuration.
Common include file, providing basic definitions. Should be included before anything else by all head...
Generic logging mechanism.
The class that represents a mesh.
Global Vorpaline namespace.
Definition: basic.h:55
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
Lookup tables that describe the combinatorics of each cell type.
Definition: mesh.h:1475