EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_DCEL_Reconcile.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
16#ifndef EBGEOMETRY_DCEL_RECONCILE_HPP
17#define EBGEOMETRY_DCEL_RECONCILE_HPP
18
19// Std includes
20#include <cstddef>
21#include <cstdint>
22
23// Our includes
27#include "EBGeometry_Macros.hpp"
29#include "EBGeometry_Pool.hpp"
30
31namespace EBGeometry {
32
33namespace DCEL {
34
39namespace ReconcileDetail {
40
45struct Corner
46{
48 uint32_t m_face;
49
51 uint32_t m_first;
52
54 uint32_t m_second;
55};
56
57} // namespace ReconcileDetail
58
81{
82public:
92 template <class T>
94 ReconcileSchedule(Pool& a_pool, const MeshT<T>& a_mesh);
95
96private:
100 template <class T>
101 friend void
102 reconcile(Pool& a_pool, const MeshT<T>& a_mesh, const ReconcileSchedule& a_schedule);
103
107 PODVector<uint32_t> m_cornerBegin;
108
113
118 PODVector<uint32_t> m_status;
119
124 uint64_t m_rootId = 0;
125
130 uint64_t m_vertexOffset = 0;
131
133 uint64_t m_edgeOffset = 0;
134
136 uint64_t m_faceOffset = 0;
137
141 uint32_t m_numVertices = 0;
142
144 uint32_t m_numEdges = 0;
145
147 uint32_t m_numFaces = 0;
148};
149
180template <class T>
182inline void
183reconcile(Pool& a_pool, const MeshT<T>& a_mesh, const ReconcileSchedule& a_schedule);
184
185namespace ReconcileDetail {
186
191template <class T>
192struct Faces
193{
199 mutable MeshT<T> m_mesh;
200
206 inline void
207 operator()(const std::size_t a_i) const
208 {
209 m_mesh.getFace(static_cast<uint32_t>(a_i)).reconcile(m_mesh);
210 }
211};
212
217template <class T>
218struct Edges
219{
223 mutable MeshT<T> m_mesh;
224
230 inline void
231 operator()(const std::size_t a_i) const noexcept
232 {
233 m_mesh.getEdge(static_cast<uint32_t>(a_i)).reconcile(m_mesh);
234 }
235};
236
242template <class T>
243struct Vertices
244{
248 mutable MeshT<T> m_mesh;
249
253 void* m_base;
254
258 PODVector<uint32_t> m_cornerBegin;
259
263 PODVector<Corner> m_corners;
264
268 PODVector<uint32_t> m_status;
269
275 inline void
276 operator()(const std::size_t a_i) const noexcept
277 {
278 const auto v = static_cast<uint32_t>(a_i);
279 const uint32_t begin = m_cornerBegin.at(m_base, v);
280 const uint32_t end = m_cornerBegin.at(m_base, v + 1);
281
282 VertexT<T>& vertex = m_mesh.getVertex(v);
283 const Vec3T<T> x0 = vertex.getPosition();
284
285 // A vertex no face uses gets a zero normal, as in MeshT::reconcile().
286 Vec3T<T> normal = Vec3T<T>::zeros();
287
288 for (uint32_t c = begin; c < end; c++) {
289 const Corner& corner = m_corners.at(m_base, c);
290 const FaceT<T>& face = m_mesh.getFace(corner.m_face);
291
292 // A zero-area face contributes nothing, as in VertexT::computeVertexNormalAngleWeighted().
293 if (face.getNormal().length2() == T(0)) {
294 continue;
295 }
296
297 const Vec3T<T>& x1 = m_mesh.getVertex(corner.m_first).getPosition();
298 const Vec3T<T>& x2 = m_mesh.getVertex(corner.m_second).getPosition();
299
300 // Every thread that finds a coincidence writes the same value, so the order does not matter.
301 if (x0 == x1 || x0 == x2 || x1 == x2) {
302 m_status.at(m_base, 0) = 1;
303
304 continue;
305 }
306
307 normal += VertexDetail::angleWeightedTerm(x0, x1, x2, face.getNormal());
308 }
309
310 vertex.setNormal(normal);
311
312 if (end > begin) {
313 vertex.normalizeNormalVector();
314 }
315 }
316};
317
318} // namespace ReconcileDetail
319
320} // namespace DCEL
321
322} // namespace EBGeometry
323
324#include "EBGeometry_DCEL_ReconcileImplem.hpp"
325
326#endif
Declaration of a mesh class which stores a DCEL mesh (with signed distance functions)
Declaration of a vertex class for use in DCEL descriptions of polygon tessellations.
GPU::parallelFor() and GPU::transform(), which run a functor over many indices or inputs: in a kernel...
#define EBGEOMETRY_HOST_DEVICE
Mark a function as callable from both host and device code (no-op on host compilers).
Definition EBGeometry_GPU.hpp:80
#define EBGEOMETRY_HOST
Mark a function as callable from host code only (no-op on host compilers).
Definition EBGeometry_GPU.hpp:83
Utility macros for EBGeometry.
Placement-independent POD array views for the GPU memory foundation.
Growable bump arena for the GPU memory foundation.
void reconcile(const Mesh &a_mesh) noexcept
Reconcile internal logic.
void reconcile(const Mesh &a_mesh)
Reconcile face. This will compute the normal vector, area, centroid, and the 2D embedding of the poly...
DCEL mesh class - stores a doubly-connected edge mesh.
Definition EBGeometry_DCEL_Mesh.hpp:102
Edge & getEdge(uint32_t a_index) noexcept
Get modifiable half-edge by index.
Face & getFace(uint32_t a_index) noexcept
Get modifiable face by index.
Which faces touch each vertex of a mesh, checked and stored once, for DCEL::reconcile().
Definition EBGeometry_DCEL_Reconcile.hpp:81
friend void reconcile(Pool &a_pool, const MeshT< T > &a_mesh, const ReconcileSchedule &a_schedule)
DCEL::reconcile() reads the arrays.
ReconcileSchedule(Pool &a_pool, const MeshT< T > &a_mesh)
Check the topology of a_mesh and store which faces touch each vertex.
Growable bump arena over a MemoryResource.
Definition EBGeometry_Pool.hpp:188
static constexpr Vec3T< T > zeros() noexcept
Return a vector with x = y = z = 0.
Vec3T< T > angleWeightedTerm(const Vec3T< T > &a_x0, const Vec3T< T > &a_x1, const Vec3T< T > &a_x2, const Vec3T< T > &a_normal) noexcept
One face's term in a vertex's angle-weighted pseudonormal: the face's normal weighted by the angle th...
Definition EBGeometry_DCEL_Vertex.hpp:366
void reconcile(Pool &a_pool, const MeshT< T > &a_mesh, const ReconcileSchedule &a_schedule)
Reconcile the copy of a_mesh that lives in a_pool, after its vertices have moved: every face's normal...
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
Vec3T< T > normal(const F &a_function, const Vec3T< T > &a_point, const T &a_delta) noexcept
Outward unit normal of a function's level set, by central finite differences.
One corner of a face, as seen from the vertex at it: the face, and the vertices before and after the ...
Definition EBGeometry_DCEL_Reconcile.hpp:46
uint32_t m_second
The second neighbor found.
Definition EBGeometry_DCEL_Reconcile.hpp:54
uint32_t m_first
The first neighbor found walking the face's loop from its half-edge.
Definition EBGeometry_DCEL_Reconcile.hpp:51
uint32_t m_face
The face.
Definition EBGeometry_DCEL_Reconcile.hpp:48
Placement-independent descriptor of a POD array inside a Pool.
Definition EBGeometry_PODVector.hpp:119