SurfaceSet.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_SET_HPP
12 #define CUBBYFLOW_SURFACE_SET_HPP
13 
14 #include <Core/Geometry/BVH.hpp>
16 
17 namespace CubbyFlow
18 {
26 template <size_t N>
27 class SurfaceSet final : public Surface<N>
28 {
29  public:
30  class Builder;
31 
33  SurfaceSet() = default;
34 
36  explicit SurfaceSet(
37  const ConstArrayView1<std::shared_ptr<Surface<N>>>& others,
38  const Transform<N>& _transform = Transform<N>{},
39  bool _isNormalFlipped = false);
40 
42  ~SurfaceSet() override = default;
43 
45  SurfaceSet(const SurfaceSet& other);
46 
48  SurfaceSet(SurfaceSet&& other) noexcept;
49 
51  SurfaceSet& operator=(const SurfaceSet& other);
52 
54  SurfaceSet& operator=(SurfaceSet&& other) noexcept;
55 
57  void UpdateQueryEngine() override;
58 
60  [[nodiscard]] bool IsBounded() const override;
61 
63  [[nodiscard]] bool IsValidGeometry() const override;
64 
66  [[nodiscard]] size_t NumberOfSurfaces() const;
67 
69  [[nodiscard]] const std::shared_ptr<Surface<N>>& SurfaceAt(size_t i) const;
70 
72  void AddSurface(const std::shared_ptr<Surface<N>>& surface);
73 
75  static Builder GetBuilder();
76 
77  private:
78  [[nodiscard]] Vector<double, N> ClosestPointLocal(
79  const Vector<double, N>& otherPoint) const override;
80 
81  [[nodiscard]] BoundingBox<double, N> BoundingBoxLocal() const override;
82 
83  [[nodiscard]] SurfaceRayIntersection<N> ClosestIntersectionLocal(
84  const Ray<double, N>& ray) const override;
85 
86  [[nodiscard]] Vector<double, N> ClosestNormalLocal(
87  const Vector<double, N>& otherPoint) const override;
88 
89  [[nodiscard]] bool IntersectsLocal(
90  const Ray<double, N>& ray) const override;
91 
92  [[nodiscard]] double ClosestDistanceLocal(
93  const Vector<double, N>& otherPoint) const override;
94 
95  [[nodiscard]] bool IsInsideLocal(
96  const Vector<double, N>& otherPoint) const override;
97 
98  void InvalidateBVH() const;
99 
100  void BuildBVH() const;
101 
103  Array1<std::shared_ptr<Surface<N>>> m_unboundedSurfaces;
104  mutable BVH<std::shared_ptr<Surface<N>>, N> m_bvh;
105  mutable bool m_bvhInvalidated = true;
106 };
107 
110 
113 
115 using SurfaceSet2Ptr = std::shared_ptr<SurfaceSet2>;
116 
118 using SurfaceSet3Ptr = std::shared_ptr<SurfaceSet3>;
119 
123 template <size_t N>
124 class SurfaceSet<N>::Builder final
125  : public SurfaceBuilderBase<N, typename SurfaceSet<N>::Builder>
126 {
127  public:
129  Builder& WithSurfaces(
130  const ConstArrayView1<std::shared_ptr<Surface<N>>>& others);
131 
133  SurfaceSet Build() const;
134 
136  std::shared_ptr<SurfaceSet<N>> MakeShared() const;
137 
138  private:
140  using Base::m_isNormalFlipped;
141  using Base::m_transform;
142 
144 };
145 } // namespace CubbyFlow
146 
147 #endif
static Builder GetBuilder()
Returns builder for SurfaceSet.
void AddSurface(const std::shared_ptr< Surface< N >> &surface)
Adds a surface instance.
N-D surface set.
Definition: SurfaceSet.hpp:27
Class for N-D ray.
Definition: Ray.hpp:25
void UpdateQueryEngine() override
Updates internal spatial query engine.
std::shared_ptr< SurfaceSet3 > SurfaceSet3Ptr
Shared pointer for the SurfaceSet3 type.
Definition: SurfaceSet.hpp:118
SurfaceSet()=default
Constructs an empty surface set.
~SurfaceSet() override=default
Default virtual destructor.
Represents N-D rigid body transform.
Definition: Transform.hpp:82
const std::shared_ptr< Surface< N > > & SurfaceAt(size_t i) const
Returns the i-th surface.
Definition: Matrix.hpp:27
size_t NumberOfSurfaces() const
Returns the number of surfaces.
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
SurfaceSet & operator=(const SurfaceSet &other)
Copy assignment operator.
std::shared_ptr< SurfaceSet2 > SurfaceSet2Ptr
Shared pointer for the SurfaceSet2 type.
Definition: SurfaceSet.hpp:115
Generic N-dimensional array class interface.
Definition: Array.hpp:32
Front-end to create SurfaceSet objects step by step.
Definition: SurfaceSet.hpp:124
bool IsValidGeometry() const override
Returns true if the surface is a valid geometry.
bool IsBounded() const override
Returns true if bounding box can be defined.
Bounding Volume Hierarchy (BVH) in N-D.
Definition: BVH.hpp:30
Base class for N-D surface builder.
Definition: Surface.hpp:153