EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_Triangle.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2024 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
11#ifndef EBGEOMETRY_TRIANGLE_HPP
12#define EBGEOMETRY_TRIANGLE_HPP
13
14// Std includes
15#include <cstdint>
16#include <type_traits>
17
18// Our includes
19#include "EBGeometry_Array.hpp"
20#include "EBGeometry_Vec.hpp"
21
22namespace EBGeometry {
23
50template <class T>
52{
53 static_assert(std::is_floating_point_v<T>, "T must be a floating-point type");
54
55public:
59 using Vec2 = Vec2T<T>;
60
64 using Vec3 = Vec3T<T>;
65
69 Triangle() noexcept = default;
70
75 Triangle(const Triangle& a_otherTriangle) noexcept = default;
76
81 Triangle(Triangle&& a_otherTriangle) noexcept = default;
82
87 Triangle(const Array<Vec3, 3>& a_vertexPositions) noexcept;
88
92 ~Triangle() noexcept = default;
93
100 operator=(const Triangle& a_otherTriangle) noexcept = default;
101
107 Triangle&
108 operator=(Triangle&& a_otherTriangle) noexcept = default;
109
115 void
116 setNormal(const Vec3& a_normal) noexcept;
117
125 void
126 setVertexPositions(const Array<Vec3, 3>& a_vertexPositions) noexcept;
127
133 void
134 setVertexNormals(const Array<Vec3, 3>& a_vertexNormals) noexcept;
135
141 void
142 setEdgeNormals(const Array<Vec3, 3>& a_edgeNormals) noexcept;
143
148 void
149 setFaceId(const uint32_t a_faceId) noexcept;
150
157 void
158 computeNormal() noexcept;
159
166 [[nodiscard]] const Vec3&
167 getNormal() const noexcept;
168
175 [[nodiscard]] const Array<Vec3, 3>&
176 getVertexPositions() const noexcept;
177
183 [[nodiscard]] const Array<Vec3, 3>&
184 getVertexNormals() const noexcept;
185
191 [[nodiscard]] const Array<Vec3, 3>&
192 getEdgeNormals() const noexcept;
193
198 [[nodiscard]] uint32_t
199 getFaceId() const noexcept;
200
208 [[nodiscard]] T
209 signedDistance(const Vec3& a_point) const noexcept;
210
211protected:
216
221
226
231
235 uint32_t m_faceId = UINT32_MAX;
236};
237} // namespace EBGeometry
238
239#include "EBGeometry_TriangleImplem.hpp" // NOLINT
240
241#endif
A fixed-size array that compiles for both host and device.
Declaration of 2D and 3D point/vector classes with templated precision, and free functions on them.
Triangle class with signed distance functionality.
Definition EBGeometry_Triangle.hpp:52
const Vec3 & getNormal() const noexcept
Get the triangle normal vector.
Array< Vec3, 3 > m_edgeNormals
Triangle edge normals.
Definition EBGeometry_Triangle.hpp:230
void setNormal(const Vec3 &a_normal) noexcept
Set the triangle normal vector.
uint32_t getFaceId() const noexcept
Get the face id.
uint32_t m_faceId
Id of the face this triangle belongs to, UINT32_MAX if unset.
Definition EBGeometry_Triangle.hpp:235
void setFaceId(const uint32_t a_faceId) noexcept
Set the face id.
const Array< Vec3, 3 > & getVertexPositions() const noexcept
Get the vertex positions.
void setVertexNormals(const Array< Vec3, 3 > &a_vertexNormals) noexcept
Set the triangle vertex normals.
Triangle() noexcept=default
Default constructor. Does not put the triangle in a usable state.
void setEdgeNormals(const Array< Vec3, 3 > &a_edgeNormals) noexcept
Set the triangle edge normals.
Array< Vec3, 3 > m_vertexNormals
Triangle vertex normals.
Definition EBGeometry_Triangle.hpp:225
Vec3 m_triangleNormal
Triangle face normal.
Definition EBGeometry_Triangle.hpp:215
void computeNormal() noexcept
Compute the triangle normal vector.
Array< Vec3, 3 > m_vertexPositions
Triangle vertex positions.
Definition EBGeometry_Triangle.hpp:220
const Array< Vec3, 3 > & getVertexNormals() const noexcept
Get the vertex normals.
T signedDistance(const Vec3 &a_point) const noexcept
Compute the signed distance from the input point x to the triangle.
void setVertexPositions(const Array< Vec3, 3 > &a_vertexPositions) noexcept
Set the triangle vertex positions.
const Array< Vec3, 3 > & getEdgeNormals() const noexcept
Get the edge normals.
Two-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:37
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
static constexpr Vec3T< T > max() noexcept
Return the most-positive representable vector.
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
Vec2T< T > max(const Vec2T< T > &u, const Vec2T< T > &v) noexcept
Component-wise maximum of two vectors.
Fixed-size array with host- and device-callable members.
Definition EBGeometry_Array.hpp:33