Loading...
Searching...
No Matches
Surface.hpp
Go to the documentation of this file.
1// This code is based on Jet framework.
2// Copyright (c) 2018 Doyub Kim
3// CubbyFlow is voxel-based fluid simulation engine for computer games.
4// Copyright (c) 2020 CubbyFlow Team
5// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6// AI Part: Dongheon Cho, Minseo Kim
7// We are making my contributions/submissions to this project solely in our
8// personal capacity and are not conveying any rights to any intellectual
9// property of any third parties.
10
11#ifndef CUBBYFLOW_SURFACE_HPP
12#define CUBBYFLOW_SURFACE_HPP
13
14#include <Core/Geometry/Ray.hpp>
17
18#include <limits>
19#include <memory>
20
21namespace CubbyFlow
22{
24template <size_t N>
26{
27 bool isIntersecting = false;
28 double distance = std::numeric_limits<double>::max();
31};
32
35
37template <size_t N>
39{
40 public:
43 bool isNormalFlipped = false);
44
46 virtual ~Surface() = default;
47
49 Surface(const Surface& other);
50
52 Surface(Surface&& other) noexcept;
53
55 Surface& operator=(const Surface& other);
56
58 Surface& operator=(Surface&& other) noexcept;
59
63 const Vector<double, N>& otherPoint) const;
64
67
69 [[nodiscard]] bool Intersects(const Ray<double, N>& ray) const;
70
73 [[nodiscard]] double ClosestDistance(
74 const Vector<double, N>& otherPoint) const;
75
78 const Ray<double, N>& ray) const;
79
83 const Vector<double, N>& otherPoint) const;
84
86 virtual void UpdateQueryEngine();
87
89 [[nodiscard]] virtual bool IsBounded() const;
90
92 [[nodiscard]] virtual bool IsValidGeometry() const;
93
96 [[nodiscard]] bool IsInside(const Vector<double, N>& otherPoint) const;
97
100
102 bool isNormalFlipped = false;
103
104 protected:
108 const Vector<double, N>& otherPoint) const = 0;
109
111 [[nodiscard]] virtual BoundingBox<double, N> BoundingBoxLocal() const = 0;
112
115 const Ray<double, N>& ray) const = 0;
116
120 const Vector<double, N>& otherPoint) const = 0;
121
124 [[nodiscard]] virtual bool IntersectsLocal(const Ray<double, N>& ray) const;
125
128 [[nodiscard]] virtual double ClosestDistanceLocal(
129 const Vector<double, N>& otherPoint) const;
130
133 [[nodiscard]] virtual bool IsInsideLocal(
134 const Vector<double, N>& otherPoint) const;
135};
136
139
142
144using Surface2Ptr = std::shared_ptr<Surface2>;
145
147using Surface3Ptr = std::shared_ptr<Surface3>;
148
152template <size_t N, typename DerivedBuilder>
154{
155 public:
157 DerivedBuilder& WithIsNormalFlipped(bool isNormalFlipped);
158
160 DerivedBuilder& WithTranslation(const Vector<double, N>& translation);
161
163 DerivedBuilder& WithOrientation(const Orientation<N>& orientation);
164
166 DerivedBuilder& WithTransform(const Transform<N>& transform);
167
168 protected:
169 bool m_isNormalFlipped = false;
171};
172
173template <size_t N, typename T>
175{
176 m_isNormalFlipped = isNormalFlipped;
177 return static_cast<T&>(*this);
178}
179
180template <size_t N, typename T>
182 const Vector<double, N>& translation)
183{
184 m_transform.SetTranslation(translation);
185 return static_cast<T&>(*this);
186}
187
188template <size_t N, typename T>
190{
191 m_transform.SetOrientation(orientation);
192 return static_cast<T&>(*this);
193}
194
195template <size_t N, typename T>
197{
198 m_transform = transform;
199 return static_cast<T&>(*this);
200}
201
202template <typename T>
204
205template <typename T>
207} // namespace CubbyFlow
208
209#endif
N-D axis-aligned bounding box class.
Definition BoundingBox.hpp:47
Definition Matrix.hpp:30
Definition Transform.hpp:23
Class for N-D ray.
Definition Ray.hpp:26
Base class for N-D surface builder.
Definition Surface.hpp:154
DerivedBuilder & WithOrientation(const Orientation< N > &orientation)
Returns builder with orientation.
Definition Surface.hpp:189
Transform< N > m_transform
Definition Surface.hpp:170
DerivedBuilder & WithTransform(const Transform< N > &transform)
Returns builder with transform.
Definition Surface.hpp:196
DerivedBuilder & WithIsNormalFlipped(bool isNormalFlipped)
Returns builder with flipped normal flag.
Definition Surface.hpp:174
DerivedBuilder & WithTranslation(const Vector< double, N > &translation)
Returns builder with translation.
Definition Surface.hpp:181
bool m_isNormalFlipped
Definition Surface.hpp:169
Abstract base class for N-D surface.
Definition Surface.hpp:39
bool isNormalFlipped
Flips normal.
Definition Surface.hpp:102
Surface(const Transform< N > &transform=Transform< N >(), bool isNormalFlipped=false)
Constructs a surface with normal direction.
Surface(const Surface &other)
Copy constructor.
Surface(Surface &&other) noexcept
Move constructor.
Vector< double, N > ClosestPoint(const Vector< double, N > &otherPoint) const
virtual bool IsInsideLocal(const Vector< double, N > &otherPoint) const
virtual ~Surface()=default
Default virtual destructor.
virtual bool IntersectsLocal(const Ray< double, N > &ray) const
virtual bool IsValidGeometry() const
Returns true if the surface is a valid geometry.
virtual void UpdateQueryEngine()
Updates internal spatial query engine.
bool IsInside(const Vector< double, N > &otherPoint) const
virtual BoundingBox< double, N > BoundingBoxLocal() const =0
Returns the bounding box of this surface object in local frame.
double ClosestDistance(const Vector< double, N > &otherPoint) const
virtual Vector< double, N > ClosestNormalLocal(const Vector< double, N > &otherPoint) const =0
virtual bool IsBounded() const
Returns true if bounding box can be defined.
Surface & operator=(Surface &&other) noexcept
Move assignment operator.
bool Intersects(const Ray< double, N > &ray) const
Returns true if the given ray intersects with this surface object.
Vector< double, N > ClosestNormal(const Vector< double, N > &otherPoint) const
Transform< N > transform
Local-to-world transform.
Definition Surface.hpp:99
virtual double ClosestDistanceLocal(const Vector< double, N > &otherPoint) const
virtual SurfaceRayIntersection< N > ClosestIntersectionLocal(const Ray< double, N > &ray) const =0
Returns the closest intersection point for given ray in local frame.
SurfaceRayIntersection< N > ClosestIntersection(const Ray< double, N > &ray) const
Returns the closest intersection point for given ray.
Surface & operator=(const Surface &other)
Copy assignment operator.
BoundingBox< double, N > GetBoundingBox() const
Returns the bounding box of this surface object.
virtual Vector< double, N > ClosestPointLocal(const Vector< double, N > &otherPoint) const =0
Represents N-D rigid body transform.
Definition Transform.hpp:83
Definition pybind11Utils.hpp:21
std::shared_ptr< Surface3 > Surface3Ptr
Shared pointer for the Surface3 type.
Definition Surface.hpp:147
std::shared_ptr< Surface2 > Surface2Ptr
Shared pointer for the Surface2 type.
Definition Surface.hpp:144
Struct that represents ray-surface intersection point.
Definition Surface.hpp:26
Vector< double, N > point
Definition Surface.hpp:29
Vector< double, N > normal
Definition Surface.hpp:30
bool isIntersecting
Definition Surface.hpp:27
double distance
Definition Surface.hpp:28