ImplicitSurfaceSet2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: ImplicitSurfaceSet2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 2-D implicit surface set.
6 > Created Time: 2017/04/16
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_IMPLICIT_SURFACE_SET2_H
10 #define CUBBYFLOW_IMPLICIT_SURFACE_SET2_H
11 
12 #include <Core/Geometry/BVH2.h>
14 
15 #include <vector>
16 
17 namespace CubbyFlow
18 {
27  {
28  public:
29  class Builder;
30 
33 
36  const std::vector<ImplicitSurface2Ptr>& surfaces,
37  const Transform2& transform = Transform2(),
38  bool isNormalFlipped = false);
39 
42  const std::vector<Surface2Ptr>& surfaces,
43  const Transform2& transform = Transform2(),
44  bool isNormalFlipped = false);
45 
48 
50  void UpdateQueryEngine() override;
51 
53  size_t NumberOfSurfaces() const;
54 
56  const ImplicitSurface2Ptr& SurfaceAt(size_t i) const;
57 
59  void AddExplicitSurface(const Surface2Ptr& surface);
60 
62  void AddSurface(const ImplicitSurface2Ptr& surface);
63 
65  static Builder GetBuilder();
66 
67  private:
68  std::vector<ImplicitSurface2Ptr> m_surfaces;
69  mutable BVH2<ImplicitSurface2Ptr> m_bvh;
70  mutable bool m_bvhInvalidated = true;
71 
72  // Surface2 implementations
73  Vector2D ClosestPointLocal(const Vector2D& otherPoint) const override;
74 
75  BoundingBox2D BoundingBoxLocal() const override;
76 
77  double ClosestDistanceLocal(const Vector2D& otherPoint) const override;
78 
79  bool IntersectsLocal(const Ray2D& ray) const override;
80 
81  Vector2D ClosestNormalLocal(const Vector2D& otherPoint) const override;
82 
83  SurfaceRayIntersection2 ClosestIntersectionLocal(const Ray2D& ray) const override;
84 
85  // ImplicitSurface2 implementations
86  double SignedDistanceLocal(const Vector2D& otherPoint) const override;
87 
88  void InvalidateBVH() const;
89 
90  void BuildBVH() const;
91  };
92 
94  using ImplicitSurfaceSet2Ptr = std::shared_ptr<ImplicitSurfaceSet2>;
95 
99  class ImplicitSurfaceSet2::Builder final : public SurfaceBuilderBase2<ImplicitSurfaceSet2::Builder>
100  {
101  public:
103  Builder& WithSurfaces(const std::vector<ImplicitSurface2Ptr>& surfaces);
104 
106  Builder& WithExplicitSurfaces(const std::vector<Surface2Ptr>& surfaces);
107 
109  ImplicitSurfaceSet2 Build() const;
110 
113 
114  private:
115  bool m_isNormalFlipped = false;
116  std::vector<ImplicitSurface2Ptr> m_surfaces;
117  };
118 }
119 
120 #endif
std::shared_ptr< ImplicitSurfaceSet2 > ImplicitSurfaceSet2Ptr
Shared pointer type for the ImplicitSurfaceSet2.
Definition: ImplicitSurfaceSet2.h:94
void AddExplicitSurface(const Surface2Ptr &surface)
Adds an explicit surface instance.
void AddSurface(const ImplicitSurface2Ptr &surface)
Adds an implicit surface instance.
Base class for 2-D surface builder.
Definition: Surface2.h:106
Class for 2-D ray.
Definition: Ray2.h:23
Represents 2-D rigid body transform.
Definition: Transform2.h:21
Transform2 transform
Local-to-world transform.
Definition: Surface2.h:36
Structure that represents ray-surface intersection point.
Definition: Surface2.h:23
Builder & WithSurfaces(const std::vector< ImplicitSurface2Ptr > &surfaces)
Returns builder with surfaces.
ImplicitSurfaceSet2 Build() const
Builds ImplicitSurfaceSet2.
2-D axis-aligned bounding box class.
Definition: BoundingBox2.h:44
bool isNormalFlipped
Flips normal.
Definition: Surface2.h:39
Definition: pybind11Utils.h:24
Front-end to create ImplicitSurfaceSet2 objects step by step.
Definition: ImplicitSurfaceSet2.h:99
const ImplicitSurface2Ptr & SurfaceAt(size_t i) const
Returns the i-th implicit surface.
ImplicitSurfaceSet2Ptr MakeShared() const
Builds shared pointer of ImplicitSurfaceSet2 instance.
void UpdateQueryEngine() override
Updates internal spatial query engine.
size_t NumberOfSurfaces() const
Returns the number of implicit surfaces.
2-D implicit surface set.
Definition: ImplicitSurfaceSet2.h:26
std::shared_ptr< ImplicitSurface2 > ImplicitSurface2Ptr
Shared pointer type for the ImplicitSurface2.
Definition: ImplicitSurface2.h:43
Builder & WithExplicitSurfaces(const std::vector< Surface2Ptr > &surfaces)
Returns builder with explicit surfaces.
static Builder GetBuilder()
Returns builder fox ImplicitSurfaceSet2.
Abstract base class for 2-D implicit surface.
Definition: ImplicitSurface2.h:17
2-D vector class.
Definition: Vector2.h:26
ImplicitSurfaceSet2()
Constructs an empty implicit surface set.
std::shared_ptr< Surface2 > Surface2Ptr
Shared pointer for the Surface2 type.
Definition: Surface2.h:100