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