EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_DCEL_Face.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_FACE_HPP
13#define EBGEOMETRY_DCEL_FACE_HPP
14
15// Std includes
16#include <cstddef>
17#include <cstdint>
18#include <type_traits>
19#include <vector>
20
21// Our includes
22#include "EBGeometry_DCEL.hpp"
25#include "EBGeometry_GPU.hpp"
26#include "EBGeometry_Vec.hpp"
27
28namespace EBGeometry {
29
30namespace DCEL {
31
66template <class T>
67class FaceT
68{
69 static_assert(std::is_floating_point_v<T>, "FaceT requires a floating-point T");
70
71public:
75 using Vec3 = Vec3T<T>;
76
81
85 using Edge = EdgeT<T>;
86
90 using Face = FaceT<T>;
91
95 using Mesh = MeshT<T>;
96
101
106 FaceT() = default;
107
114 FaceT(const uint32_t a_edgeIndex);
115
123 FaceT(const Face& a_otherFace) = default;
124
131 FaceT(Face&& a_otherFace) = default;
132
136 ~FaceT() = default;
137
144 Face&
145 operator=(const Face& a_otherFace) = default;
146
154 Face&
155 operator=(Face&& a_otherFace) = default;
156
163 inline void
164 define(const Vec3& a_normal, const uint32_t a_edgeIndex) noexcept;
165
175 inline void
176 reconcile(const Mesh& a_mesh);
177
183 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
184 inline uint32_t
185 numVertices(const Mesh& a_mesh) const noexcept;
186
196 inline void
198
203 inline void
204 flipNormal() noexcept;
205
212 inline void
213 setHalfEdge(const uint32_t a_halfEdgeIndex) noexcept;
214
221 inline void
223
228 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
229 inline uint32_t
230 getHalfEdgeIndex() const noexcept;
231
236 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
237 inline Vec3T<T>&
238 getCentroid() noexcept;
239
244 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
245 inline const Vec3T<T>&
246 getCentroid() const noexcept;
247
253 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
254 inline T&
255 getCentroid(const size_t a_dir) noexcept;
256
262 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
263 inline const T&
264 getCentroid(const size_t a_dir) const noexcept;
265
270 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
271 inline Vec3T<T>&
272 getNormal() noexcept;
273
278 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
279 inline const Vec3T<T>&
280 getNormal() const noexcept;
281
286 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
287 inline T&
288 getArea() noexcept;
289
294 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
295 inline const T&
296 getArea() const noexcept;
297
308 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
309 inline T
310 signedDistance(const Vec3& a_x0, const Mesh& a_mesh) const noexcept;
311
330 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
331 inline T
332 rayCrossing(const Vec3& a_origin, const Vec3& a_direction, T a_tMin, T a_tMax, const Mesh& a_mesh) const noexcept;
333
344 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
345 inline T
346 unsignedDistance2(const Vec3& a_x0, const Mesh& a_mesh) const noexcept;
347
354 [[nodiscard]] EBGEOMETRY_HOST
355 inline std::vector<Vec3T<T>>
356 getAllVertexCoordinates(const Mesh& a_mesh) const;
357
364 [[nodiscard]] EBGEOMETRY_HOST
365 inline std::vector<uint32_t>
366 gatherVertexIndices(const Mesh& a_mesh) const;
367
374 [[nodiscard]] EBGEOMETRY_HOST
375 inline std::vector<uint32_t>
376 gatherEdgeIndices(const Mesh& a_mesh) const;
377
386 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
387 inline Vec3T<T>
388 getSmallestCoordinate(const Mesh& a_mesh) const noexcept;
389
398 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
399 inline Vec3T<T>
400 getHighestCoordinate(const Mesh& a_mesh) const noexcept;
401
402protected:
407 uint32_t m_halfEdge = UINT32_MAX;
408
412 Vec3 m_normal = Vec3::zeros();
413
417 Vec3 m_centroid = Vec3::zeros();
418
422 T m_area{T(0)};
423
432 uint32_t m_xDir = UINT32_MAX;
433
439 uint32_t m_yDir = UINT32_MAX;
440
445
451 inline void
452 computeCentroid(const Mesh& a_mesh);
453
461 inline void
462 computeNormal(const Mesh& a_mesh);
463
469 inline void
470 computeArea(const Mesh& a_mesh);
471
477 inline void
479
485 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
486 inline Vec3T<T>
487 projectPointIntoFacePlane(const Vec3& a_p) const noexcept;
488
496 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
497 inline bool
498 isPointInsideFace(const Vec3& a_p, const Mesh& a_mesh) const noexcept;
499
505 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
506 inline Vec2T<T>
507 projectPoint(const Vec3& a_point) const noexcept;
508
516 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
517 inline int
518 computeWindingNumber(const Vec2T<T>& a_point, const Mesh& a_mesh) const noexcept;
519
527 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
528 inline size_t
529 computeCrossingNumber(const Vec2T<T>& a_point, const Mesh& a_mesh) const noexcept;
530
538 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
539 inline T
540 computeSubtendedAngle(const Vec2T<T>& a_point, const Mesh& a_mesh) const noexcept;
541};
542
543static_assert(std::is_trivially_copyable_v<FaceT<float>>, "FaceT<float> must be trivially copyable");
544static_assert(std::is_trivially_copyable_v<FaceT<double>>, "FaceT<double> must be trivially copyable");
545
546} // namespace DCEL
547
548} // namespace EBGeometry
549
550#include "EBGeometry_DCEL_FaceImplem.hpp"
551
552#endif
Namespace documentation.
Declaration of a half-edge class for use in DCEL descriptions of polygon tessellations.
Declaration of a vertex 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
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
Vec3T< T > & getNormal() noexcept
Get modifiable normal vector.
uint32_t numVertices(const Mesh &a_mesh) const noexcept
Number of vertices on this face's half-edge loop.
bool isPointInsideFace(const Vec3 &a_p, const Mesh &a_mesh) const noexcept
Check if a point projects to inside or outside the polygon face.
void normalizeNormalVector() noexcept
Normalize the normal vector, ensuring it has a length of 1.
T signedDistance(const Vec3 &a_x0, const Mesh &a_mesh) const noexcept
Compute the signed distance to a point.
Vec3T< T > getHighestCoordinate(const Mesh &a_mesh) const noexcept
Get the upper-right-most coordinate of this polygon face.
void setHalfEdge(const uint32_t a_halfEdgeIndex) noexcept
Set the half edge index.
FaceT(const Face &a_otherFace)=default
Copy constructor.
Vec3T< T > getSmallestCoordinate(const Mesh &a_mesh) const noexcept
Get the lower-left-most coordinate of this polygon face.
FaceT()=default
Default constructor. Sets the half-edge index to the unset sentinel and the inside/outside algorithm ...
std::vector< uint32_t > gatherVertexIndices(const Mesh &a_mesh) const
Return the indices of all the vertices on this polygon.
FaceT(Face &&a_otherFace)=default
Move constructor.
std::vector< uint32_t > gatherEdgeIndices(const Mesh &a_mesh) const
Return the indices of all the half-edges on this polygon.
T & getArea() noexcept
Get modifiable polygon area (computed during reconcile()).
void computeProjectionDirections() noexcept
Compute the 2D embedding of this polygon from the current normal vector and topology,...
Vec3 m_normal
Polygon face normal vector.
Definition EBGeometry_DCEL_Face.hpp:412
T unsignedDistance2(const Vec3 &a_x0, const Mesh &a_mesh) const noexcept
Compute the unsigned squared distance to a point.
void define(const Vec3 &a_normal, const uint32_t a_edgeIndex) noexcept
Define function which sets the normal vector and half-edge index.
void computeNormal(const Mesh &a_mesh)
Compute the unit normal vector of this polygon (Newell's method).
Vec2T< T > projectPoint(const Vec3 &a_point) const noexcept
Project a 3D point to this face's 2D embedding by dropping one coordinate.
FaceT(const uint32_t a_edgeIndex)
Partial constructor. Calls default constructor but associates a half-edge.
~FaceT()=default
Destructor (does nothing)
size_t computeCrossingNumber(const Vec2T< T > &a_point, const Mesh &a_mesh) const noexcept
Compute the crossing number of a +x ray from a projected 2D point with this polygon.
T rayCrossing(const Vec3 &a_origin, const Vec3 &a_direction, T a_tMin, T a_tMax, const Mesh &a_mesh) const noexcept
Where a ray crosses the face, from either side.
void computeCentroid(const Mesh &a_mesh)
Compute the centroid position of this polygon.
uint32_t m_yDir
Cartesian axis used as the 2D y-direction of this polygon's 2D embedding (stored by reconcile()).
Definition EBGeometry_DCEL_Face.hpp:439
InsideOutsideAlgorithm m_insideOutsideAlgorithm
Algorithm for inside/outside tests.
Definition EBGeometry_DCEL_Face.hpp:444
void setInsideOutsideAlgorithm(InsideOutsideAlgorithm a_algorithm) noexcept
Set the inside/outside algorithm when determining if a point projects to the inside or outside of the...
void flipNormal() noexcept
Flip the normal vector.
T computeSubtendedAngle(const Vec2T< T > &a_point, const Mesh &a_mesh) const noexcept
Compute the total subtended angle of this polygon's edges around a projected 2D point.
uint32_t m_halfEdge
This polygon's half-edge index. A valid face will always have this set.
Definition EBGeometry_DCEL_Face.hpp:407
Vec3T< T > & getCentroid() noexcept
Get modifiable centroid.
void computeArea(const Mesh &a_mesh)
Compute the area of this polygon and cache it in m_area.
Vec3 m_centroid
Polygon face centroid position.
Definition EBGeometry_DCEL_Face.hpp:417
uint32_t getHalfEdgeIndex() const noexcept
Get the index of the starting half-edge.
Vec3T< T > projectPointIntoFacePlane(const Vec3 &a_p) const noexcept
Compute the projection of a point onto the polygon face plane.
void reconcile(const Mesh &a_mesh)
Reconcile face. This will compute the normal vector, area, centroid, and the 2D embedding of the poly...
uint32_t m_xDir
Cartesian axis used as the 2D x-direction of this polygon's 2D embedding (stored by reconcile())....
Definition EBGeometry_DCEL_Face.hpp:432
std::vector< Vec3T< T > > getAllVertexCoordinates(const Mesh &a_mesh) const
Return the coordinates of all the vertices on this polygon.
T m_area
Cached polygon face area (stored by reconcile()).
Definition EBGeometry_DCEL_Face.hpp:422
int computeWindingNumber(const Vec2T< T > &a_point, const Mesh &a_mesh) const noexcept
Compute the winding number of this polygon's boundary around a projected 2D point.
Face & operator=(Face &&a_otherFace)=default
Move assignment operator.
Face & operator=(const Face &a_otherFace)=default
Copy assignment operator.
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
Two-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:37
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
InsideOutsideAlgorithm
Supported algorithms for testing whether a point projects to the inside of a polygon face.
Definition EBGeometry_DCEL.hpp:67
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26