GCC Code Coverage Report


Directory: ./
File: lib/geogram/mesh/mesh_convex_hull.cpp
Date: 2026-09-07 02:36:43
Exec Total Coverage
Lines: 20 36 55.6%
Functions: 1 2 50.0%
Branches: 31 108 28.7%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2000-2025 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/en/bruno-levy-1
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39
40 #include <geogram/mesh/mesh_convex_hull.h>
41 #include <geogram/mesh/mesh.h>
42 #include <geogram/mesh/mesh_geometry.h>
43 #include <geogram/mesh/mesh_io.h>
44 #include <geogram/delaunay/delaunay.h>
45 #include <geogram/numerics/predicates.h>
46
47 namespace GEO {
48
49 void compute_convex_hull_2d(Mesh& mesh) {
50 Delaunay_var delaunay = Delaunay::create(coord_index_t(2), "BDEL2d");
51 delaunay->set_keeps_infinite(true);
52 delaunay->set_vertices(mesh.vertices.nb(), mesh.vertices.point_ptr(0));
53 mesh.edges.clear();
54 for(index_t t=delaunay->nb_finite_cells(); t<delaunay->nb_cells(); ++t) {
55 index_t v1= NO_INDEX, v2=NO_INDEX;
56 for(index_t lv=0; lv<3; ++lv) {
57 if(delaunay->cell_vertex(t,lv) == NO_INDEX) {
58 v1 = delaunay->cell_vertex(t,(lv+1)%3);
59 v2 = delaunay->cell_vertex(t,(lv+2)%3);
60 }
61 }
62 geo_assert(v1 != NO_INDEX && v2 != NO_INDEX);
63 mesh.edges.create_edge(v2,v1);
64 }
65 mesh.vertices.remove_isolated();
66 }
67
68 1 void compute_convex_hull_3d(Mesh& mesh) {
69
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 Delaunay_var delaunay = Delaunay::create(coord_index_t(3), "PDEL");
70
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 delaunay->set_keeps_infinite(true);
71
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
1 delaunay->set_vertices(mesh.vertices.nb(), mesh.vertices.point_ptr(0));
72
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 mesh.facets.clear();
73
5/8
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1485 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1484 times.
✓ Branch 11 taken 1 times.
1485 for(index_t t=delaunay->nb_finite_cells(); t<delaunay->nb_cells(); ++t) {
74
2/4
✓ Branch 1 taken 1484 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1484 times.
✗ Branch 5 not taken.
1484 index_t v0 = delaunay->cell_vertex(t,0);
75
2/4
✓ Branch 1 taken 1484 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1484 times.
✗ Branch 5 not taken.
1484 index_t v1 = delaunay->cell_vertex(t,1);
76
2/4
✓ Branch 1 taken 1484 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1484 times.
✗ Branch 5 not taken.
1484 index_t v2 = delaunay->cell_vertex(t,2);
77
2/4
✓ Branch 1 taken 1484 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1484 times.
✗ Branch 5 not taken.
1484 index_t v3 = delaunay->cell_vertex(t,3);
78
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1484 times.
1484 if(v0 == NO_INDEX) {
79 mesh.facets.create_triangle(v3,v2,v1);
80
2/2
✓ Branch 0 taken 625 times.
✓ Branch 1 taken 859 times.
1484 } else if(v1 == NO_INDEX) {
81
1/2
✓ Branch 1 taken 625 times.
✗ Branch 2 not taken.
625 mesh.facets.create_triangle(v0,v2,v3);
82
2/2
✓ Branch 0 taken 329 times.
✓ Branch 1 taken 530 times.
859 } else if(v2 == NO_INDEX) {
83
1/2
✓ Branch 1 taken 329 times.
✗ Branch 2 not taken.
329 mesh.facets.create_triangle(v0,v3,v1);
84
1/2
✓ Branch 0 taken 530 times.
✗ Branch 1 not taken.
530 } else if(v3 == NO_INDEX) {
85
1/2
✓ Branch 1 taken 530 times.
✗ Branch 2 not taken.
530 mesh.facets.create_triangle(v0,v1,v2);
86 }
87 }
88
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 mesh.vertices.remove_isolated();
89
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 mesh.facets.connect();
90 1 }
91 }
92