CustomImplicitSurface.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_CUSTOM_IMPLICIT_SURFACE_HPP
12 #define CUBBYFLOW_CUSTOM_IMPLICIT_SURFACE_HPP
13 
15 
16 namespace CubbyFlow
17 {
19 template <size_t N>
20 class CustomImplicitSurface final : public ImplicitSurface<N>
21 {
22  public:
23  class Builder;
24 
37  std::function<double(const Vector<double, N>&)> func,
39  double resolution = 1e-3, double rayMarchingResolution = 1e-6,
40  unsigned int maxNumOfIterations = 5,
41  const Transform<N>& _transform = Transform<N>{},
42  bool _isNormalFlipped = false);
43 
45  ~CustomImplicitSurface() override = default;
46 
48  CustomImplicitSurface(const CustomImplicitSurface& other) = default;
49 
51  CustomImplicitSurface(CustomImplicitSurface&& other) noexcept = default;
52 
55  default;
56 
59  default;
60 
62  static Builder GetBuilder();
63 
64  private:
65  [[nodiscard]] Vector<double, N> ClosestPointLocal(
66  const Vector<double, N>& otherPoint) const override;
67 
68  [[nodiscard]] bool IntersectsLocal(
69  const Ray<double, N>& ray) const override;
70 
71  [[nodiscard]] BoundingBox<double, N> BoundingBoxLocal() const override;
72 
73  [[nodiscard]] Vector<double, N> ClosestNormalLocal(
74  const Vector<double, N>& otherPoint) const override;
75 
76  [[nodiscard]] double SignedDistanceLocal(
77  const Vector<double, N>& otherPoint) const override;
78 
79  [[nodiscard]] SurfaceRayIntersection<N> ClosestIntersectionLocal(
80  const Ray<double, N>& ray) const override;
81 
82  [[nodiscard]] Vector<double, N> GradientLocal(
83  const Vector<double, N>& x) const;
84 
85  std::function<double(const Vector<double, N>&)> m_func;
86  BoundingBox<double, N> m_domain;
87  double m_resolution = 1e-3;
88  double m_rayMarchingResolution = 1e-6;
89  unsigned int m_maxNumOfIterations = 5;
90 };
91 
94 
97 
99 using CustomImplicitSurface2Ptr = std::shared_ptr<CustomImplicitSurface2>;
100 
102 using CustomImplicitSurface3Ptr = std::shared_ptr<CustomImplicitSurface3>;
103 
107 template <size_t N>
109  : public SurfaceBuilderBase<N, typename CustomImplicitSurface<N>::Builder>
110 {
111  public:
113  Builder& WithSignedDistanceFunction(
114  const std::function<double(const Vector<double, N>&)>& func);
115 
117  Builder& WithDomain(const BoundingBox<double, N>& domain);
118 
120  Builder& WithResolution(double resolution);
121 
124  Builder& WithRayMarchingResolution(double rayMarchingResolution);
125 
128  Builder& WithMaxNumberOfIterations(unsigned int numIter);
129 
131  CustomImplicitSurface<N> Build() const;
132 
134  std::shared_ptr<CustomImplicitSurface<N>> MakeShared() const;
135 
136  private:
137  using Base =
139  using Base::m_isNormalFlipped;
140  using Base::m_transform;
141 
142  std::function<double(const Vector<double, N>&)> m_func;
143  BoundingBox<double, N> m_domain;
144  double m_resolution = 1e-3;
145  double m_rayMarchingResolution = 1e-6;
146  unsigned int m_maxNumOfIterations = 5;
147 };
148 } // namespace CubbyFlow
149 
150 #endif
Abstract base class for N-D implicit surface.
Definition: ImplicitSurface.hpp:20
Class for N-D ray.
Definition: Ray.hpp:25
std::shared_ptr< CustomImplicitSurface3 > CustomImplicitSurface3Ptr
Shared pointer type for the CustomImplicitSurface3.
Definition: CustomImplicitSurface.hpp:102
static Builder GetBuilder()
Returns builder for CustomImplicitSurface.
Front-end to create CustomImplicitSurface objects step by step.
Definition: CustomImplicitSurface.hpp:108
Represents N-D rigid body transform.
Definition: Transform.hpp:82
Definition: Matrix.hpp:27
CustomImplicitSurface & operator=(const CustomImplicitSurface &other)=default
Default copy assignment operator.
Definition: pybind11Utils.hpp:20
Struct that represents ray-surface intersection point.
Definition: Surface.hpp:25
CustomImplicitSurface(std::function< double(const Vector< double, N > &)> func, const BoundingBox< double, N > &domain=BoundingBox< double, N >{}, double resolution=1e-3, double rayMarchingResolution=1e-6, unsigned int maxNumOfIterations=5, const Transform< N > &_transform=Transform< N >{}, bool _isNormalFlipped=false)
std::shared_ptr< CustomImplicitSurface2 > CustomImplicitSurface2Ptr
Shared pointer type for the CustomImplicitSurface2.
Definition: CustomImplicitSurface.hpp:99
Custom N-D implicit surface using arbitrary function.
Definition: CustomImplicitSurface.hpp:20
~CustomImplicitSurface() override=default
Default virtual destructor.
Base class for N-D surface builder.
Definition: Surface.hpp:153