CustomImplicitSurface3.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: CustomImplicitSurface3.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Custom 3-D implicit surface using arbitrary function.
6 > Created Time: 2017/09/08
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_CUSTOM_IMPLICIT_SURFACE3_H
10 #define CUBBYFLOW_CUSTOM_IMPLICIT_SURFACE3_H
11 
13 
14 #include <functional>
15 
16 namespace CubbyFlow
17 {
20  {
21  public:
22  class Builder;
23 
36  const std::function<double(const Vector3D&)>& func,
37  const BoundingBox3D& domain = BoundingBox3D(),
38  double resolution = 1e-3,
39  double rayMarchingResolution = 1e-6,
40  unsigned int maxNumberOfIterations = 5,
41  const Transform3& transform = Transform3(),
42  bool isNormalFlipped = false);
43 
45  virtual ~CustomImplicitSurface3();
46 
48  static Builder GetBuilder();
49 
50  private:
51  std::function<double(const Vector3D&)> m_func;
52  BoundingBox3D m_domain;
53  double m_resolution = 1e-3;
54  double m_rayMarchingResolution = 1e-6;
55  unsigned int m_maxNumberOfIterations = 5;
56 
57  Vector3D ClosestPointLocal(const Vector3D& otherPoint) const override;
58 
59  bool IntersectsLocal(const Ray3D& ray) const override;
60 
61  BoundingBox3D BoundingBoxLocal() const override;
62 
63  Vector3D ClosestNormalLocal(const Vector3D& otherPoint) const override;
64 
65  double SignedDistanceLocal(const Vector3D& otherPoint) const override;
66 
67  SurfaceRayIntersection3 ClosestIntersectionLocal(const Ray3D& ray) const override;
68 
69  Vector3D GradientLocal(const Vector3D& x) const;
70  };
71 
73  using CustomImplicitSurface3Ptr = std::shared_ptr<CustomImplicitSurface3>;
74 
78  class CustomImplicitSurface3::Builder final : public SurfaceBuilderBase3<CustomImplicitSurface3::Builder>
79  {
80  public:
82  Builder& WithSignedDistanceFunction(const std::function<double(const Vector3D&)>& func);
83 
85  Builder& WithDomain(const BoundingBox3D& domain);
86 
88  Builder& WithResolution(double resolution);
89 
92  Builder& WithRayMarchingResolution(double rayMarchingResolution);
93 
95  Builder& WithMaxNumberOfIterations(unsigned int numIter);
96 
99 
102 
103  private:
104  std::function<double(const Vector3D&)> m_func;
105  BoundingBox3D m_domain;
106  double m_resolution = 1e-3;
107  double m_rayMarchingResolution = 1e-6;
108  unsigned int m_maxNumberOfIterations = 5;
109  };
110 }
111 
112 #endif
3-D vector class.
Definition: Vector3.h:26
Builder & WithDomain(const BoundingBox3D &domain)
Returns builder with domain.
std::shared_ptr< CustomImplicitSurface3 > CustomImplicitSurface3Ptr
Shared pointer type for the CustomImplicitSurface3.
Definition: CustomImplicitSurface3.h:73
virtual ~CustomImplicitSurface3()
Destructor.
Custom 3-D implicit surface using arbitrary function.
Definition: CustomImplicitSurface3.h:19
CustomImplicitSurface3 Build() const
Builds CustomImplicitSurface3.
Builder & WithRayMarchingResolution(double rayMarchingResolution)
Structure that represents ray-surface intersection point.
Definition: Surface3.h:23
BoundingBox3< double > BoundingBox3D
Double-type 3-D BoundingBox.
Definition: BoundingBox3.h:129
CustomImplicitSurface3(const std::function< double(const Vector3D &)> &func, const BoundingBox3D &domain=BoundingBox3D(), double resolution=1e-3, double rayMarchingResolution=1e-6, unsigned int maxNumberOfIterations=5, const Transform3 &transform=Transform3(), bool isNormalFlipped=false)
Builder & WithSignedDistanceFunction(const std::function< double(const Vector3D &)> &func)
Returns builder with custom signed-distance function.
Base class for 3-D surface builder.
Definition: Surface3.h:106
Definition: pybind11Utils.h:24
Transform3 transform
Local-to-world transform.
Definition: Surface3.h:36
3-D axis-aligned bounding box class.
Definition: BoundingBox3.h:44
Builder & WithResolution(double resolution)
Returns builder with finite differencing resolution.
Builder & WithMaxNumberOfIterations(unsigned int numIter)
Returns builder with number of iterations for closest point/normal searches.
static Builder GetBuilder()
Returns builder for CustomImplicitSurface3.
Represents 3-D rigid body transform.
Definition: Transform3.h:22
bool isNormalFlipped
Flips normal when calling Surface3::closestNormal(...).
Definition: Surface3.h:39
Abstract base class for 3-D implicit surface.
Definition: ImplicitSurface3.h:17
CustomImplicitSurface3Ptr MakeShared() const
Builds shared pointer of CustomImplicitSurface3 instance.
Class for 3-D ray.
Definition: Ray3.h:23
Front-end to create CustomImplicitSurface3 objects step by step.
Definition: CustomImplicitSurface3.h:78