GCC Code Coverage Report


Directory: ./
File: tests/test_convex_cell/main.cpp
Date: 2026-09-07 02:37:58
Exec Total Coverage
Lines: 122 258 47.3%
Functions: 3 6 50.0%
Branches: 163 583 28.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 #include <geogram/basic/common.h>
41 #include <geogram/basic/logger.h>
42 #include <geogram/basic/command_line.h>
43 #include <geogram/basic/command_line_args.h>
44 #include <geogram/basic/line_stream.h>
45 #include <geogram/basic/stopwatch.h>
46 #include <geogram/basic/geometry.h>
47 #include <geogram/voronoi/generic_RVD_cell.h>
48 #include <geogram/mesh/mesh_halfedges.h>
49 #include <geogram/mesh/mesh_io.h>
50 #include <geogram/mesh/mesh_topology.h>
51 #include <geogram/mesh/mesh_geometry.h>
52
53 namespace {
54
55 using namespace GEO;
56 using GEOGen::ConvexCell;
57
58 /**
59 * \brief Creates a mesh from a cube.
60 * \details Creates a mesh that represents a cube centered on the
61 * origin, with a edge length of 2.
62 * \param[out] M the resulting mesh
63 */
64 18 void initialize_mesh_with_box(Mesh& M) {
65 18 M.clear();
66 18 M.vertices.set_dimension(3);
67
68
1/2
✓ Branch 3 taken 18 times.
✗ Branch 4 not taken.
18 M.vertices.create_vertex(vec3(-1, -1, -1).data());
69
1/2
✓ Branch 3 taken 18 times.
✗ Branch 4 not taken.
18 M.vertices.create_vertex(vec3(-1, -1, 1).data());
70
1/2
✓ Branch 3 taken 18 times.
✗ Branch 4 not taken.
18 M.vertices.create_vertex(vec3(-1, 1, -1).data());
71
1/2
✓ Branch 3 taken 18 times.
✗ Branch 4 not taken.
18 M.vertices.create_vertex(vec3(-1, 1, 1).data());
72
1/2
✓ Branch 3 taken 18 times.
✗ Branch 4 not taken.
18 M.vertices.create_vertex(vec3(1, -1, -1).data());
73
1/2
✓ Branch 3 taken 18 times.
✗ Branch 4 not taken.
18 M.vertices.create_vertex(vec3(1, -1, 1).data());
74
1/2
✓ Branch 3 taken 18 times.
✗ Branch 4 not taken.
18 M.vertices.create_vertex(vec3(1, 1, -1).data());
75
1/2
✓ Branch 3 taken 18 times.
✗ Branch 4 not taken.
18 M.vertices.create_vertex(vec3(1, 1, 1).data());
76
77 18 M.facets.create_quad(7,6,2,3);
78 18 M.facets.create_quad(1,3,2,0);
79 18 M.facets.create_quad(5,7,3,1);
80 18 M.facets.create_quad(4,6,7,5);
81 18 M.facets.create_quad(4,5,1,0);
82 18 M.facets.create_quad(6,4,0,2);
83
84 18 M.facets.connect();
85 18 }
86
87 /**
88 * \brief Saves a Delaunay triangulation to a file
89 * \details Saves the vertices of the Delaunay triangulation \p delaunay
90 * to file \p filename;
91 * \param[in] delaunay a Delaunay triangulation
92 * \param[in] filename path to the file to save
93 * \retval true if the file could be successfully saved
94 * \retval false otherwise
95 */
96 bool save_points(const Delaunay* delaunay, const std::string& filename) {
97 std::ofstream out(filename.c_str());
98 if(!out) {
99 Logger::out("I/O")
100 << "Could not save points to file " << filename << "..."
101 << std::endl;
102 return false;
103 }
104
105 Logger::out("I/O")
106 << "Saving points to file " << filename << "..."
107 << std::endl;
108
109 out << delaunay->nb_vertices() << std::endl;
110 for(index_t i = 0; i < delaunay->nb_vertices(); ++i) {
111 for(coord_index_t c = 0; c < delaunay->dimension(); ++c) {
112 out << delaunay->vertex_ptr(i)[c] << ' ';
113 }
114 out << std::endl;
115 }
116 return true;
117 }
118
119 /**
120 * \brief Loads a XYZ point file
121 * \details Load points from file \p filename in XYZ format and stores the
122 * points coordinates to output vector \p points.
123 * \param[out] points output vector of points coordinates
124 * \param[in] filename path to the file to load
125 * \retval true if the file could be successfully loaded
126 * \retval false otherwise
127 */
128 18 bool load_points(
129 vector<double>& points,
130 const std::string& filename
131 ) {
132 try {
133
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 LineInput in(filename);
134
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
18 if(!in.OK()) {
135 return false;
136 }
137 18 index_t nb_points = 0;
138 18 index_t cur = 0;
139
6/8
✓ Branch 1 taken 6735 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6735 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6717 times.
✓ Branch 7 taken 18 times.
✓ Branch 8 taken 6717 times.
✓ Branch 9 taken 18 times.
6735 while(!in.eof() && in.get_line()) {
140
1/2
✓ Branch 1 taken 6717 times.
✗ Branch 2 not taken.
6717 in.get_fields();
141
2/3
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 6699 times.
✗ Branch 3 not taken.
6717 switch(in.nb_fields()) {
142 18 case 1:
143 {
144
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 nb_points = in.field_as_uint(0);
145
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 points.resize(3 * nb_points);
146 18 } break;
147 6699 case 3:
148 {
149
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6699 times.
6699 if(cur >= nb_points) {
150 Logger::err("I/O")
151 << "too many points in .xyz file"
152 << std::endl;
153 return false;
154 }
155
2/4
✓ Branch 1 taken 6699 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6699 times.
✗ Branch 5 not taken.
6699 points[3 * cur] = in.field_as_double(0);
156
2/4
✓ Branch 1 taken 6699 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6699 times.
✗ Branch 5 not taken.
6699 points[3 * cur + 1] = in.field_as_double(1);
157
2/4
✓ Branch 1 taken 6699 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6699 times.
✗ Branch 5 not taken.
6699 points[3 * cur + 2] = in.field_as_double(2);
158 6699 ++cur;
159 6699 } break;
160 default:
161 {
162 Logger::err("I/O")
163 << "invalid number of fields in .xyz file"
164 << std::endl;
165 return false;
166 }
167 }
168 }
169
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 }
170 catch(const std::exception& ex) {
171 Logger::err("I/O") << ex.what() << std::endl;
172 return false;
173 }
174 18 return true;
175 }
176
177 /**
178 * \brief Creates a random point-set on the surface of a sphere
179 * \details Generates \p nb_vertices vertices randomly distributed on the
180 * surface of a sphere centered on [0.5, 0.5, 0.5] with radius 1. The
181 * generated vertices are stored to output vector \p vertices.
182 * \param[out] vertices output vector of vertices coordinates
183 * \param[in] nb_vertices number of vertices to generate
184 */
185 void init_sphere(vector<double>& vertices, index_t nb_vertices) {
186 vertices.resize((nb_vertices + 1) * 3);
187 vertices[0] = 0.0;
188 vertices[1] = 0.0;
189 vertices[2] = 0.0;
190 for(index_t i = 1; i < nb_vertices + 1; ++i) {
191 vec3 v(
192 Numeric::random_float64(),
193 Numeric::random_float64(),
194 Numeric::random_float64()
195 );
196 v = normalize(v - vec3(0.5, 0.5, 0.5));
197 vertices[3 * i] = v[0];
198 vertices[3 * i + 1] = v[1];
199 vertices[3 * i + 2] = v[2];
200 }
201 }
202
203 /**
204 * \brief Creates a random point-set on the surface of a cone
205 * \details Generates \p nb_vertices vertices randomly distributed on the
206 * surface of a cone. The generated vertices are stored to output vector
207 * \p vertices.
208 * \param[out] vertices output vector of vertices coordinates
209 * \param[in] nb_vertices number of vertices to generate
210 * \param[in] use_random_vertices if true, random angular sampling is used
211 */
212 void init_cone(
213 vector<double>& vertices, index_t nb_vertices,
214 bool use_random_vertices=true
215 ) {
216 vertices.resize((nb_vertices + 1) * 3);
217 vertices[0] = 0.0;
218 vertices[1] = 0.0;
219 vertices[2] = 0.0;
220 for(index_t i = 1; i < nb_vertices + 1; ++i) {
221 vec3 N;
222 if(use_random_vertices) {
223 N = vec3(
224 Numeric::random_float64(), Numeric::random_float64(), 0.0
225 );
226 N = 2.0 * N - vec3(1.0, 1.0, 0.0);
227 } else {
228 double s = ::sin(
229 double(i) * 2.0 * M_PI / double(nb_vertices - 1)
230 );
231 double c = ::cos(
232 double(i) * 2.0 * M_PI / double(nb_vertices - 1)
233 );
234 N = vec3(s, c, 0.0);
235 }
236 N = normalize(N);
237 N = N - vec3(0.0, 0.0, 1.0);
238 vertices[3 * i] = N[0];
239 vertices[3 * i + 1] = N[1];
240 vertices[3 * i + 2] = N[2];
241 }
242 }
243 }
244
245 19 int main(int argc, char** argv) {
246
247 using namespace GEO;
248 using GEOGen::ConvexCell;
249
250 19 GEO::initialize(GEO::GEOGRAM_INSTALL_ALL);
251 19 int result = 0;
252
253 try {
254
255
2/4
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
19 Stopwatch W("Total time");
256
257 19 std::vector<std::string> filenames;
258
1/2
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
19 std::string output_filename = "out.eobj";
259 19 std::string points_filename;
260
261
2/4
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
38 CmdLine::import_arg_group("standard");
262
2/4
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
38 CmdLine::import_arg_group("algo");
263
264
3/6
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 19 times.
✗ Branch 8 not taken.
76 CmdLine::declare_arg("nb_clip", 10, "number of clipping planes");
265
1/2
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
19 CmdLine::declare_arg(
266
2/4
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
95 "nb_clip_times", 1, "number of times clipping is done"
267 );
268
1/2
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
19 CmdLine::declare_arg(
269
2/4
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
95 "shape", "sphere", "one of sphere,cone,file"
270 );
271
1/2
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
19 CmdLine::declare_arg(
272
2/4
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
95 "save_points", false, "save generated points into points.xyz"
273 );
274
1/2
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
19 CmdLine::declare_arg(
275
2/4
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
95 "integer", false, "integer coordinates only"
276 );
277
1/2
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
19 CmdLine::declare_arg(
278
2/4
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
95 "lrs", false, "generate output for lrs (lrs.ine file)"
279 );
280
281
1/2
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
19 CmdLine::declare_arg(
282
1/2
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
38 "integer_coord_mul", 1e6,
283
1/2
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
57 "multiplicative factor before integer conversion"
284 );
285
286
1/2
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
19 CmdLine::declare_arg(
287
1/2
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
38 "integer_Ncoord_mul", 1e6,
288
1/2
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
57 "multiplicative factor before normal vector integer conversion"
289 );
290
291 19 if(
292
1/2
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
19 !CmdLine::parse(
293
2/4
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 19 times.
57 argc, argv, filenames, "<pointsfile> <outputfile>"
294 )
295 ) {
296 return 1;
297 }
298
299
1/2
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
19 Delaunay_var delaunay = Delaunay::create(3);
300
2/4
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
38 index_t nb_vertices = CmdLine::get_arg_uint("nb_clip");
301
2/4
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
38 index_t nb_times = CmdLine::get_arg_uint("nb_clip_times");
302
2/4
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
38 std::string shape = CmdLine::get_arg("shape");
303
3/6
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 19 times.
✗ Branch 8 not taken.
19 bool exact = (CmdLine::get_arg("algo:predicates") == "exact");
304
305
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 7 times.
19 if(exact) {
306
2/4
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
36 Logger::out("Predicates")
307
2/4
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
12 << "Using exact predicates" << std::endl;
308 }
309
310 19 vector<double> vertices;
311
2/4
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 19 times.
19 if(shape == "sphere") {
312 Logger::out("Program")
313 << "Using random sphere shape" << std::endl;
314 init_sphere(vertices, nb_vertices);
315
2/4
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 19 times.
19 } else if(shape == "cone") {
316 Logger::out("Program")
317 << "Using random cone shape" << std::endl;
318 init_cone(vertices, nb_vertices);
319
2/4
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 19 times.
✗ Branch 4 not taken.
19 } else if(shape == "file") {
320
2/4
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
38 Logger::out("Program")
321
2/4
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
19 << "Taking shape from file" << std::endl;
322
323
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 18 times.
19 if(filenames.size() == 0) {
324
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 Logger::err("Program")
325
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 << "Missing input shape file argument" << std::endl;
326 1 return 1;
327 }
328
329
1/2
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
18 points_filename = filenames[0];
330
1/2
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
36 filenames.erase(filenames.begin());
331
332
2/4
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
36 Logger::out("I/O")
333
2/4
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
18 << "Loading shape from file " << points_filename
334
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 << std::endl;
335
336
2/4
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
18 if(!load_points(vertices, points_filename)) {
337 Logger::err("I/O")
338 << "Could not load file: " << points_filename
339 << std::endl;
340 return 1;
341 }
342 18 nb_vertices = (vertices.size() / 3) - 1;
343 } else {
344 Logger::err("Program")
345 << shape << ": invalid shape" << std::endl;
346 return 1;
347 }
348
349
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
18 if(filenames.size() >= 1) {
350 output_filename = filenames[0];
351 }
352
353
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
18 if(filenames.size() > 1) {
354 Logger::warn("Program")
355 << "Extraneous files ignored" << std::endl;
356 }
357
358
3/6
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 18 times.
✗ Branch 8 not taken.
18 delaunay->set_vertices(nb_vertices + 1, &(vertices[0]));
359
360
3/6
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 18 times.
36 if(CmdLine::get_arg_bool("save_points")) {
361 if(!save_points(delaunay, "points.xyz")) {
362 return 1;
363 }
364 }
365
366
3/6
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 18 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 18 times.
✗ Branch 9 not taken.
36 CmdLine::set_arg("nb_clip", delaunay->nb_vertices() - 1);
367
368
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 Mesh M;
369
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 initialize_mesh_with_box(M);
370
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 ConvexCell C(3);
371
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 C.initialize_from_surface_mesh(&M, true);
372
373
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(index_t k = 0; k < nb_times; ++k) {
374
2/2
✓ Branch 0 taken 26652 times.
✓ Branch 1 taken 72 times.
26724 for(index_t i = 1; i < nb_vertices; ++i) {
375
1/2
✓ Branch 2 taken 26652 times.
✗ Branch 3 not taken.
26652 C.clip_by_plane<3>(&M, delaunay, 0, i, exact, exact);
376 }
377 }
378
379
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 Mesh C_mesh;
380
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 C.convert_to_mesh(&C_mesh);
381
382
383
2/4
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
36 double coord_scale = CmdLine::get_arg_double("integer_coord_mul");
384
2/4
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
36 double N_scale = CmdLine::get_arg_double("integer_Ncoord_mul");
385
386
2/4
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
18 bool integer_mode = CmdLine::get_arg_bool("integer");
387
388
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(integer_mode) {
389 double xyz_min[3];
390 double xyz_max[3];
391 get_bbox(C_mesh, xyz_min, xyz_max);
392 double R = xyz_max[0]-xyz_min[0];
393 R = std::max(R, xyz_max[1]-xyz_min[1]);
394 R = std::max(R, xyz_max[2]-xyz_min[2]);
395 FOR(v,C_mesh.vertices.nb()) {
396 double* p = C_mesh.vertices.point_ptr(v);
397 FOR(c,3) {
398 p[c] = (p[c] - xyz_min[c]) * coord_scale / R;
399 }
400 }
401 } else {
402 18 coord_scale = 1.0;
403 18 N_scale = 1.0;
404 }
405
406
3/6
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 18 times.
36 if(CmdLine::get_arg_bool("lrs")) {
407 Logger::out("ConvexCell") << "Generating lrs.ine" << std::endl;
408 std::ofstream out("lrs.ine");
409 out << "cell" << std::endl;
410 out << "*convex cell output converted to LRS format" << std::endl;
411 out << "H-representation" << std::endl;
412 out << "begin" << std::endl;
413 out << C_mesh.facets.nb() << " " << 4 << " "
414 << "rational" << std::endl;
415 FOR(f,C_mesh.facets.nb()) {
416 index_t n = C_mesh.facets.nb_vertices(f);
417 vec3 N(0.0, 0.0, 0.0);
418 vec3 g(0.0, 0.0, 0.0);
419 FOR(lv,n) {
420 index_t v1 = C_mesh.facets.vertex(f,lv);
421 index_t v2 = C_mesh.facets.vertex(f,(lv+1)%n);
422 index_t v3 = C_mesh.facets.vertex(f,(lv+2)%n);
423 vec3 p1(C_mesh.vertices.point_ptr(v1));
424 vec3 p2(C_mesh.vertices.point_ptr(v2));
425 vec3 p3(C_mesh.vertices.point_ptr(v3));
426 N += cross(p1-p2,p3-p2);
427 g += p1;
428 }
429 g = (1.0 / double(n)) * g;
430 N = normalize(N);
431 N = N_scale * N;
432 double d = -dot(N,g);
433 if(integer_mode) {
434 out << long(d) << " "
435 << long(N.x) << " " << long(N.y) << " " << long(N.z)
436 << std::endl;
437 } else {
438 out << d << " "
439 << N.x << " " << N.y << " " << N.z
440 << std::endl;
441 }
442 }
443 out << "end" << std::endl;
444 }
445
446
2/4
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
36 Logger::out("I/O")
447
2/4
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
18 << "Saving mesh to file " << output_filename
448
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 << std::endl;
449
450
3/6
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 18 times.
18 if(!mesh_save(C_mesh, output_filename)) {
451 return 1;
452 }
453
454
2/4
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
18 if(!meshes_have_same_topology(M, C_mesh, true)) {
455 return 1;
456 }
457
17/20
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 18 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 18 times.
✓ Branch 11 taken 1 times.
✓ Branch 13 taken 18 times.
✓ Branch 14 taken 1 times.
✓ Branch 16 taken 18 times.
✓ Branch 17 taken 1 times.
✓ Branch 19 taken 18 times.
✓ Branch 20 taken 1 times.
✓ Branch 22 taken 18 times.
✓ Branch 23 taken 1 times.
✓ Branch 25 taken 18 times.
✓ Branch 26 taken 1 times.
✓ Branch 28 taken 18 times.
✓ Branch 29 taken 1 times.
25 }
458 catch(const std::exception& e) {
459 std::cerr << "Received an exception: " << e.what() << std::endl;
460 return 1;
461 }
462
463 18 return result;
464 }
465