Geogram Version 1.8.5
A programming library of geometric algorithms
Loading...
Searching...
No Matches
periodic.h
Go to the documentation of this file.
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_DELAUNAY_PERIODIC
41#define GEOGRAM_DELAUNAY_PERIODIC
42
46
52namespace GEO {
53
57 class GEOGRAM_API Periodic {
58 public:
59
65 geo_debug_assert(pv < nb_vertices_non_periodic_ * 27);
66 return pv / nb_vertices_non_periodic_;
67 }
68
74 geo_debug_assert(pv < nb_vertices_non_periodic_ * 27);
75 return pv % nb_vertices_non_periodic_;
76 }
77
83 geo_debug_assert(pv < signed_index_t(nb_vertices_non_periodic_ * 27));
84 geo_debug_assert(pv != -1);
85 return pv % signed_index_t(nb_vertices_non_periodic_);
86 }
87
94 geo_debug_assert(real < nb_vertices_non_periodic_);
95 geo_debug_assert(instance < 27);
96 return real + nb_vertices_non_periodic_*instance;
97 }
98
104 static index_t T_to_instance(int Tx, int Ty, int Tz) {
105 geo_debug_assert(Tx >= -1 && Tx <= 1);
106 geo_debug_assert(Ty >= -1 && Ty <= 1);
107 geo_debug_assert(Tz >= -1 && Tz <= 1);
108 int i = (Tz+1) + 3*(Ty+1) + 9*(Tx+1);
109 geo_debug_assert(i >= 0 && i < 27);
110 return index_t(reorder_instances[i]);
111 }
112
118 void periodic_vertex_get_T(index_t pv, int& Tx, int& Ty, int& Tz) const {
119 geo_debug_assert(pv < nb_vertices_non_periodic_ * 27);
120 index_t instance = periodic_vertex_instance(pv);
121 Tx = translation[instance][0];
122 Ty = translation[instance][1];
123 Tz = translation[instance][2];
124 }
125
131 void periodic_vertex_set_T(index_t& pv, int Tx, int Ty, int Tz) const {
132 geo_debug_assert(pv < nb_vertices_non_periodic_ * 27);
133 geo_debug_assert(Tx >= -1 && Tx <= 1);
134 geo_debug_assert(Ty >= -1 && Ty <= 1);
135 geo_debug_assert(Tz >= -1 && Tz <= 1);
136 pv = make_periodic_vertex(
137 periodic_vertex_real(pv), T_to_instance(Tx, Ty, Tz)
138 );
139 }
140
141 std::string periodic_vertex_to_string(index_t v) const {
142 return
143 String::to_string(periodic_vertex_real(v)) + ":" +
144 String::to_string(periodic_vertex_instance(v)) ;
145 }
146
147 std::string binary_to_string(Numeric::uint32 m) const {
148 std::string s(32,' ');
149 for(index_t i=0; i<32; ++i) {
150 s[i] = ((m & (1u << (31u-i))) != 0) ? '1' : '0';
151 }
152 return s;
153 }
154
160 static int translation[27][3];
161
169 static int reorder_instances[27];
170
175 static bool instance_is_positive[27];
176
181 };
182
183}
184
185#endif
186
Assertion checking mechanism.
#define geo_debug_assert(x)
Verifies that a condition is met.
Definition assert.h:195
Common include file, providing basic definitions. Should be included before anything else by all head...
Utilities for managing 3D periodic space.
Definition periodic.h:57
void periodic_vertex_get_T(index_t pv, int &Tx, int &Ty, int &Tz) const
Gets the translation from a periodic vertex.
Definition periodic.h:118
index_t periodic_vertex_instance(index_t pv) const
Gets the instance from a periodic vertex.
Definition periodic.h:64
index_t make_periodic_vertex(index_t real, index_t instance) const
Makes a periodic vertex from a real vertex and instance.
Definition periodic.h:93
static index_t T_to_instance(int Tx, int Ty, int Tz)
Gets the instance from a translation.
Definition periodic.h:104
index_t periodic_vertex_real(index_t pv) const
Gets the real vertex from a periodic vertex.
Definition periodic.h:73
index_t nb_vertices_non_periodic_
Number of real vertices.
Definition periodic.h:180
signed_index_t periodic_vertex_real(signed_index_t pv) const
Gets the real vertex from a periodic vertex.
Definition periodic.h:82
void periodic_vertex_set_T(index_t &pv, int Tx, int Ty, int Tz) const
Sets the translation in a periodic vertex.
Definition periodic.h:131
Global Vorpaline namespace.
Definition algorithm.h:64
geo_signed_index_t signed_index_t
The type for storing and manipulating indices differences.
Definition numeric.h:301
geo_index_t index_t
The type for storing and manipulating indices.
Definition numeric.h:287
Functions for string manipulation.