ImplicitSurfaceSet.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_IMPLICIT_SURFACE_SET_HPP
12 #define CUBBYFLOW_IMPLICIT_SURFACE_SET_HPP
13 
14 #include <Core/Array/Array.hpp>
15 #include <Core/Geometry/BVH.hpp>
17 
18 namespace CubbyFlow
19 {
27 template <size_t N>
28 class ImplicitSurfaceSet final : public ImplicitSurface<N>
29 {
30  public:
31  class Builder;
32 
35 
37  ImplicitSurfaceSet() = default;
38 
41  ConstArrayView1<std::shared_ptr<ImplicitSurface<N>>> surfaces,
42  const Transform<N>& _transform = Transform<N>{},
43  bool _isNormalFlipped = false);
44 
46  ImplicitSurfaceSet(ConstArrayView1<std::shared_ptr<Surface<N>>> surfaces,
47  const Transform<N>& _transform = Transform<N>{},
48  bool _isNormalFlipped = false);
49 
51  ~ImplicitSurfaceSet() override = default;
52 
55 
57  ImplicitSurfaceSet(ImplicitSurfaceSet&& other) noexcept;
58 
61 
64 
66  void UpdateQueryEngine() override;
67 
68  [[nodiscard]] bool IsBounded() const override;
69 
71  [[nodiscard]] bool IsValidGeometry() const override;
72 
74  [[nodiscard]] size_t NumberOfSurfaces() const;
75 
77  [[nodiscard]] const std::shared_ptr<ImplicitSurface<N>>& SurfaceAt(
78  size_t i) const;
79 
81  void AddExplicitSurface(const std::shared_ptr<Surface<N>>& surface);
82 
84  void AddSurface(const std::shared_ptr<ImplicitSurface<N>>& surface);
85 
87  static Builder GetBuilder();
88 
89  private:
90  [[nodiscard]] Vector<double, N> ClosestPointLocal(
91  const Vector<double, N>& otherPoint) const override;
92 
93  [[nodiscard]] BoundingBox<double, N> BoundingBoxLocal() const override;
94 
95  [[nodiscard]] bool IsInsideLocal(
96  const Vector<double, N>& otherPoint) const override;
97 
98  [[nodiscard]] double ClosestDistanceLocal(
99  const Vector<double, N>& otherPoint) const override;
100 
101  [[nodiscard]] bool IntersectsLocal(
102  const Ray<double, N>& ray) const override;
103 
104  [[nodiscard]] Vector<double, N> ClosestNormalLocal(
105  const Vector<double, N>& otherPoint) const override;
106 
107  [[nodiscard]] SurfaceRayIntersection<N> ClosestIntersectionLocal(
108  const Ray<double, N>& ray) const override;
109 
110  [[nodiscard]] double SignedDistanceLocal(
111  const Vector<double, N>& otherPoint) const override;
112 
113  void InvalidateBVH() const;
114 
115  void BuildBVH() const;
116 
118  Array1<std::shared_ptr<ImplicitSurface<N>>> m_unboundedSurfaces;
119  mutable BVH<std::shared_ptr<ImplicitSurface<N>>, N> m_bvh;
120  mutable bool m_bvhInvalidated = true;
121 };
122 
125 
128 
130 using ImplicitSurfaceSet2Ptr = std::shared_ptr<ImplicitSurfaceSet2>;
131 
133 using ImplicitSurfaceSet3Ptr = std::shared_ptr<ImplicitSurfaceSet3>;
134 
138 template <size_t N>
140  : public SurfaceBuilderBase<N, typename ImplicitSurfaceSet<N>::Builder>
141 {
142  public:
144  Builder& WithSurfaces(
145  const ConstArrayView1<std::shared_ptr<ImplicitSurface<N>>>& surfaces);
146 
148  Builder& WithExplicitSurfaces(
149  const ConstArrayView1<std::shared_ptr<Surface<N>>>& surfaces);
150 
152  ImplicitSurfaceSet<N> Build() const;
153 
155  std::shared_ptr<ImplicitSurfaceSet<N>> MakeShared() const;
156 
157  private:
159  using Base::m_isNormalFlipped;
160  using Base::m_transform;
161 
163 };
164 } // namespace CubbyFlow
165 
166 #endif
std::shared_ptr< ImplicitSurfaceSet2 > ImplicitSurfaceSet2Ptr
Shared pointer type for the ImplicitSurfaceSet2.
Definition: ImplicitSurfaceSet.hpp:130
Abstract base class for N-D implicit surface.
Definition: ImplicitSurface.hpp:20
Class for N-D ray.
Definition: Ray.hpp:25
N-D implicit surface set.
Definition: ImplicitSurfaceSet.hpp:28
void UpdateQueryEngine() override
Updates internal spatial query engine.
void AddExplicitSurface(const std::shared_ptr< Surface< N >> &surface)
Adds an explicit surface instance.
Front-end to create ImplicitSurfaceSet objects step by step.
Definition: ImplicitSurfaceSet.hpp:139
static Builder GetBuilder()
Returns builder fox ImplicitSurfaceSet.
Represents N-D rigid body transform.
Definition: Transform.hpp:82
Definition: Matrix.hpp:27
~ImplicitSurfaceSet() override=default
Default virtual destructor.
size_t NumberOfSurfaces() const
Returns the number of implicit surfaces.
bool IsValidGeometry() const override
Returns true if the surface is a valid geometry.
Definition: pybind11Utils.hpp:20
Definition: Array-Impl.hpp:19
Abstract base class for N-D surface.
Definition: Surface.hpp:38
Struct that represents ray-surface intersection point.
Definition: Surface.hpp:25
ImplicitSurfaceSet & operator=(const ImplicitSurfaceSet &other)
Copy assignment operator.
void AddSurface(const std::shared_ptr< ImplicitSurface< N >> &surface)
Adds an implicit surface instance.
Generic N-dimensional array class interface.
Definition: Array.hpp:32
Bounding Volume Hierarchy (BVH) in N-D.
Definition: BVH.hpp:30
ImplicitSurfaceSet()=default
Constructs an empty implicit surface set.
bool IsBounded() const override
Returns true if bounding box can be defined.
const std::shared_ptr< ImplicitSurface< N > > & SurfaceAt(size_t i) const
Returns the i-th implicit surface.
Base class for N-D surface builder.
Definition: Surface.hpp:153
std::shared_ptr< ImplicitSurfaceSet3 > ImplicitSurfaceSet3Ptr
Shared pointer type for the ImplicitSurfaceSet3.
Definition: ImplicitSurfaceSet.hpp:133