Geogram  Version 1.9.1-rc
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 
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 
84  pv < signed_index_t(nb_vertices_non_periodic_ * 27)
85  );
86  geo_debug_assert(pv != -1);
87  return pv % signed_index_t(nb_vertices_non_periodic_);
88  }
89 
95  index_t make_periodic_vertex(index_t real, index_t instance) const {
96  geo_debug_assert(real < nb_vertices_non_periodic_);
97  geo_debug_assert(instance < 27);
98  return real + nb_vertices_non_periodic_*instance;
99  }
100 
106  static index_t T_to_instance(int Tx, int Ty, int Tz) {
107  geo_debug_assert(Tx >= -1 && Tx <= 1);
108  geo_debug_assert(Ty >= -1 && Ty <= 1);
109  geo_debug_assert(Tz >= -1 && Tz <= 1);
110  int i = (Tz+1) + 3*(Ty+1) + 9*(Tx+1);
111  geo_debug_assert(i >= 0 && i < 27);
112  return index_t(reorder_instances[i]);
113  }
114 
120  void periodic_vertex_get_T(index_t pv, int& Tx, int& Ty, int& Tz) const {
121  geo_debug_assert(pv < nb_vertices_non_periodic_ * 27);
122  index_t instance = periodic_vertex_instance(pv);
123  Tx = translation[instance][0];
124  Ty = translation[instance][1];
125  Tz = translation[instance][2];
126  }
127 
133  void periodic_vertex_set_T(index_t& pv, int Tx, int Ty, int Tz) const {
134  geo_debug_assert(pv < nb_vertices_non_periodic_ * 27);
135  geo_debug_assert(Tx >= -1 && Tx <= 1);
136  geo_debug_assert(Ty >= -1 && Ty <= 1);
137  geo_debug_assert(Tz >= -1 && Tz <= 1);
138  pv = make_periodic_vertex(
139  periodic_vertex_real(pv), T_to_instance(Tx, Ty, Tz)
140  );
141  }
142 
143  std::string periodic_vertex_to_string(index_t v) const {
144  return
145  String::to_string(periodic_vertex_real(v)) + ":" +
146  String::to_string(periodic_vertex_instance(v)) ;
147  }
148 
149  std::string binary_to_string(Numeric::uint32 m) const {
150  std::string s(32,' ');
151  for(index_t i=0; i<32; ++i) {
152  s[i] = ((m & (1u << (31u-i))) != 0) ? '1' : '0';
153  }
154  return s;
155  }
156 
162  static int translation[27][3];
163 
171  static int reorder_instances[27];
172 
177  static bool instance_is_positive[27];
178 
183  };
184 
185 }
186 
187 #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:120
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:95
static index_t T_to_instance(int Tx, int Ty, int Tz)
Gets the instance from a translation.
Definition: periodic.h:106
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:182
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:133
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.