GCC Code Coverage Report


Directory: ./
File: lib/geogram_gfx/GLUP/GLUP_marching_cells.h
Date: 2026-09-07 02:28:19
Exec Total Coverage
Lines: 0 13 0.0%
Functions: 0 0 -%
Branches: 0 28 0.0%

Line Branch Exec Source
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>
44 #include <geogram_gfx/basic/common.h>
45 #include <geogram/basic/logger.h>
46 #include <geogram/mesh/mesh.h> // For cell descriptors / marching cells.
47
48 /**
49 * \file geogram_gfx/GLUP/GLUP_marching_cells.h
50 * \brief Implementation of the marching cells algorithms.
51 * \details Used to implement GLUP_CLIP_SLICE_CELLS clipping mode.
52 */
53
54 namespace GLUP {
55 using namespace GEO;
56
57 /**********************************************************************/
58
59 /**
60 * \brief Implements the MarchingCells algorithm.
61 * \details MarchingCell compute the intersection between
62 * a cell and a plane, using only combinatorial information.
63 * It uses the static tables from the Mesh class, so that cell
64 * numberings are coherent between storage and graphics.
65 */
66 class MarchingCell {
67 public:
68
69 /**
70 * \brief MarchingCell constructor
71 * \param[in] prim the GLUP volumetric primitive, should be one
72 * of GLUP_TETRAHEDRA, GLUP_HEXAHEDRA, GLUP_PRISMS, GLUP_PYRAMIDS.
73 */
74 MarchingCell(GLUPprimitive prim);
75
76 /**
77 * \brief MarchingCell destructor.
78 */
79 ~MarchingCell();
80
81 /**
82 * \brief Gets the number of vertices.
83 * \return the number of vertices in a cell
84 */
85 index_t nb_vertices() const {
86 return nb_vertices_;
87 }
88
89 /**
90 * \brief Gets the number of edges.
91 * \return the number of edges in a cell
92 */
93 index_t nb_edges() const {
94 return nb_edges_;
95 }
96
97
98 /**
99 * \brief Gets the number of configurations.
100 * \return the number of configurations
101 */
102 index_t nb_configs() const {
103 return nb_configs_;
104 }
105
106 /**
107 * \brief Gets a vertex by edge index and local vertex index.
108 * \param[in] e the index of the edge
109 * \param[in] lv the local vertex index in the edge, one of 0,1
110 * \return the vertex index
111 */
112 index_t edge_vertex(index_t e, index_t lv) const {
113 geo_debug_assert(e < nb_edges());
114 geo_debug_assert(lv < 2);
115 return edge_[e*2+lv];
116 }
117
118 /**
119 * \brief Gets the number of intersected edges in a configuration.
120 * \param[in] config the vertex configuration bitcode. The
121 * bit corresponding to vertex v is set if v is on the positive
122 * side of the intersection plane.
123 * \return the number of intersected edges in configuration \p config
124 */
125 index_t config_size(index_t config) const {
126 geo_debug_assert(config < nb_configs());
127 return config_size_[config];
128 }
129
130 /**
131 * \brief Gets the maximum configuration size.
132 * \return the largest number of vertices in an intersection polygon
133 */
134 index_t max_config_size() const {
135 return max_config_size_;
136 }
137
138 /**
139 * \brief Gets the list of intersected edges in a configuration.
140 * \param[in] config the vertex configuration bitcode. The
141 * bit corresponding to vertex v is set if v is on the positive
142 * side of the intersection plane.
143 * \return a pointer to the array of edge indices that correspond to
144 * this configuration, of size config_size()
145 */
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
151 /**
152 * \brief Gets the GLSL declaration of marching cell uniform state.
153 * \return a pointer to GLSL source code that declares this
154 * marching cell's uniform state.
155 */
156 const char* GLSL_uniform_state_declaration() const {
157 return GLSL_uniform_state_declaration_.c_str();
158 }
159
160 /**
161 * \brief Gets the GLSL declaration of the function that
162 * computes the intersections.
163 * \return a pointer to GLSL source code.
164 */
165 const char* GLSL_compute_intersections() const {
166 return GLSL_compute_intersections_.c_str();
167 }
168
169
170 /**
171 * \brief Gets the binding point of the uniform buffer that
172 * contains the tables for the marching cell.
173 * \return the uniform binding point
174 */
175 GLuint uniform_binding_point() const {
176 return uniform_binding_point_;
177 }
178
179 /**
180 * \brief Creates a Uniform Buffer Object that contains
181 * the tables for the marching cell.
182 * \details Used by GLUP150 and GLUP440 profiles that support
183 * UBOs. This MarchingCells keeps ownership of the created
184 * UBO (it is destroyed by the destructor of this MarchingCells).
185 */
186 GLuint create_UBO();
187
188 /**
189 * \brief Creates a Vertex Buffer Object with the indices
190 * for all configurations.
191 * \details Used by GLUPES2 that does not support UBOs.
192 * This MarchingCells keeps ownership of the created
193 * VBO (it is destroyed by the destructor of this MarchingCells).
194 * \note NOT USED YET.
195 */
196 GLuint create_elements_VBO();
197
198 /**
199 * \brief Binds the uniform state marching cell variables
200 * to a given program.
201 */
202 void bind_uniform_state(GLuint program);
203
204 protected:
205
206 /**
207 * \brief Computes the intersection polygon for a configuration.
208 * \param[in] config the vertex configuration bitcode. The
209 * bit corresponding to vertex v is set if v is on the positive
210 * side of the intersection plane.
211 */
212 void compute_config(index_t config);
213
214 /**
215 * \brief Moves from a given halfedge to the next halfege.
216 * \details The halfedge is refered to as a facet index and a
217 * local vertex index within the facet.
218 * \param[in,out] f the index of the facet
219 * \param[in,out] lv the local index of the vertex in the facet.
220 */
221 void move_to_next(index_t& f, index_t& lv) {
222 lv = (lv+1) % desc_->nb_vertices_in_facet[f];
223 }
224
225 /**
226 * \brief Gets the origin vertex of a halfedge.
227 * \details The halfedge is refered to as a facet index and a
228 * local vertex index within the facet.
229 * \param[in] f the index of the facet
230 * \param[in] lv the local index of the vertex in the facet.
231 * \return the index of the origin vertex of the halfedge
232 */
233 index_t origin_vertex(index_t f, index_t lv) {
234 return desc_->facet_vertex[f][lv];
235 }
236
237 /**
238 * \brief Gets the destination vertex of a halfedge.
239 * \details The halfedge is refered to as a facet index and a
240 * local vertex index within the facet.
241 * \param[in] f the index of the facet
242 * \param[in] lv the local index of the vertex in the facet.
243 * \return the index of the destination vertex of the halfedge
244 */
245 index_t destination_vertex(index_t f, index_t lv) {
246 move_to_next(f, lv);
247 return origin_vertex(f, lv);
248 }
249
250 /**
251 * \brief Gets the edge index that corresponds to a given halfedge.
252 * \details The halfedge is refered to as a facet index and a
253 * local vertex index within the facet.
254 * \param[in] f the index of the facet
255 * \param[in] lv the local index of the vertex in the facet.
256 * \return the index of the edge.
257 */
258 index_t edge(index_t f, index_t lv) {
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
266 /**
267 * \brief Moves from a given halfedge to the opposite halfege.
268 * \details The halfedge is refered to as a facet index and a
269 * local vertex index within the facet.
270 * \param[in,out] f the index of the facet
271 * \param[in,out] lv the local index of the vertex in the facet.
272 */
273 void move_to_opposite(index_t& f, index_t& lv);
274
275 /**
276 * \brief Tests whether a given edge is intersected.
277 * \details The halfedge is refered to as a facet index and a
278 * local vertex index within the facet.
279 * \param[in] f the index of the facet
280 * \param[in] lv the local index of the vertex in the facet.
281 * \param[in] config the vertex configuration bitcode. The
282 * bit corresponding to vertex v is set if v is on the positive
283 * side of the intersection plane.
284 * \retval true if the edge is intersected
285 * \retval false otherwise
286 */
287 bool edge_is_intersected(index_t f, index_t lv, index_t config) {
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
295 /**
296 * \brief Tests whether a vertex configuration bitcode is
297 * ambiguous.
298 * \details A configuration is ambiguous if it results in several
299 * intersection polygons.
300 * \param[in] config the vertex configuration bitcode. The
301 * bit corresponding to vertex v is set if v is on the positive
302 * side of the intersection plane.
303 * \retval true if the configuration is ambiguous
304 * \retval false otherwise
305 */
306 bool config_is_ambiguous(index_t config);
307
308 /**
309 * \brief Gets the first intersected halfedge given a
310 * vertex configuration.
311 * \param[out] f the facet of the first intersected halfedge
312 * \param[out] lv the local vertex index of the first intersected
313 * halfedge
314 * \param[in] config the vertex configuration bitcode. The
315 * bit corresponding to vertex v is set if v is on the positive
316 * side of the intersection plane.
317 * \retval true if there was an intersection
318 * \retval false otherwise
319 */
320 bool get_first_edge(index_t& f, index_t& lv, index_t config);
321
322 private:
323 /**
324 * \brief Forbids copy.
325 */
326 MarchingCell(const MarchingCell& rhs);
327
328 /**
329 * \brief Forbids copy.
330 */
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
355