Jet  v1.3.3
triangle3.h
Go to the documentation of this file.
1 // Copyright (c) 2018 Doyub Kim
2 //
3 // I am making my contributions/submissions to this project solely in my
4 // personal capacity and am not conveying any rights to any intellectual
5 // property of any third parties.
6 
7 #ifndef INCLUDE_JET_TRIANGLE3_H_
8 #define INCLUDE_JET_TRIANGLE3_H_
9 
10 #include <jet/surface3.h>
11 
12 namespace jet {
13 
20 class Triangle3 final : public Surface3 {
21  public:
22  class Builder;
23 
25  std::array<Vector3D, 3> points;
26 
28  std::array<Vector3D, 3> normals;
29 
31  std::array<Vector2D, 3> uvs;
32 
35  const Transform3& transform = Transform3(),
36  bool isNormalFlipped = false);
37 
40  const std::array<Vector3D, 3>& points,
41  const std::array<Vector3D, 3>& normals,
42  const std::array<Vector2D, 3>& uvs,
43  const Transform3& transform = Transform3(),
44  bool isNormalFlipped = false);
45 
47  Triangle3(const Triangle3& other);
48 
50  double area() const;
51 
54  const Vector3D& pt,
55  double* b0,
56  double* b1,
57  double* b2) const;
58 
61 
64 
66  static Builder builder();
67 
68  protected:
69  Vector3D closestPointLocal(const Vector3D& otherPoint) const override;
70 
71  bool intersectsLocal(const Ray3D& ray) const override;
72 
73  BoundingBox3D boundingBoxLocal() const override;
74 
76  const Vector3D& otherPoint) const override;
77 
79  const Ray3D& ray) const override;
80 };
81 
83 typedef std::shared_ptr<Triangle3> Triangle3Ptr;
84 
85 
89 class Triangle3::Builder final
90  : public SurfaceBuilderBase3<Triangle3::Builder> {
91  public:
93  Builder& withPoints(const std::array<Vector3D, 3>& points);
94 
96  Builder& withNormals(const std::array<Vector3D, 3>& normals);
97 
99  Builder& withUvs(const std::array<Vector2D, 3>& uvs);
100 
102  Triangle3 build() const;
103 
106 
107  private:
108  std::array<Vector3D, 3> _points;
109  std::array<Vector3D, 3> _normals;
110  std::array<Vector2D, 3> _uvs;
111 };
112 
113 } // namespace jet
114 
115 #endif // INCLUDE_JET_TRIANGLE3_H_
jet::Triangle3::Builder::withPoints
Builder & withPoints(const std::array< Vector3D, 3 > &points)
Returns builder with points.
jet::Triangle3::area
double area() const
Returns the area of this triangle.
jet::Triangle3::boundingBoxLocal
BoundingBox3D boundingBoxLocal() const override
Returns the bounding box of this surface object in local frame.
jet::Triangle3::closestNormalLocal
Vector3D closestNormalLocal(const Vector3D &otherPoint) const override
jet::Triangle3::getBarycentricCoords
void getBarycentricCoords(const Vector3D &pt, double *b0, double *b1, double *b2) const
Returns barycentric coordinates for the given point pt.
jet::Triangle3::closestIntersectionLocal
SurfaceRayIntersection3 closestIntersectionLocal(const Ray3D &ray) const override
Returns the closest intersection point for given ray in local frame.
jet::Triangle3::Builder
Front-end to create Triangle3 objects step by step.
Definition: triangle3.h:90
surface3.h
jet::BoundingBox< T, 3 >
3-D axis-aligned bounding box class.
Definition: bounding_box3.h:41
jet::Triangle3::builder
static Builder builder()
Returns builder fox Triangle3.
jet::SurfaceBuilderBase3
Base class for 3-D surface builder.
Definition: surface3.h:115
jet::Triangle3::points
std::array< Vector3D, 3 > points
Three points.
Definition: triangle3.h:22
jet::Surface3::isNormalFlipped
bool isNormalFlipped
Flips normal when calling Surface3::closestNormal(...).
Definition: surface3.h:33
jet
Definition: advection_solver2.h:18
jet::Triangle3::setNormalsToFaceNormal
void setNormalsToFaceNormal()
Set Triangle3::normals to the face normal.
jet::Triangle3::closestPointLocal
Vector3D closestPointLocal(const Vector3D &otherPoint) const override
jet::Triangle3::intersectsLocal
bool intersectsLocal(const Ray3D &ray) const override
jet::Triangle3::uvs
std::array< Vector2D, 3 > uvs
Three UV coordinates.
Definition: triangle3.h:31
jet::Surface3::transform
Transform3 transform
Local-to-world transform.
Definition: surface3.h:30
jet::Ray< T, 3 >
Class for 2-D ray.
Definition: ray3.h:21
jet::Triangle3::Builder::makeShared
Triangle3Ptr makeShared() const
Builds shared pointer of Triangle3 instance.
jet::SurfaceRayIntersection3
Struct that represents ray-surface intersection point.
Definition: surface3.h:19
jet::Vector< T, 3 >
3-D vector class.
Definition: vector3.h:25
jet::Triangle3::Builder::withNormals
Builder & withNormals(const std::array< Vector3D, 3 > &normals)
Returns builder with normals.
jet::Triangle3
3-D triangle geometry.
Definition: triangle3.h:20
jet::Triangle3::Triangle3
Triangle3(const Transform3 &transform=Transform3(), bool isNormalFlipped=false)
Constructs an empty triangle.
jet::Triangle3::normals
std::array< Vector3D, 3 > normals
Three normals.
Definition: triangle3.h:28
jet::Triangle3::Triangle3
Triangle3(const Triangle3 &other)
Copy constructor.
jet::Transform3
Represents 3-D rigid body transform.
Definition: transform3.h:20
jet::Triangle3::Triangle3
Triangle3(const std::array< Vector3D, 3 > &points, const std::array< Vector3D, 3 > &normals, const std::array< Vector2D, 3 > &uvs, const Transform3 &transform=Transform3(), bool isNormalFlipped=false)
Constructs a triangle with given points, normals, and uvs.
jet::Triangle3Ptr
std::shared_ptr< Triangle3 > Triangle3Ptr
Shared pointer for the Triangle3 type.
Definition: triangle3.h:83
jet::Surface3
Abstract base class for 3-D surface.
Definition: surface3.h:27
jet::Triangle3::faceNormal
Vector3D faceNormal() const
Returns the face normal of the triangle.
jet::Triangle3::Builder::withUvs
Builder & withUvs(const std::array< Vector2D, 3 > &uvs)
Returns builder with uvs.
jet::Triangle3::Builder::build
Triangle3 build() const
Builds Triangle3.