SurfaceToImplicit.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_TO_IMPLICIT_HPP
12 #define CUBBYFLOW_SURFACE_TO_IMPLICIT_HPP
13 
15 
16 #include <memory>
17 
18 namespace CubbyFlow
19 {
29 template <size_t N>
30 class SurfaceToImplicit final : public ImplicitSurface<N>
31 {
32  public:
33  class Builder;
34 
37 
39  SurfaceToImplicit(std::shared_ptr<Surface<N>> surface,
40  const Transform<N>& _transform = Transform<N>{},
41  bool _isNormalFlipped = false);
42 
44  ~SurfaceToImplicit() override = default;
45 
48 
50  SurfaceToImplicit(SurfaceToImplicit&& other) noexcept;
51 
54 
57 
59  void UpdateQueryEngine() override;
60 
62  [[nodiscard]] bool IsBounded() const override;
63 
65  [[nodiscard]] bool IsValidGeometry() const override;
66 
68  [[nodiscard]] std::shared_ptr<Surface<N>> GetSurface() const;
69 
71  static Builder GetBuilder();
72 
73  protected:
75  const Vector<double, N>& otherPoint) const override;
76 
77  [[nodiscard]] double ClosestDistanceLocal(
78  const Vector<double, N>& otherPoint) const override;
79 
80  [[nodiscard]] bool IntersectsLocal(
81  const Ray<double, N>& ray) const override;
82 
83  [[nodiscard]] BoundingBox<double, N> BoundingBoxLocal() const override;
84 
86  const Vector<double, N>& otherPoint) const override;
87 
88  [[nodiscard]] double SignedDistanceLocal(
89  const Vector<double, N>& otherPoint) const override;
90 
92  const Ray<double, N>& ray) const override;
93 
94  private:
95  std::shared_ptr<Surface<N>> m_surface;
96 };
97 
100 
103 
105 using SurfaceToImplicit2Ptr = std::shared_ptr<SurfaceToImplicit2>;
106 
108 using SurfaceToImplicit3Ptr = std::shared_ptr<SurfaceToImplicit3>;
109 
113 template <size_t N>
114 class SurfaceToImplicit<N>::Builder final
115  : public SurfaceBuilderBase<N, typename SurfaceToImplicit<N>::Builder>
116 {
117  public:
119  Builder& WithSurface(const std::shared_ptr<Surface<N>>& surface);
120 
122  SurfaceToImplicit Build() const;
123 
125  std::shared_ptr<SurfaceToImplicit> MakeShared() const;
126 
127  private:
129  using Base::m_isNormalFlipped;
130  using Base::m_transform;
131 
132  std::shared_ptr<Surface<N>> m_surface;
133 };
134 } // namespace CubbyFlow
135 
136 #endif
bool IsValidGeometry() const override
Returns true if the surface is a valid geometry.
Abstract base class for N-D implicit surface.
Definition: ImplicitSurface.hpp:20
bool IsBounded() const override
Returns true if bounding box can be defined.
Front-end to create SurfaceToImplicit objects step by step.
Definition: SurfaceToImplicit.hpp:114
Class for N-D ray.
Definition: Ray.hpp:25
std::shared_ptr< Surface< N > > GetSurface() const
Returns the raw surface instance.
SurfaceToImplicit & operator=(const SurfaceToImplicit &other)
Copy assignment operator.
bool IntersectsLocal(const Ray< double, N > &ray) const override
double SignedDistanceLocal(const Vector< double, N > &otherPoint) const override
Vector< double, N > ClosestNormalLocal(const Vector< double, N > &otherPoint) const override
SurfaceRayIntersection< N > ClosestIntersectionLocal(const Ray< double, N > &ray) const override
Returns the closest intersection point for given ray in local frame.
Represents N-D rigid body transform.
Definition: Transform.hpp:82
Definition: Matrix.hpp:27
Definition: pybind11Utils.hpp:20
std::shared_ptr< SurfaceToImplicit3 > SurfaceToImplicit3Ptr
Shared pointer for the SurfaceToImplicit3 type.
Definition: SurfaceToImplicit.hpp:108
Abstract base class for N-D surface.
Definition: Surface.hpp:38
~SurfaceToImplicit() override=default
Default virtual destructor.
Struct that represents ray-surface intersection point.
Definition: Surface.hpp:25
Vector< double, N > ClosestPointLocal(const Vector< double, N > &otherPoint) const override
double ClosestDistanceLocal(const Vector< double, N > &otherPoint) const override
static Builder GetBuilder()
Returns builder fox SurfaceToImplicit.
N-D implicit surface wrapper for generic Surface instance.
Definition: SurfaceToImplicit.hpp:30
BoundingBox< double, N > BoundingBoxLocal() const override
Returns the bounding box of this surface object in local frame.
std::shared_ptr< SurfaceToImplicit2 > SurfaceToImplicit2Ptr
Shared pointer for the SurfaceToImplicit2 type.
Definition: SurfaceToImplicit.hpp:105
SurfaceToImplicit(std::shared_ptr< Surface< N >> surface, const Transform< N > &_transform=Transform< N >{}, bool _isNormalFlipped=false)
Constructs an instance with generic Surface2 instance.
Base class for N-D surface builder.
Definition: Surface.hpp:153
void UpdateQueryEngine() override
Updates internal spatial query engine.