Surface3.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: Surface3.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Abstract base class for 3-D surface.
6 > Created Time: 2017/03/20
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_SURFACE3_H
10 #define CUBBYFLOW_SURFACE3_H
11 
13 #include <Core/Ray/Ray3.h>
15 #include <Core/Vector/Vector3.h>
16 
17 #include <limits>
18 #include <memory>
19 
20 namespace CubbyFlow
21 {
24  {
25  bool isIntersecting = false;
26  double distance = std::numeric_limits<double>::max();
29  };
30 
32  class Surface3
33  {
34  public:
37 
39  bool isNormalFlipped = false;
40 
42  Surface3(
43  const Transform3& transform = Transform3(),
44  bool isNormalFlipped = false);
45 
47  Surface3(const Surface3& other);
48 
50  virtual ~Surface3();
51 
53  Vector3D ClosestPoint(const Vector3D& otherPoint) const;
54 
56  BoundingBox3D BoundingBox() const;
57 
59  bool Intersects(const Ray3D& ray) const;
60 
63  double ClosestDistance(const Vector3D& otherPoint) const;
64 
67 
70  Vector3D ClosestNormal(const Vector3D& otherPoint) const;
71 
73  virtual void UpdateQueryEngine();
74 
75  protected:
78  virtual Vector3D ClosestPointLocal(const Vector3D& otherPoint) const = 0;
79 
81  virtual BoundingBox3D BoundingBoxLocal() const = 0;
82 
84  virtual SurfaceRayIntersection3 ClosestIntersectionLocal(const Ray3D& ray) const = 0;
85 
88  virtual Vector3D ClosestNormalLocal(const Vector3D& otherPoint) const = 0;
89 
92  virtual bool IntersectsLocal(const Ray3D& ray) const;
93 
96  virtual double ClosestDistanceLocal(const Vector3D& otherPoint) const;
97  };
98 
100  using Surface3Ptr = std::shared_ptr<Surface3>;
101 
105  template <typename DerivedBuilder>
107  {
108  public:
110  DerivedBuilder& WithIsNormalFlipped(bool isNormalFlipped);
111 
113  DerivedBuilder& WithTranslation(const Vector3D& translation);
114 
116  DerivedBuilder& WithOrientation(const QuaternionD& orientation);
117 
119  DerivedBuilder& WithTransform(const Transform3& transform);
120 
121  protected:
122  bool m_isNormalFlipped = false;
124  };
125 
126  template <typename T>
128  {
129  m_isNormalFlipped = isNormalFlipped;
130  return static_cast<T&>(*this);
131  }
132 
133  template <typename T>
135  {
136  m_transform.SetTranslation(translation);
137  return static_cast<T&>(*this);
138  }
139 
140  template <typename T>
142  {
143  m_transform.SetOrientation(orientation);
144  return static_cast<T&>(*this);
145  }
146 
147  template <typename T>
149  {
150  m_transform = transform;
151  return static_cast<T&>(*this);
152  }
153 }
154 
155 #endif
bool isIntersecting
Definition: Surface3.h:25
3-D vector class.
Definition: Vector3.h:26
virtual BoundingBox3D BoundingBoxLocal() const =0
Returns the bounding box of this surface object in local frame.
Vector3D ClosestNormal(const Vector3D &otherPoint) const
virtual void UpdateQueryEngine()
Updates internal spatial query engine.
virtual bool IntersectsLocal(const Ray3D &ray) const
DerivedBuilder & WithTransform(const Transform3 &transform)
Returns builder with transform.
Definition: Surface3.h:148
Vector3D normal
Definition: Surface3.h:28
double ClosestDistance(const Vector3D &otherPoint) const
Surface3(const Transform3 &transform=Transform3(), bool isNormalFlipped=false)
Constructs a surface with normal direction.
virtual Vector3D ClosestPointLocal(const Vector3D &otherPoint) const =0
bool m_isNormalFlipped
Definition: Surface3.h:122
double distance
Definition: Surface3.h:26
virtual Vector3D ClosestNormalLocal(const Vector3D &otherPoint) const =0
SurfaceRayIntersection3 ClosestIntersection(const Ray3D &ray) const
Returns the closest intersection point for given ray.
DerivedBuilder & WithIsNormalFlipped(bool isNormalFlipped)
Returns builder with flipped normal flag.
Definition: Surface3.h:127
Structure that represents ray-surface intersection point.
Definition: Surface3.h:23
Base class for 3-D surface builder.
Definition: Surface3.h:106
Definition: pybind11Utils.h:24
Vector3D point
Definition: Surface3.h:27
Abstract base class for 3-D surface.
Definition: Surface3.h:32
Transform3 transform
Local-to-world transform.
Definition: Surface3.h:36
std::shared_ptr< Surface3 > Surface3Ptr
Shared pointer for the Surface3 type.
Definition: Surface3.h:100
3-D axis-aligned bounding box class.
Definition: BoundingBox3.h:44
Represents 3-D rigid body transform.
Definition: Transform3.h:22
bool Intersects(const Ray3D &ray) const
Returns true if the given ray intersects with this surface object.
bool isNormalFlipped
Flips normal when calling Surface3::closestNormal(...).
Definition: Surface3.h:39
DerivedBuilder & WithOrientation(const QuaternionD &orientation)
Returns builder with orientation.
Definition: Surface3.h:141
virtual double ClosestDistanceLocal(const Vector3D &otherPoint) const
Transform3 m_transform
Definition: Surface3.h:123
virtual ~Surface3()
Default destructor.
BoundingBox3D BoundingBox() const
Returns the bounding box of this surface object.
Vector3D ClosestPoint(const Vector3D &otherPoint) const
Returns the closest point from the given point otherPoint to the surface.
DerivedBuilder & WithTranslation(const Vector3D &translation)
Returns builder with translation.
Definition: Surface3.h:134
Class for 3-D ray.
Definition: Ray3.h:23
virtual SurfaceRayIntersection3 ClosestIntersectionLocal(const Ray3D &ray) const =0
Returns the closest intersection point for given ray in local frame.