GCC Code Coverage Report


Directory: ./
File: lib/geogram/delaunay/periodic.h
Date: 2026-09-07 02:28:19
Exec Total Coverage
Lines: 0 5 0.0%
Functions: 0 0 -%
Branches: 0 12 0.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 #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
47 /**
48 * \file geogram/delaunay/periodic.h
49 * \brief Manipulation of indices for 3D periodic space.
50 */
51
52 namespace GEO {
53
54 /**
55 * \brief Utilities for managing 3D periodic space.
56 */
57 class GEOGRAM_API Periodic {
58 public:
59
60 /**
61 * \brief Gets the number of non-periodic vertices
62 * \details in periodic mode, nb_vertices() returns
63 * the total number of vertices, real ones and
64 * periodic instances. This function gets the number
65 * of real vertices.
66 * \return the number of non-periodic vertices
67 */
68 index_t nb_vertices_non_periodic() const {
69 return nb_vertices_non_periodic_;
70 }
71
72 /**
73 * \brief Gets the instance from a periodic vertex.
74 * \return the instance in 0..26
75 */
76 index_t periodic_vertex_instance(index_t pv) const {
77 geo_debug_assert(pv < nb_vertices_non_periodic_ * 27);
78 return pv / nb_vertices_non_periodic_;
79 }
80
81 /**
82 * \brief Gets the real vertex from a periodic vertex.
83 * \return the real vertex, in 0..nb_vertices_non_periodic_-1
84 */
85 index_t periodic_vertex_real(index_t pv) const {
86 geo_debug_assert(pv < nb_vertices_non_periodic_ * 27);
87 return pv % nb_vertices_non_periodic_;
88 }
89
90 /**
91 * \brief Makes a periodic vertex from a real vertex and instance.
92 * \param[in] real the real vertex, in 0..nb_vertices_non_periodic_-1
93 * \param[in] instance the instance, in 0..26
94 */
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
101 /**
102 * \brief Gets the instance from a translation.
103 * \param[in] Tx , Ty , Tz the translation coordinates, in {-1, 0, 1}
104 * \return the instance, in 0..26
105 */
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
115 /**
116 * \brief Gets the translation from a periodic vertex.
117 * \param[in] pv the periodic vertex
118 * \param[out] Tx , Ty , Tz the translation coordinates, in {-1, 0, 1}
119 */
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
128 /**
129 * \brief Sets the translation in a periodic vertex.
130 * \param[in,out] pv the periodic vertex
131 * \param[in] Tx , Ty , Tz the translation coordinates, in {-1, 0, 1}
132 */
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
157 /**
158 * \brief Gives for each instance the integer translation coordinates
159 * in {-1,0,1}.
160 * \details The zero translation is the first one (instance 0).
161 */
162 static int translation[27][3];
163
164 /**
165 * \brief Used to back-map an integer translation to an instance.
166 * \details This maps (Tx+1) + 3*(Ty+1) + 9*(Tz+1) to the associated
167 * instance id. This indirection is required because we wanted
168 * instance 0 to correspond to the 0 translation
169 * (rather than (-1,-1,-1) that would require no indirection).
170 */
171 static int reorder_instances[27];
172
173 /**
174 * \brief Tests whether all the coordinates of the translation vector
175 * associated with an instance are 0 or 1.
176 */
177 static bool instance_is_positive[27];
178
179 /**
180 * \brief Number of real vertices.
181 */
182 index_t nb_vertices_non_periodic_;
183 };
184
185 }
186
187 #endif
188