Loading...
Searching...
No Matches
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
17namespace CubbyFlow
18{
26template <size_t N>
27class 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
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
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
115using SurfaceSet2Ptr = std::shared_ptr<SurfaceSet2>;
116
118using SurfaceSet3Ptr = std::shared_ptr<SurfaceSet3>;
119
123template <size_t N>
124class SurfaceSet<N>::Builder final
125 : public SurfaceBuilderBase<N, typename SurfaceSet<N>::Builder>
126{
127 public:
130 const ConstArrayView1<std::shared_ptr<Surface<N>>>& others);
131
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
Definition Array.hpp:36
Generic N-dimensional array class interface.
Definition ArrayView.hpp:26
Bounding Volume Hierarchy (BVH) in N-D.
Definition BVH.hpp:32
N-D axis-aligned bounding box class.
Definition BoundingBox.hpp:47
Definition Matrix.hpp:30
Class for N-D ray.
Definition Ray.hpp:26
Base class for N-D surface builder.
Definition Surface.hpp:154
Abstract base class for N-D surface.
Definition Surface.hpp:39
Front-end to create SurfaceSet objects step by step.
Definition SurfaceSet.hpp:126
std::shared_ptr< SurfaceSet< N > > MakeShared() const
Builds shared pointer of SurfaceSet instance.
Builder & WithSurfaces(const ConstArrayView1< std::shared_ptr< Surface< N > > > &others)
Returns builder with other surfaces.
SurfaceSet Build() const
Builds SurfaceSet.
N-D surface set.
Definition SurfaceSet.hpp:28
size_t NumberOfSurfaces() const
Returns the number of surfaces.
bool IsValidGeometry() const override
Returns true if the surface is a valid geometry.
static Builder GetBuilder()
Returns builder for SurfaceSet.
SurfaceSet(SurfaceSet &&other) noexcept
Move constructor.
SurfaceSet & operator=(const SurfaceSet &other)
Copy assignment operator.
~SurfaceSet() override=default
Default virtual destructor.
SurfaceSet(const ConstArrayView1< std::shared_ptr< Surface< N > > > &others, const Transform< N > &_transform=Transform< N >{}, bool _isNormalFlipped=false)
Constructs with a list of other surfaces.
void AddSurface(const std::shared_ptr< Surface< N > > &surface)
Adds a surface instance.
SurfaceSet(const SurfaceSet &other)
Copy constructor.
bool IsBounded() const override
Returns true if bounding box can be defined.
SurfaceSet & operator=(SurfaceSet &&other) noexcept
Move assignment operator.
const std::shared_ptr< Surface< N > > & SurfaceAt(size_t i) const
Returns the i-th surface.
void UpdateQueryEngine() override
Updates internal spatial query engine.
SurfaceSet()=default
Constructs an empty surface set.
Represents N-D rigid body transform.
Definition Transform.hpp:83
Definition pybind11Utils.hpp:21
std::shared_ptr< SurfaceSet2 > SurfaceSet2Ptr
Shared pointer for the SurfaceSet2 type.
Definition SurfaceSet.hpp:115
std::shared_ptr< SurfaceSet3 > SurfaceSet3Ptr
Shared pointer for the SurfaceSet3 type.
Definition SurfaceSet.hpp:118
Struct that represents ray-surface intersection point.
Definition Surface.hpp:26