Geogram Version 1.10.2
A programming library of geometric algorithms
Loading...
Searching...
No Matches
periodic_delaunay_3d.h
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 PERIODIC_DELAUNAY_TRIANGULATION_3D
41#define PERIODIC_DELAUNAY_TRIANGULATION_3D
42
49#include <stack>
50
52
53namespace GEO {
54
55 class PeriodicDelaunay3dThread;
56
57
67 class GEOGRAM_API PeriodicDelaunay3d : public Delaunay, public Periodic {
68 public:
69
78 std::stack<index_t> S;
79 vector<index_t> incident_tets_set;
80
85 incident_tets_set.resize(0);
86 }
87
93 incident_tets_set.push_back(t);
94 }
95
103 bool has_incident_tet(index_t t) const {
104 for(index_t i=0; i<incident_tets_set.size(); ++i) {
105 if(incident_tets_set[i] == t) {
106 return true;
107 }
108 }
109 return false;
110 }
111
112 vector<index_t>::const_iterator begin() const {
113 return incident_tets_set.begin();
114 }
115
116 vector<index_t>::const_iterator end() const {
117 return incident_tets_set.end();
118 }
119 };
120
126 PeriodicDelaunay3d(bool periodic, double period=1.0);
127
133 PeriodicDelaunay3d(const vec3& period, bool periodic = true);
134
140 index_t nb_vertices, const double* vertices
141 ) override;
142
151 void set_weights(const double* weights);
152
156 void compute();
157
164 bool periodic() const {
165 return periodic_;
166 }
167
176 convex_cell_exact_predicates_ = x;
177 }
178
187 vec3 vertex(index_t v) const {
188 if(!periodic_) {
190 return vec3(vertices_ + 3*v);
191 }
194 vec3 result(vertices_ + 3*v);
195 result.x += double(translation[instance][0]) * period_.x;
196 result.y += double(translation[instance][1]) * period_.y;
197 result.z += double(translation[instance][2]) * period_.z;
198 return result;
199 }
200
207 double weight(index_t v) const {
208 if(weights_ == nullptr) {
209 return 0.0;
210 }
211 return periodic_ ? weights_[periodic_vertex_real(v)] : weights_[v] ;
212 }
213
217 index_t nearest_vertex(const double* p) const override;
218
222 void set_BRIO_levels(const vector<index_t>& levels) override;
223
233
245 GEO::index_t i,
246 ConvexCell& C,
248 ) const;
249
265
272 void abort_if_empty_cell(bool x) {
273 abort_on_empty_cell_ = x;
274 }
275
284 bool has_empty_cells() const {
285 return has_empty_cells_;
286 }
287
296 void save_cells(const std::string& basename, bool clipped);
297
298 protected:
299
316 GEO::index_t i,
317 const GEO::vec3& Pi,
318 double wi,
319 double Pi_len2,
320 GEO::index_t t,
321 ConvexCell& C,
323 ) const;
324
325
332 index_t compress(bool shrink=true);
333
340 void update_v_to_cell() override;
341
345 void update_cicl() override;
346
352
353
362
375
384
392 void insert_vertices(const char* phase, index_t b, index_t e);
393
405 const char* phase, const vector<index_t>& levels
406 );
407
412
418 PeriodicDelaunay3dThread* thread(index_t t) {
419 geo_debug_assert(t < threads_.size());
420 return reinterpret_cast<PeriodicDelaunay3dThread*>(
421 threads_[t].get()
422 );
423 }
424
430 return index_t(threads_.size());
431 }
432
433 void check_max_t();
434
435 private:
436 friend class PeriodicDelaunay3dThread;
437
438 bool periodic_;
439 vec3 period_;
440
441 const double* weights_;
442 vector<index_t> cell_to_v_store_;
443 vector<index_t> cell_to_cell_store_;
444 vector<index_t> cell_next_;
445
446 CellStatusArray cell_status_;
447
448 ThreadGroup threads_;
449 vector<index_t> reorder_;
450 vector<index_t> levels_;
451
455 bool debug_mode_;
456
460 bool verbose_debug_mode_;
461
465 bool benchmark_mode_;
466
470 bool detailed_benchmark_mode_;
471
476 vector<Numeric::uint32> vertex_instances_;
477
478 bool update_periodic_v_to_cell_;
479 vector<index_t> periodic_v_to_cell_rowptr_;
480 vector<index_t> periodic_v_to_cell_data_;
481
486 bool abort_on_empty_cell_;
487
491 bool has_empty_cells_;
492
497 index_t nb_reallocations_;
498
502 bool convex_cell_exact_predicates_;
503
504 struct Stats {
505
506 Stats();
507
508 void reset();
509
510 std::string to_string() {
511 return raw_ ? to_string_raw() : to_string_pretty();
512 }
513
514 std::string to_string_raw() const;
515 std::string to_string_pretty() const;
516
521 bool raw_;
522
523 double total_t_;
524
525 double phase_0_t_;
526
527 double phase_I_t_;
528 double phase_I_classify_t_;
529 index_t phase_I_nb_inside_;
530 index_t phase_I_nb_cross_;
531 index_t phase_I_nb_outside_;
532 double phase_I_insert_t_;
533 index_t phase_I_insert_nb_;
534
535 double phase_II_t_;
536 double phase_II_classify_t_;
537 double phase_II_insert_t_;
538 index_t phase_II_insert_nb_;
539 } stats_;
540
541 friend class LaguerreDiagramOmegaSimple3d;
542 };
543
544
545}
546
547#endif
#define geo_debug_assert(x)
Verifies that a condition is met.
Definition assert.h:202
An array of cell status codes associates to each tetrahedron in a Delaunay tetrahedralization.
index_t nb_vertices() const
Gets the number of vertices.
Definition delaunay.h:238
Delaunay(coord_index_t dimension)
Creates a new Delaunay triangulation.
PeriodicDelaunay3d(const vec3 &period, bool periodic=true)
Constructs a new PeriodicDelaunay3d.
void abort_if_empty_cell(bool x)
Sets whether computation should be stopped when an empty cell is encountered.
PeriodicDelaunay3d(bool periodic, double period=1.0)
Constructs a new PeriodicDelaunay3d.
void check_volume()
Checks the volume of Laguerre cells.
void compute()
Computes the Delaunay triangulation.
void use_exact_predicates_for_convex_cell(bool x)
Use exact predicates in convex cell computations.
void handle_periodic_boundaries()
Duplicates the points with Voronoi cells that cross the boundary.
void save_cells(const std::string &basename, bool clipped)
Saves the cells in an Alias-Wavefront file.
void set_BRIO_levels(const vector< index_t > &levels) override
Specifies the bounds of each level to be used when hierarchic ordering is specified from outside.
index_t compress(bool shrink=true)
Removes unused tetrahedra.
void insert_vertices(const char *phase, index_t b, index_t e)
Inserts vertices from reorder_[b] to reorder_[e-1] using multithreaded Delaunay. Called by insert_ver...
void handle_periodic_boundaries_phase_II()
Phase II of periodic boundaries handling.
double weight(index_t v) const
Gets a weight by index.
bool Laguerre_vertex_is_in_conflict_with_plane(index_t t, vec4 P) const
Tests the position of a Laguerre vertex w.r.t. a plane.
void update_v_to_cell() override
Stores for each vertex v a cell incident to v.
bool periodic() const
Tests whether this PeriodicDelaunay3d is in periodic mode.
void update_cicl() override
Updates the circular incident cell lists.
void get_incident_tets(index_t v, IncidentTetrahedra &W) const
computes the set of tetrahedra that are incident to a vertex.
void copy_Laguerre_cell_from_Delaunay(GEO::index_t i, ConvexCell &C, IncidentTetrahedra &W) const
Copies a Laguerre cell from the triangulation.
void insert_vertices_with_BRIO(const char *phase, const vector< index_t > &levels)
Inserts vertices as indicated by a reordering vector and a vector of BRIO levels, as obtained using c...
index_t nb_threads() const
Gets the number of threads.
void handle_periodic_boundaries_phase_I()
Phase I of periodic boundaries handling.
index_t nearest_vertex(const double *p) const override
Computes the nearest vertex from a query point.
void copy_Laguerre_cell_from_Delaunay(GEO::index_t i, ConvexCell &C) const
Copies a Laguerre cell from the triangulation.
vec3 vertex(index_t v) const
Gets a vertex by index.
bool has_empty_cells() const
Tests whether the Laguerre diagram has empty cells.
GEO::index_t copy_Laguerre_cell_facet_from_Delaunay(GEO::index_t i, const GEO::vec3 &Pi, double wi, double Pi_len2, GEO::index_t t, ConvexCell &C, IncidentTetrahedra &W) const
Copies a Laguerre cell facet from the triangulation.
void set_weights(const double *weights)
Sets the weights.
void set_vertices(index_t nb_vertices, const double *vertices) override
Sets the vertices of this Delaunay, and recomputes the cells.
PeriodicDelaunay3dThread * thread(index_t t)
Gets a thread by index.
Utilities for managing 3D periodic space.
Definition periodic.h:57
index_t periodic_vertex_real(index_t pv) const
Gets the real vertex from a periodic vertex.
Definition periodic.h:85
index_t nb_vertices_non_periodic_
Number of real vertices.
Definition periodic.h:182
static int translation[27][3]
Gives for each instance the integer translation coordinates in {-1,0,1}.
Definition periodic.h:162
Vector with aligned memory allocation.
Definition memory.h:703
Computes the intersection between a set of halfplanes using Bowyer-Watson algorithm.
Class to compute the intersection of a set of half-spaces in 3D.
Abstract interface for Delaunay.
Synchronization primitives for parallel Delaunay.
Common include file, providing basic definitions. Should be included before anything else by all head...
Geometric functions in 2d and 3d.
Global Vorpaline namespace.
Definition basic.h:55
std::vector< Thread_var > ThreadGroup
Collection of Threads.
Definition process.h:155
vecng< 3, Numeric::float64 > vec3
Represents points and vectors in 3d.
Definition geometry.h:65
geo_index_t index_t
The type for storing and manipulating indices.
Definition numeric.h:341
vecng< 4, Numeric::float64 > vec4
Represents points and vectors in 4d.
Definition geometry.h:71
Manipulation of indices for 3D periodic space.
Function and classes for process manipulation.
Gathers some structures used by some algorithms, makes multithreading more efficient by avoiding dyna...
void add_incident_tet(index_t t)
Inserts a tet into the set of incident tets.
void clear_incident_tets()
Clears the set of incident tets.
bool has_incident_tet(index_t t) const
Tests whether a tet belongs to the set of incident tets.