CustomImplicitSurface2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: CustomImplicitSurface2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Custom 2-D implicit surface using arbitrary function.
6 > Created Time: 2017/09/07
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_CUSTOM_IMPLICIT_SURFACE2_H
10 #define CUBBYFLOW_CUSTOM_IMPLICIT_SURFACE2_H
11 
13 
14 #include <functional>
15 
16 namespace CubbyFlow
17 {
20  {
21  public:
22  class Builder;
23 
36  const std::function<double(const Vector2D&)>& func,
37  const BoundingBox2D& domain = BoundingBox2D(),
38  double resolution = 1e-3,
39  double rayMarchingResolution = 1e-6,
40  unsigned int maxNumberOfIterations = 5,
41  const Transform2& transform = Transform2(),
42  bool isNormalFlipped = false);
43 
45  virtual ~CustomImplicitSurface2();
46 
48  static Builder GetBuilder();
49 
50  private:
51  std::function<double(const Vector2D&)> m_func;
52  BoundingBox2D m_domain;
53  double m_resolution = 1e-3;
54  double m_rayMarchingResolution = 1e-6;
55  unsigned int m_maxNumberOfIterations = 5;
56 
57  Vector2D ClosestPointLocal(const Vector2D& otherPoint) const override;
58 
59  bool IntersectsLocal(const Ray2D& ray) const override;
60 
61  BoundingBox2D BoundingBoxLocal() const override;
62 
63  Vector2D ClosestNormalLocal(const Vector2D& otherPoint) const override;
64 
65  double SignedDistanceLocal(const Vector2D& otherPoint) const override;
66 
67  SurfaceRayIntersection2 ClosestIntersectionLocal(const Ray2D& ray) const override;
68 
69  Vector2D GradientLocal(const Vector2D& x) const;
70  };
71 
73  using CustomImplicitSurface2Ptr = std::shared_ptr<CustomImplicitSurface2>;
74 
78  class CustomImplicitSurface2::Builder final : public SurfaceBuilderBase2<CustomImplicitSurface2::Builder>
79  {
80  public:
82  Builder& WithSignedDistanceFunction(const std::function<double(const Vector2D&)>& func);
83 
85  Builder& WithDomain(const BoundingBox2D& 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 Vector2D&)> m_func;
105  BoundingBox2D 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
CustomImplicitSurface2 Build() const
Builds CustomImplicitSurface2.
Base class for 2-D surface builder.
Definition: Surface2.h:106
Class for 2-D ray.
Definition: Ray2.h:23
Front-end to create CustomImplicitSurface2 objects step by step.
Definition: CustomImplicitSurface2.h:78
Represents 2-D rigid body transform.
Definition: Transform2.h:21
BoundingBox2< double > BoundingBox2D
Double-type 2-D BoundingBox.
Definition: BoundingBox2.h:126
Transform2 transform
Local-to-world transform.
Definition: Surface2.h:36
Structure that represents ray-surface intersection point.
Definition: Surface2.h:23
Custom 2-D implicit surface using arbitrary function.
Definition: CustomImplicitSurface2.h:19
Builder & WithSignedDistanceFunction(const std::function< double(const Vector2D &)> &func)
Returns builder with custom signed-distance function.
CustomImplicitSurface2Ptr MakeShared() const
Builds shared pointer of CustomImplicitSurface2 instance.
2-D axis-aligned bounding box class.
Definition: BoundingBox2.h:44
bool isNormalFlipped
Flips normal.
Definition: Surface2.h:39
Definition: pybind11Utils.h:24
Builder & WithDomain(const BoundingBox2D &domain)
Returns builder with domain.
Builder & WithRayMarchingResolution(double rayMarchingResolution)
static Builder GetBuilder()
Returns builder for CustomImplicitSurface2.
virtual ~CustomImplicitSurface2()
Destructor.
Abstract base class for 2-D implicit surface.
Definition: ImplicitSurface2.h:17
CustomImplicitSurface2(const std::function< double(const Vector2D &)> &func, const BoundingBox2D &domain=BoundingBox2D(), double resolution=1e-3, double rayMarchingResolution=1e-6, unsigned int maxNumberOfIterations=5, const Transform2 &transform=Transform2(), bool isNormalFlipped=false)
std::shared_ptr< CustomImplicitSurface2 > CustomImplicitSurface2Ptr
Shared pointer type for the CustomImplicitSurface2.
Definition: CustomImplicitSurface2.h:73
2-D vector class.
Definition: Vector2.h:26
Builder & WithMaxNumberOfIterations(unsigned int numIter)
Returns builder with number of iterations for closest point/normal searches.
Builder & WithResolution(double resolution)
Returns builder with finite differencing resolution.