Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TBasicTriangle.h
Go to the documentation of this file.
1#pragma once
2
3#include "Math/TVector3.h"
4#include "Math/TVector2.h"
6#include "Utility/utility.h"
7
8#include <cstddef>
9#include <utility>
10#include <array>
11
12namespace ph::math
13{
14
19template<typename T>
21{
22public:
23 // TODO: doc & test
25 const std::array<TVector3<T>, 3>& attributes,
26 const TVector3<T>& barycentricCoords);
27
29 const TVector3<T>& attributeA,
30 const TVector3<T>& attributeB,
31 const TVector3<T>& attributeC,
32 const TVector3<T>& barycentricCoords);
33
34 // TODO: doc & test
36 const std::array<TVector3<T>, 3>& attributes,
37 const std::array<TVector2<T>, 3>& parameterizations,
38 TVector3<T>* out_dXdU,
39 TVector3<T>* out_dXdV);
40
41public:
43 TVector3<T> vA,
44 TVector3<T> vB,
45 TVector3<T> vC);
46
47 explicit TBasicTriangle(std::array<TVector3<T>, 3> vertices);
48
49// Hide special members as this class is not intended to be used polymorphically.
50// It is derived class's choice to expose them (by defining them in public) or not.
51protected:
53
54public:
55 T getArea() const;
58 TAABB3D<T> getAABB() const;
59
67 T getAspectRatio() const;
68
76 TVector3<T> safeGetFaceNormal(const TVector3<T>& failSafe = {0, 1, 0}) const;
77
78 std::pair<TVector3<T>, TVector3<T>> getEdgeVectors() const;
79 TVector3<T> surfaceToBarycentric(const TVector3<T>& position) const;
80 TVector3<T> barycentricToSurface(const TVector3<T>& barycentricCoords) const;
81
89 TVector3<T> sampleToBarycentricOsada(const std::array<T, 2>& sample) const;
90
94 TVector3<T> sampleToBarycentricOsada(const std::array<T, 2>& sample, T* out_pdfA) const;
95
97
101 bool isDegenerate() const;
102
103 TVector3<T> getVa() const;
104 TVector3<T> getVb() const;
105 TVector3<T> getVc() const;
106
107private:
108 TVector3<T> m_vA;
109 TVector3<T> m_vB;
110 TVector3<T> m_vC;
111};
112
113}// end namespace ph::math
114
A 3-D Axis-Aligned Bounding Box (AABB).
Definition TAABB3D.h:32
Basic 3-D triangle functionalities.
Definition TBasicTriangle.h:21
TVector3< T > getCentroid() const
Definition TBasicTriangle.ipp:124
T getAspectRatio() const
Calculate aspect ratio of this triangle. For a triangle, its aspect ratio is defined to be the ratio ...
Definition TBasicTriangle.ipp:166
T uniformSurfaceSamplePdfA() const
Definition TBasicTriangle.ipp:262
TVector3< T > getFaceNormal() const
Definition TBasicTriangle.ipp:108
static TVector3< T > interpolate(const std::array< TVector3< T >, 3 > &attributes, const TVector3< T > &barycentricCoords)
Definition TBasicTriangle.ipp:16
static bool calcSurfaceParamDerivatives(const std::array< TVector3< T >, 3 > &attributes, const std::array< TVector2< T >, 3 > &parameterizations, TVector3< T > *out_dXdU, TVector3< T > *out_dXdV)
Definition TBasicTriangle.ipp:41
TVector3< T > getVb() const
Definition TBasicTriangle.ipp:284
bool isDegenerate() const
Definition TBasicTriangle.ipp:268
TVector3< T > sampleToBarycentricOsada(const std::array< T, 2 > &sample) const
Map the 2D sample to a position on the surface of the triangle. A common mapping on triangles which i...
Definition TBasicTriangle.ipp:236
TVector3< T > surfaceToBarycentric(const TVector3< T > &position) const
Definition TBasicTriangle.ipp:194
TVector3< T > safeGetFaceNormal(const TVector3< T > &failSafe={0, 1, 0}) const
Calculate face normal with a fail-safe value. The vertices may form a degenerate triangle (zero cross...
Definition TBasicTriangle.ipp:116
TVector3< T > getVa() const
Definition TBasicTriangle.ipp:278
TVector3< T > getVc() const
Definition TBasicTriangle.ipp:290
TAABB3D< T > getAABB() const
Definition TBasicTriangle.ipp:138
T getArea() const
Definition TBasicTriangle.ipp:100
TVector3< T > barycentricToSurface(const TVector3< T > &barycentricCoords) const
Definition TBasicTriangle.ipp:227
PH_DEFINE_INLINE_RULE_OF_5_MEMBERS(TBasicTriangle)
std::pair< TVector3< T >, TVector3< T > > getEdgeVectors() const
Definition TBasicTriangle.ipp:185
TBasicTriangle(TVector3< T > vA, TVector3< T > vB, TVector3< T > vC)
Definition TBasicTriangle.ipp:81
Represents a 2-D vector.
Definition TVector2.h:19
Represents a 3-D vector.
Definition TVector3.h:17
Math functions and utilities.
Definition TransformInfo.h:10