SurfaceSet2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: SurfaceSet2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 2-D surface set.
6 > Created Time: 2017/04/04
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_SURFACE_SET2_H
10 #define CUBBYFLOW_SURFACE_SET2_H
11 
12 #include <Core/Geometry/BVH2.h>
13 #include <Core/Surface/Surface2.h>
14 
15 #include <vector>
16 
17 namespace CubbyFlow
18 {
26  class SurfaceSet2 final : public Surface2
27  {
28  public:
29  class Builder;
30 
32  SurfaceSet2();
33 
35  explicit SurfaceSet2(
36  const std::vector<Surface2Ptr>& others,
37  const Transform2& transform = Transform2(),
38  bool isNormalFlipped = false);
39 
41  SurfaceSet2(const SurfaceSet2& other);
42 
44  void UpdateQueryEngine() override;
45 
47  size_t NumberOfSurfaces() const;
48 
50  const Surface2Ptr& SurfaceAt(size_t i) const;
51 
53  void AddSurface(const Surface2Ptr& surface);
54 
56  static Builder GetBuilder();
57 
58  private:
59  std::vector<Surface2Ptr> m_surfaces;
60  mutable BVH2<Surface2Ptr> m_bvh;
61  mutable bool m_bvhInvalidated = true;
62 
63  // Surface2 implementations
64  Vector2D ClosestPointLocal(const Vector2D& otherPoint) const override;
65 
66  BoundingBox2D BoundingBoxLocal() const override;
67 
68  double ClosestDistanceLocal(const Vector2D& otherPoint) const override;
69 
70  bool IntersectsLocal(const Ray2D& ray) const override;
71 
72  Vector2D ClosestNormalLocal(const Vector2D& otherPoint) const override;
73 
74  SurfaceRayIntersection2 ClosestIntersectionLocal(const Ray2D& ray) const override;
75 
76  void InvalidateBVH() const;
77 
78  void BuildBVH() const;
79  };
80 
82  using SurfaceSet2Ptr = std::shared_ptr<SurfaceSet2>;
83 
87  class SurfaceSet2::Builder final : public SurfaceBuilderBase2<SurfaceSet2>
88  {
89  public:
91  Builder& WithSurfaces(const std::vector<Surface2Ptr>& others);
92 
94  SurfaceSet2 Build() const;
95 
97  SurfaceSet2Ptr MakeShared() const;
98 
99  private:
100  std::vector<Surface2Ptr> m_surfaces;
101  };
102 }
103 
104 #endif
void AddSurface(const Surface2Ptr &surface)
Adds a surface instance.
2-D surface set.
Definition: SurfaceSet2.h:26
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
SurfaceSet2()
Constructs an empty surface set.
Abstract base class for 2-D surface.
Definition: Surface2.h:32
Front-end to create SurfaceSet2 objects step by step.
Definition: SurfaceSet2.h:87
const Surface2Ptr & SurfaceAt(size_t i) const
Returns the i-th surface.
2-D axis-aligned bounding box class.
Definition: BoundingBox2.h:44
bool isNormalFlipped
Flips normal.
Definition: Surface2.h:39
Definition: pybind11Utils.h:24
void UpdateQueryEngine() override
Updates internal spatial query engine.
Builder & WithSurfaces(const std::vector< Surface2Ptr > &others)
Returns builder with other surfaces.
std::shared_ptr< SurfaceSet2 > SurfaceSet2Ptr
Shared pointer for the SurfaceSet2 type.
Definition: SurfaceSet2.h:82
size_t NumberOfSurfaces() const
Returns the number of surfaces.
2-D vector class.
Definition: Vector2.h:26
static Builder GetBuilder()
Returns builder for SurfaceSet2.
SurfaceSet2 Build() const
Builds SurfaceSet2.
std::shared_ptr< Surface2 > Surface2Ptr
Shared pointer for the Surface2 type.
Definition: Surface2.h:100
SurfaceSet2Ptr MakeShared() const
Builds shared pointer of SurfaceSet2 instance.