Jet  v1.3.3
surface3.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_SURFACE3_H_
8 #define INCLUDE_JET_SURFACE3_H_
9 
10 #include <jet/bounding_box3.h>
11 #include <jet/constants.h>
12 #include <jet/ray3.h>
13 #include <jet/transform3.h>
14 #include <memory>
15 
16 namespace jet {
17 
20  bool isIntersecting = false;
21  double distance = kMaxD;
24 };
25 
27 class Surface3 {
28  public:
31 
33  bool isNormalFlipped = false;
34 
37  bool isNormalFlipped = false);
38 
40  Surface3(const Surface3& other);
41 
43  virtual ~Surface3();
44 
47  Vector3D closestPoint(const Vector3D& otherPoint) const;
48 
51 
53  bool intersects(const Ray3D& ray) const;
54 
57  double closestDistance(const Vector3D& otherPoint) const;
58 
61 
64  Vector3D closestNormal(const Vector3D& otherPoint) const;
65 
67  virtual void updateQueryEngine();
68 
70  virtual bool isBounded() const;
71 
73  virtual bool isValidGeometry() const;
74 
77  bool isInside(const Vector3D& otherPoint) const;
78 
79  protected:
82  virtual Vector3D closestPointLocal(const Vector3D& otherPoint) const = 0;
83 
85  virtual BoundingBox3D boundingBoxLocal() const = 0;
86 
89  const Ray3D& ray) const = 0;
90 
93  virtual Vector3D closestNormalLocal(const Vector3D& otherPoint) const = 0;
94 
97  virtual bool intersectsLocal(const Ray3D& ray) const;
98 
101  virtual double closestDistanceLocal(const Vector3D& otherPoint) const;
102 
105  virtual bool isInsideLocal(const Vector3D& otherPoint) const;
106 };
107 
109 typedef std::shared_ptr<Surface3> Surface3Ptr;
110 
114 template <typename DerivedBuilder>
116  public:
118  DerivedBuilder& withIsNormalFlipped(bool isNormalFlipped);
119 
121  DerivedBuilder& withTranslation(const Vector3D& translation);
122 
124  DerivedBuilder& withOrientation(const QuaternionD& orientation);
125 
127  DerivedBuilder& withTransform(const Transform3& transform);
128 
129  protected:
130  bool _isNormalFlipped = false;
132 };
133 
134 template <typename T>
136  _isNormalFlipped = isNormalFlipped;
137  return static_cast<T&>(*this);
138 }
139 
140 template <typename T>
142  _transform.setTranslation(translation);
143  return static_cast<T&>(*this);
144 }
145 
146 template <typename T>
148  _transform.setOrientation(orientation);
149  return static_cast<T&>(*this);
150 }
151 
152 template <typename T>
154  _transform = transform;
155  return static_cast<T&>(*this);
156 }
157 
158 } // namespace jet
159 
160 #endif // INCLUDE_JET_SURFACE3_H_
jet::SurfaceBuilderBase3::withTranslation
DerivedBuilder & withTranslation(const Vector3D &translation)
Returns builder with translation.
Definition: surface3.h:141
transform3.h
jet::SurfaceRayIntersection3::distance
double distance
Definition: surface3.h:21
jet::Surface3::isBounded
virtual bool isBounded() const
Returns true if bounding box can be defined.
jet::Surface3::isInside
bool isInside(const Vector3D &otherPoint) const
jet::Surface3::isInsideLocal
virtual bool isInsideLocal(const Vector3D &otherPoint) const
jet::Surface3::closestDistanceLocal
virtual double closestDistanceLocal(const Vector3D &otherPoint) const
jet::Surface3::closestPoint
Vector3D closestPoint(const Vector3D &otherPoint) const
jet::Surface3::boundingBoxLocal
virtual BoundingBox3D boundingBoxLocal() const =0
Returns the bounding box of this surface object in local frame.
jet::Surface3::updateQueryEngine
virtual void updateQueryEngine()
Updates internal spatial query engine.
jet::BoundingBox< T, 3 >
3-D axis-aligned bounding box class.
Definition: bounding_box3.h:41
jet::Surface3::closestDistance
double closestDistance(const Vector3D &otherPoint) const
jet::SurfaceBuilderBase3::_isNormalFlipped
bool _isNormalFlipped
Definition: surface3.h:130
jet::SurfaceBuilderBase3
Base class for 3-D surface builder.
Definition: surface3.h:115
jet::Surface3::~Surface3
virtual ~Surface3()
Default destructor.
jet::Surface3::Surface3
Surface3(const Transform3 &transform=Transform3(), bool isNormalFlipped=false)
Constructs a surface with normal direction.
jet::Surface3::isNormalFlipped
bool isNormalFlipped
Flips normal when calling Surface3::closestNormal(...).
Definition: surface3.h:33
jet::Surface3Ptr
std::shared_ptr< Surface3 > Surface3Ptr
Shared pointer for the Surface3 type.
Definition: surface3.h:109
jet::Quaternion< double >
jet::Surface3::closestNormal
Vector3D closestNormal(const Vector3D &otherPoint) const
jet
Definition: advection_solver2.h:18
jet::Surface3::closestIntersectionLocal
virtual SurfaceRayIntersection3 closestIntersectionLocal(const Ray3D &ray) const =0
Returns the closest intersection point for given ray in local frame.
ray3.h
jet::SurfaceBuilderBase3::withTransform
DerivedBuilder & withTransform(const Transform3 &transform)
Returns builder with transform.
Definition: surface3.h:153
jet::Surface3::closestIntersection
SurfaceRayIntersection3 closestIntersection(const Ray3D &ray) const
Returns the closest intersection point for given ray.
jet::Surface3::closestPointLocal
virtual Vector3D closestPointLocal(const Vector3D &otherPoint) const =0
jet::Surface3::closestNormalLocal
virtual Vector3D closestNormalLocal(const Vector3D &otherPoint) const =0
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::SurfaceBuilderBase3::withIsNormalFlipped
DerivedBuilder & withIsNormalFlipped(bool isNormalFlipped)
Returns builder with flipped normal flag.
Definition: surface3.h:135
jet::SurfaceBuilderBase3::_transform
Transform3 _transform
Definition: surface3.h:131
jet::kMaxD
constexpr double kMaxD
Max double.
Definition: constants.h:88
jet::SurfaceRayIntersection3::normal
Vector3D normal
Definition: surface3.h:23
jet::SurfaceRayIntersection3
Struct that represents ray-surface intersection point.
Definition: surface3.h:19
jet::Surface3::intersects
bool intersects(const Ray3D &ray) const
Returns true if the given ray intersects with this surface object.
jet::Surface3::intersectsLocal
virtual bool intersectsLocal(const Ray3D &ray) const
jet::SurfaceRayIntersection3::isIntersecting
bool isIntersecting
Definition: surface3.h:20
constants.h
jet::Vector< T, 3 >
3-D vector class.
Definition: vector3.h:25
jet::SurfaceRayIntersection3::point
Vector3D point
Definition: surface3.h:22
jet::Surface3::boundingBox
BoundingBox3D boundingBox() const
Returns the bounding box of this surface object.
bounding_box3.h
jet::Transform3
Represents 3-D rigid body transform.
Definition: transform3.h:20
jet::SurfaceBuilderBase3::withOrientation
DerivedBuilder & withOrientation(const QuaternionD &orientation)
Returns builder with orientation.
Definition: surface3.h:147
jet::Surface3
Abstract base class for 3-D surface.
Definition: surface3.h:27
jet::Surface3::isValidGeometry
virtual bool isValidGeometry() const
Returns true if the surface is a valid geometry.
jet::Surface3::Surface3
Surface3(const Surface3 &other)
Copy constructor.