EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_DCEL_Vertex.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_VERTEX_HPP
13#define EBGEOMETRY_DCEL_VERTEX_HPP
14
15// Std includes
16#include <cmath>
17#include <cstdint>
18#include <type_traits>
19#include <vector>
20
21// Our includes
22#include "EBGeometry_DCEL.hpp"
24#include "EBGeometry_GPU.hpp"
25#include "EBGeometry_Math.hpp"
26#include "EBGeometry_Vec.hpp"
27
28namespace EBGeometry {
29
30namespace DCEL {
31
61template <class T>
63{
64 static_assert(std::is_floating_point_v<T>, "VertexT<T>: T must be a floating-point type");
65
66public:
70 using Vec3 = Vec3T<T>;
71
76
80 using Edge = EdgeT<T>;
81
85 using Face = FaceT<T>;
86
90 using Mesh = MeshT<T>;
91
96
102 VertexT() = default;
103
111 VertexT(const Vec3& a_position);
112
121 VertexT(const Vec3& a_position, const Vec3& a_normal);
122
132 VertexT(const Vertex& a_otherVertex) = default;
133
140 VertexT(Vertex&& a_otherVertex) = default;
141
145 ~VertexT() = default;
146
153 Vertex&
154 operator=(const Vertex& a_otherVertex) = default;
155
163 Vertex&
164 operator=(Vertex&& a_otherVertex) = default;
165
175 inline void
176 define(const Vec3& a_position, const uint32_t a_edgeIndex, const Vec3& a_normal) noexcept;
177
183 inline void
184 setPosition(const Vec3& a_position) noexcept;
185
191 inline void
192 setNormal(const Vec3& a_normal) noexcept;
193
200 inline void
201 setEdge(const uint32_t a_edgeIndex) noexcept;
202
209 inline void
211
230 inline void
231 computeVertexNormalAngleWeighted(const uint32_t a_thisVertexIndex,
232 const std::vector<uint32_t>& a_faceIndices,
233 const Mesh& a_mesh);
234
239 inline void
240 flipNormal() noexcept;
241
246 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
247 inline Vec3T<T>&
248 getPosition() noexcept;
249
254 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
255 inline const Vec3T<T>&
256 getPosition() const noexcept;
257
262 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
263 inline Vec3T<T>&
264 getNormal() noexcept;
265
270 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
271 inline const Vec3T<T>&
272 getNormal() const noexcept;
273
278 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
279 inline uint32_t
280 getOutgoingEdgeIndex() const noexcept;
281
287 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
288 inline Edge&
289 getOutgoingEdge(Mesh& a_mesh) noexcept;
290
297 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
298 inline const Edge&
299 getOutgoingEdge(const Mesh& a_mesh) const noexcept;
300
307 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
308 inline T
309 signedDistance(const Vec3& a_x0) const noexcept;
310
318 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
319 inline T
320 unsignedDistance2(const Vec3& a_x0) const noexcept;
321
322protected:
329 uint32_t m_outgoingEdge = UINT32_MAX;
330
334 Vec3 m_position = Vec3::zeros();
335
339 Vec3 m_normal = Vec3::zeros();
340};
341
342static_assert(std::is_trivially_copyable_v<VertexT<float>>, "VertexT<float> must be trivially copyable");
343static_assert(std::is_trivially_copyable_v<VertexT<double>>, "VertexT<double> must be trivially copyable");
344
349namespace VertexDetail {
350
363template <class T>
365inline Vec3T<T>
366angleWeightedTerm(const Vec3T<T>& a_x0, const Vec3T<T>& a_x1, const Vec3T<T>& a_x2, const Vec3T<T>& a_normal) noexcept
367{
368 Vec3T<T> v1 = a_x1 - a_x0;
369 Vec3T<T> v2 = a_x2 - a_x0;
370
371 v1 = v1 / v1.length();
372 v2 = v2 / v2.length();
373
374 // Clamp to [-1,1] to guard against std::acos(NaN) from floating-point rounding.
375 const T alpha = std::acos(Math::clamp(v1.dot(v2), T(-1), T(1)));
376
377 return alpha * a_normal;
378}
379
380} // namespace VertexDetail
381
382} // namespace DCEL
383
384} // namespace EBGeometry
385
386#include "EBGeometry_DCEL_VertexImplem.hpp"
387
388#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
#define EBGEOMETRY_HOST
Mark a function as callable from host code only (no-op on host compilers).
Definition EBGeometry_GPU.hpp:83
Scalar helpers and numeric limits that compile for both host and device.
Declaration of 2D and 3D point/vector classes with templated precision, and free functions on them.
Half-edge iterator class for navigating the half edge mesh.
Definition EBGeometry_DCEL_Iterator.hpp:51
Half-edge class for navigating a DCEL mesh.
Definition EBGeometry_DCEL_Edge.hpp:60
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:102
Vertex class for navigating a DCEL mesh.
Definition EBGeometry_DCEL_Vertex.hpp:63
T unsignedDistance2(const Vec3 &a_x0) const noexcept
Get the squared unsigned distance to this vertex.
void setEdge(const uint32_t a_edgeIndex) noexcept
Set the index of the outgoing edge.
uint32_t getOutgoingEdgeIndex() const noexcept
Get the index of the outgoing edge.
Vec3T< T > & getNormal() noexcept
Return modifiable vertex normal vector.
Edge & getOutgoingEdge(Mesh &a_mesh) noexcept
Get the outgoing edge.
Vec3T< T > & getPosition() noexcept
Return modifiable vertex position.
VertexT(const Vertex &a_otherVertex)=default
Copy constructor.
VertexT()=default
Default constructor.
void flipNormal() noexcept
Flip the normal vector.
Vertex & operator=(const Vertex &a_otherVertex)=default
Copy assignment operator.
T signedDistance(const Vec3 &a_x0) const noexcept
Get the signed distance to this vertex.
VertexT(const Vec3 &a_position, const Vec3 &a_normal)
Constructor.
~VertexT()=default
Destructor (does nothing)
void normalizeNormalVector() noexcept
Normalize the normal vector, ensuring its length is 1.
Vec3 m_position
Vertex position.
Definition EBGeometry_DCEL_Vertex.hpp:334
Vec3 m_normal
Vertex normal vector.
Definition EBGeometry_DCEL_Vertex.hpp:339
VertexT(const Vec3 &a_position)
Partial constructor.
void setNormal(const Vec3 &a_normal) noexcept
Set the vertex normal vector.
VertexT(Vertex &&a_otherVertex)=default
Move constructor.
uint32_t m_outgoingEdge
Index of an outgoing edge from this vertex.
Definition EBGeometry_DCEL_Vertex.hpp:329
Vertex & operator=(Vertex &&a_otherVertex)=default
Move assignment operator.
void computeVertexNormalAngleWeighted(const uint32_t a_thisVertexIndex, const std::vector< uint32_t > &a_faceIndices, const Mesh &a_mesh)
Compute the vertex normal, using the pseudonormal algorithm which weights the normal with the subtend...
void setPosition(const Vec3 &a_position) noexcept
Set the vertex position.
void define(const Vec3 &a_position, const uint32_t a_edgeIndex, const Vec3 &a_normal) noexcept
Define function.
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
constexpr T dot(const Vec3T< T > &u) const noexcept
Vector dot product.
T length() const noexcept
Compute vector length.
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
constexpr T clamp(const T &a_value, const T &a_lo, const T &a_hi) noexcept
A value limited to [lo, hi].
Definition EBGeometry_Math.hpp:78
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26