EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_DCEL_Edge.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
12#ifndef EBGEOMETRY_DCEL_EDGE_HPP
13#define EBGEOMETRY_DCEL_EDGE_HPP
14
15// Std includes
16#include <cstdint>
17#include <type_traits>
18
19// Our includes
20#include "EBGeometry_DCEL.hpp"
22#include "EBGeometry_GPU.hpp"
23#include "EBGeometry_Vec.hpp"
24
25namespace EBGeometry {
26
27namespace DCEL {
28
58template <class T>
59class EdgeT
60{
61 static_assert(std::is_floating_point_v<T>, "EdgeT<T>: T must be a floating-point type");
62
63public:
67 using Vec3 = Vec3T<T>;
68
73
77 using Edge = EdgeT<T>;
78
82 using Face = FaceT<T>;
83
87 using Mesh = MeshT<T>;
88
93 EdgeT() noexcept = default;
94
104 EdgeT(const Edge& a_otherEdge) = default;
105
112 EdgeT(Edge&& a_otherEdge) = default;
113
120 EdgeT(const uint32_t a_vertexIndex) noexcept;
121
125 ~EdgeT() = default;
126
133 Edge&
134 operator=(const Edge& a_otherEdge) = default;
135
143 Edge&
144 operator=(Edge&& a_otherEdge) = default;
145
150 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
151 inline size_t
152 size() const noexcept;
153
163 inline void
164 define(const uint32_t a_vertexIndex, const uint32_t a_pairEdgeIndex, const uint32_t a_nextEdgeIndex) noexcept;
165
172 inline void
173 reconcile(const Mesh& a_mesh) noexcept;
174
179 inline void
180 flipNormal() noexcept;
181
187 inline void
188 setVertex(const uint32_t a_vertexIndex) noexcept;
189
196 inline void
197 setPairEdge(const uint32_t a_pairEdgeIndex) noexcept;
198
205 inline void
206 setNextEdge(const uint32_t a_nextEdgeIndex) noexcept;
207
214 inline void
215 setFace(const uint32_t a_faceIndex) noexcept;
216
222 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
223 inline uint32_t
224 getVertexIndex() const noexcept;
225
230 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
231 inline uint32_t
232 getPairEdgeIndex() const noexcept;
233
238 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
239 inline uint32_t
240 getNextEdgeIndex() const noexcept;
241
246 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
247 inline uint32_t
248 getFaceIndex() const noexcept;
249
255 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
256 inline Vertex&
257 getVertex(Mesh& a_mesh) noexcept;
258
264 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
265 inline const Vertex&
266 getVertex(const Mesh& a_mesh) const noexcept;
267
273 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
274 inline Vertex&
275 getOtherVertex(Mesh& a_mesh) noexcept;
276
282 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
283 inline const Vertex&
284 getOtherVertex(const Mesh& a_mesh) const noexcept;
285
291 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
292 inline Edge&
293 getPairEdge(Mesh& a_mesh) noexcept;
294
300 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
301 inline const Edge&
302 getPairEdge(const Mesh& a_mesh) const noexcept;
303
309 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
310 inline Edge&
311 getNextEdge(Mesh& a_mesh) noexcept;
312
318 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
319 inline const Edge&
320 getNextEdge(const Mesh& a_mesh) const noexcept;
321
330 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
331 inline Vec3T<T>
332 computeNormal(const Mesh& a_mesh) const noexcept;
333
338 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
339 inline Vec3T<T>&
340 getNormal() noexcept;
341
346 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
347 inline const Vec3T<T>&
348 getNormal() const noexcept;
349
355 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
356 inline Face&
357 getFace(Mesh& a_mesh) noexcept;
358
364 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
365 inline const Face&
366 getFace(const Mesh& a_mesh) const noexcept;
367
378 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
379 inline T
380 signedDistance(const Vec3& a_x0, const Mesh& a_mesh) const noexcept;
381
391 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
392 inline T
393 unsignedDistance2(const Vec3& a_x0, const Mesh& a_mesh) const noexcept;
394
395protected:
399 Vec3 m_normal = Vec3::zeros();
400
405 uint32_t m_vertex = UINT32_MAX;
406
410 uint32_t m_pairEdge = UINT32_MAX;
411
415 uint32_t m_nextEdge = UINT32_MAX;
416
421 uint32_t m_face = UINT32_MAX;
422
432 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
433 inline T
434 projectPointToEdge(const Vec3& a_x0, const Mesh& a_mesh) const noexcept;
435
442 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
443 inline Vec3T<T>
444 getX2X1(const Mesh& a_mesh) const noexcept;
445};
446
447static_assert(std::is_trivially_copyable_v<EdgeT<float>>, "EdgeT<float> must be trivially copyable");
448static_assert(std::is_trivially_copyable_v<EdgeT<double>>, "EdgeT<double> must be trivially copyable");
449
450} // namespace DCEL
451
452} // namespace EBGeometry
453
454#include "EBGeometry_DCEL_EdgeImplem.hpp"
455
456#endif
Namespace documentation.
Declaration of a polygon face class for use in DCEL descriptions of polygon tessellations.
GPU portability layer: host/device decoration macros and backend detection.
#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
Declaration of 2D and 3D point/vector classes with templated precision, and free functions on them.
Half-edge class for navigating a DCEL mesh.
Definition EBGeometry_DCEL_Edge.hpp:60
uint32_t m_face
Index of the enclosing polygon face, into the owning mesh's face array, or UINT32_MAX if unset.
Definition EBGeometry_DCEL_Edge.hpp:421
Edge & getPairEdge(Mesh &a_mesh) noexcept
Get the pair edge.
Vec3T< T > getX2X1(const Mesh &a_mesh) const noexcept
Get the vector pointing along this edge (from start to end vertex).
Vertex & getVertex(Mesh &a_mesh) noexcept
Get the starting vertex.
void setVertex(const uint32_t a_vertexIndex) noexcept
Set the index of the starting vertex.
Vec3T< T > & getNormal() noexcept
Get modifiable normal vector.
uint32_t getFaceIndex() const noexcept
Get the index of this half-edge's face.
Vec3T< T > computeNormal(const Mesh &a_mesh) const noexcept
Compute the normal vector as the average of the face normals on both sides of this edge.
uint32_t getVertexIndex() const noexcept
Get the index of the starting vertex.
uint32_t m_nextEdge
Index of the next edge. See m_vertex for the indexing convention.
Definition EBGeometry_DCEL_Edge.hpp:415
uint32_t m_pairEdge
Index of the pair edge. See m_vertex for the indexing convention.
Definition EBGeometry_DCEL_Edge.hpp:410
Vertex & getOtherVertex(Mesh &a_mesh) noexcept
Get the end vertex.
Edge & getNextEdge(Mesh &a_mesh) noexcept
Get the next edge.
T projectPointToEdge(const Vec3 &a_x0, const Mesh &a_mesh) const noexcept
Returns the parametric projection of a_x0 onto this edge.
uint32_t getPairEdgeIndex() const noexcept
Get the index of the pair edge.
void flipNormal() noexcept
Flip surface normal.
Vec3 m_normal
Normal vector.
Definition EBGeometry_DCEL_Edge.hpp:399
uint32_t m_vertex
Index of the starting vertex.
Definition EBGeometry_DCEL_Edge.hpp:405
uint32_t getNextEdgeIndex() const noexcept
Get the index of the next edge.
void reconcile(const Mesh &a_mesh) noexcept
Reconcile internal logic.
void setNextEdge(const uint32_t a_nextEdgeIndex) noexcept
Set the index of the next edge.
Face & getFace(Mesh &a_mesh) noexcept
Get this half-edge's face.
T unsignedDistance2(const Vec3 &a_x0, const Mesh &a_mesh) const noexcept
Get the squared unsigned distance from a_x0 to this half-edge.
T signedDistance(const Vec3 &a_x0, const Mesh &a_mesh) const noexcept
Get the signed distance from a_x0 to this half-edge.
EdgeT() noexcept=default
Default constructor. Sets all topology indices to the unset sentinel and vectors to zero vectors.
void define(const uint32_t a_vertexIndex, const uint32_t a_pairEdgeIndex, const uint32_t a_nextEdgeIndex) noexcept
Define function. Sets the starting vertex, pair/next edge indices.
void setFace(const uint32_t a_faceIndex) noexcept
Set the index of this half-edge's face.
void setPairEdge(const uint32_t a_pairEdgeIndex) noexcept
Set the index of the pair edge.
size_t size() const noexcept
Get the number of vertices spanned by a half-edge.
Face class for navigating a DCEL mesh.
Definition EBGeometry_DCEL_Face.hpp:68
DCEL mesh class - stores a doubly-connected edge mesh.
Definition EBGeometry_DCEL_Mesh.hpp:100
Vertex class for navigating a DCEL mesh.
Definition EBGeometry_DCEL_Vertex.hpp:61
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26