GCC Code Coverage Report


Directory: ./
File: tests/test_lifecycled_attribute/main.cpp
Date: 2026-09-07 02:36:43
Exec Total Coverage
Lines: 49 64 76.6%
Functions: 3 3 100.0%
Branches: 67 160 41.9%

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
41 #include <geogram/basic/common.h>
42 #include <geogram/basic/logger.h>
43 #include <geogram/basic/command_line.h>
44 #include <geogram/basic/command_line_args.h>
45 #include <geogram/mesh/mesh.h>
46 #include <geogram/mesh/mesh_io.h>
47 #include <geogram/mesh/mesh_subdivision.h>
48 #include <geogram/basic/stopwatch.h>
49 #include <stack>
50
51 // Tests lifecycled attribute
52
53 namespace {
54 using namespace GEO;
55
56 2 void create_attribute(Mesh& M) {
57
4/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 1 times.
4 if(!CmdLine::get_arg_bool("with_string_attribute")) {
58 1 return;
59 }
60
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
1 Attribute<std::string> str_id(M.vertices.attributes(),"str_id");
61
2/2
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 1 times.
13 for(index_t v: M.vertices) {
62
2/4
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
12 str_id[v] = String::to_string(v);
63 }
64 1 }
65
66 2 void create_geodesic_sphere(Mesh& M, index_t nb_subdivisions, bool quads) {
67 static vec3 points[] = {
68 {0, 0.0, 1.175571},
69 {1.051462, 0.0, 0.5257311},
70 {0.3249197, 1.0, 0.5257311},
71 {-0.8506508, 0.618034, 0.5257311},
72 {-0.8506508, -0.618034, 0.5257311},
73 {0.3249197, -1.0, 0.5257311},
74 {0.8506508, 0.618034, -0.5257311},
75 {0.8506508, -0.618034, -0.5257311},
76 {-0.3249197, 1.0, -0.5257311},
77 {-1.051462, 0.0, -0.5257311},
78 {-0.3249197, -1.0, -0.5257311},
79 {0.0, 0.0, -1.175571}
80
14/30
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 2 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 2 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 2 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 2 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 2 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 2 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 2 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 2 times.
✗ Branch 37 not taken.
✓ Branch 39 taken 2 times.
✗ Branch 40 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
2 };
81
82 static index_t facets[][3] = {
83 {0,1,2},
84 {0,2,3},
85 {0,3,4},
86 {0,4,5},
87 {0,5,1},
88 {1,5,7},
89 {1,7,6},
90 {1,6,2},
91 {2,6,8},
92 {2,8,3},
93 {3,8,9},
94 {3,9,4},
95 {4,9,10},
96 {4,10,5},
97 {5,10,7},
98 {6,7,11},
99 {6,11,8},
100 {7,10,11},
101 {8,11,9},
102 {9,11,10},
103 };
104
105 2 M.clear();
106 2 M.vertices.set_dimension(3);
107
108 2 M.vertices.create_vertices(12);
109
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 2 times.
26 for(index_t v=0; v<12; ++v) {
110 24 M.vertices.point(v) = points[v];
111 }
112
113
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 2 times.
42 for(index_t f=0; f<20; ++f) {
114 40 M.facets.create_triangle(
115 facets[f][0],
116 facets[f][1],
117 facets[f][2]
118 );
119 }
120
121 2 M.facets.connect();
122
123 2 create_attribute(M);
124
125 {
126
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 Stopwatch W("splitting");
127
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2 times.
14 for(index_t k=0; k<nb_subdivisions; ++k) {
128
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(quads) {
129 mesh_split_quads(M);
130 } else {
131
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 mesh_split_triangles(M);
132 }
133 }
134 2 }
135
136 {
137
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 Stopwatch W("normalizing");
138
6/10
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 81924 times.
✗ Branch 11 not taken.
✓ Branch 14 taken 81924 times.
✓ Branch 15 taken 2 times.
81926 for(vec3& p:M.vertices.points()) {
139
1/2
✓ Branch 1 taken 81924 times.
✗ Branch 2 not taken.
81924 p = normalize(p);
140 }
141 2 }
142 2 }
143 }
144
145
146 2 int main(int argc, char** argv) {
147 using namespace GEO;
148
149
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 GEO::initialize(GEO::GEOGRAM_INSTALL_ALL);
150
151
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
4 geo_register_attribute_type<std::string>("string");
152
153
154
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
4 CmdLine::import_arg_group("standard");
155
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 CmdLine::declare_arg(
156
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 "nb_subdivisions",4,
157
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
6 "number of subdivisions from icosahedron"
158 );
159
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 CmdLine::declare_arg(
160
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
10 "quads", false, "use quads instead of triangles"
161 );
162
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 CmdLine::declare_arg(
163
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
8 "with_string_attribute", true, "create a string attribute"
164 );
165 2 std::vector<std::string> filenames;
166
3/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
4 if(!CmdLine::parse(argc, argv, filenames, "<inputfile>")) {
167 return 1;
168 }
169 try {
170
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 Mesh M;
171
172
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if(filenames.size() >= 1) {
173 mesh_load(filenames[0], M);
174 create_attribute(M);
175 index_t nb_subdivisions = CmdLine::get_arg_uint("nb_subdivisions");
176 bool quads = CmdLine::get_arg_bool("quads");
177 Stopwatch W("splitting");
178 for(index_t k=0; k<nb_subdivisions; ++k) {
179 if(quads) {
180 mesh_split_quads(M);
181 } else {
182 mesh_split_triangles(M);
183 }
184 }
185 } else {
186 4 create_geodesic_sphere(
187 M,
188
3/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
2 CmdLine::get_arg_uint("nb_subdivisions"),
189
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
6 CmdLine::get_arg_bool("quads")
190 );
191 }
192
0/2
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 } catch(const std::exception& e) {
193 std::cerr << "Received an exception: " << e.what() << std::endl;
194 return 1;
195 }
196
197 2 return 0;
198 2 }
199