Geogram  Version 1.9.1
A programming library of geometric algorithms
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 
43 #include <geogram/basic/common.h>
44 #include <geogram/basic/string.h>
45 #include <geogram/basic/assert.h>
46 
52 namespace GEO {
53 
57  class GEOGRAM_API Periodic {
58  public:
59 
69  return nb_vertices_non_periodic_;
70  }
71 
77  geo_debug_assert(pv < nb_vertices_non_periodic_ * 27);
78  return pv / nb_vertices_non_periodic_;
79  }
80 
86  geo_debug_assert(pv < nb_vertices_non_periodic_ * 27);
87  return pv % nb_vertices_non_periodic_;
88  }
89 
96  pv < signed_index_t(nb_vertices_non_periodic_ * 27)
97  );
98  geo_debug_assert(pv != -1);
99  return pv % signed_index_t(nb_vertices_non_periodic_);
100  }
101 
107  index_t make_periodic_vertex(index_t real, index_t instance) const {
108  geo_debug_assert(real < nb_vertices_non_periodic_);
109  geo_debug_assert(instance < 27);
110  return real + nb_vertices_non_periodic_*instance;
111  }
112 
118  static index_t T_to_instance(int Tx, int Ty, int Tz) {
119  geo_debug_assert(Tx >= -1 && Tx <= 1);
120  geo_debug_assert(Ty >= -1 && Ty <= 1);
121  geo_debug_assert(Tz >= -1 && Tz <= 1);
122  int i = (Tz+1) + 3*(Ty+1) + 9*(Tx+1);
123  geo_debug_assert(i >= 0 && i < 27);
124  return index_t(reorder_instances[i]);
125  }
126 
132  void periodic_vertex_get_T(index_t pv, int& Tx, int& Ty, int& Tz) const {
133  geo_debug_assert(pv < nb_vertices_non_periodic_ * 27);
134  index_t instance = periodic_vertex_instance(pv);
135  Tx = translation[instance][0];
136  Ty = translation[instance][1];
137  Tz = translation[instance][2];
138  }
139 
145  void periodic_vertex_set_T(index_t& pv, int Tx, int Ty, int Tz) const {
146  geo_debug_assert(pv < nb_vertices_non_periodic_ * 27);
147  geo_debug_assert(Tx >= -1 && Tx <= 1);
148  geo_debug_assert(Ty >= -1 && Ty <= 1);
149  geo_debug_assert(Tz >= -1 && Tz <= 1);
150  pv = make_periodic_vertex(
151  periodic_vertex_real(pv), T_to_instance(Tx, Ty, Tz)
152  );
153  }
154 
155  std::string periodic_vertex_to_string(index_t v) const {
156  return
157  String::to_string(periodic_vertex_real(v)) + ":" +
158  String::to_string(periodic_vertex_instance(v)) ;
159  }
160 
161  std::string binary_to_string(Numeric::uint32 m) const {
162  std::string s(32,' ');
163  for(index_t i=0; i<32; ++i) {
164  s[i] = ((m & (1u << (31u-i))) != 0) ? '1' : '0';
165  }
166  return s;
167  }
168 
174  static int translation[27][3];
175 
183  static int reorder_instances[27];
184 
189  static bool instance_is_positive[27];
190 
195  };
196 
197 }
198 
199 #endif
Assertion checking mechanism.
#define geo_debug_assert(x)
Verifies that a condition is met.
Definition: assert.h:196
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:132
index_t periodic_vertex_instance(index_t pv) const
Gets the instance from a periodic vertex.
Definition: periodic.h:76
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:107
static index_t T_to_instance(int Tx, int Ty, int Tz)
Gets the instance from a translation.
Definition: periodic.h:118
index_t nb_vertices_non_periodic() const
Gets the number of non-periodic vertices.
Definition: periodic.h:68
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:194
signed_index_t periodic_vertex_real(signed_index_t pv) const
Gets the real vertex from a periodic vertex.
Definition: periodic.h:94
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:145
Common include file, providing basic definitions. Should be included before anything else by all head...
uint32_t uint32
Definition: numeric.h:141
Global Vorpaline namespace.
Definition: basic.h:55
geo_signed_index_t signed_index_t
The type for storing and manipulating indices differences.
Definition: numeric.h:343
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
Functions for string manipulation.