ImplicitSurfaceSet3.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: ImplicitSurfaceSet3.h
3 > Project Name: CubbyFlow
4 > Author: Dongmin Kim
5 > Purpose: 3-D implicit surface set.
6 > Created Time: 2017/04/18
7 > Copyright (c) 2018, Dongmin Kim
8 *************************************************************************/
9 #ifndef CUBBYFLOW_IMPLICIT_SURFACE_SET3_H
10 #define CUBBYFLOW_IMPLICIT_SURFACE_SET3_H
11 
12 #include <Core/Geometry/BVH3.h>
14 
15 #include <vector>
16 
17 namespace CubbyFlow
18 {
27  {
28  public:
29  class Builder;
30 
33 
36  const std::vector<ImplicitSurface3Ptr>& surfaces,
37  const Transform3& transform = Transform3(),
38  bool isNormalFlipped = false);
39 
42  const std::vector<Surface3Ptr>& surfaces,
43  const Transform3& transform = Transform3(),
44  bool isNormalFlipped = false);
45 
48 
50  void UpdateQueryEngine() override;
51 
53  size_t NumberOfSurfaces() const;
54 
56  const ImplicitSurface3Ptr& SurfaceAt(size_t i) const;
57 
59  void AddExplicitSurface(const Surface3Ptr& surface);
60 
62  void AddSurface(const ImplicitSurface3Ptr& surface);
63 
65  static Builder GetBuilder();
66 
67  private:
68  std::vector<ImplicitSurface3Ptr> m_surfaces;
69  mutable BVH3<ImplicitSurface3Ptr> m_bvh;
70  mutable bool m_bvhInvalidated = true;
71 
72  // Surface3 implementations.
73  Vector3D ClosestPointLocal(const Vector3D& otherPoint) const override;
74 
75  BoundingBox3D BoundingBoxLocal() const override;
76 
77  double ClosestDistanceLocal(const Vector3D& otherPoint) const override;
78 
79  bool IntersectsLocal(const Ray3D& ray) const override;
80 
81  Vector3D ClosestNormalLocal(const Vector3D& otherPoint) const override;
82 
83  SurfaceRayIntersection3 ClosestIntersectionLocal(const Ray3D& ray) const override;
84 
85  // ImplicitSurface3 implementations.
86  double SignedDistanceLocal(const Vector3D& otherPoint) const override;
87 
88  void InvalidateBVH() const;
89 
90  void BuildBVH() const;
91  };
92 
94  using ImplicitSurfaceSet3Ptr = std::shared_ptr<ImplicitSurfaceSet3>;
95 
99  class ImplicitSurfaceSet3::Builder final : public SurfaceBuilderBase3<ImplicitSurfaceSet3::Builder>
100  {
101  public:
103  Builder& WithSurfaces(const std::vector<ImplicitSurface3Ptr>& surfaces);
104 
106  Builder& WithExplicitSurfaces(const std::vector<Surface3Ptr>& surfaces);
107 
109  ImplicitSurfaceSet3 Build() const;
110 
113 
114  private:
115  bool m_isNormalFlipped = false;
116  std::vector<ImplicitSurface3Ptr> m_surfaces;
117  };
118 }
119 
120 #endif
size_t NumberOfSurfaces() const
Returns the number of implicit surfaces.
3-D vector class.
Definition: Vector3.h:26
ImplicitSurfaceSet3()
Constructs an empty implicit surface set.
Front-end to create ImplicitSurfaceSet3 objects step by step.
Definition: ImplicitSurfaceSet3.h:99
Builder & WithExplicitSurfaces(const std::vector< Surface3Ptr > &surfaces)
Returns builder with explicit surfaces.
std::shared_ptr< ImplicitSurface3 > ImplicitSurface3Ptr
Shared pointer type for the ImplicitSurface3.
Definition: ImplicitSurface3.h:43
ImplicitSurfaceSet3Ptr MakeShared() const
Builds shared pointer of ImplicitSurfaceSet3 instance.
Structure that represents ray-surface intersection point.
Definition: Surface3.h:23
3-D implicit surface set.
Definition: ImplicitSurfaceSet3.h:26
static Builder GetBuilder()
Returns builder for ImplicitSurfaceSet3.
Base class for 3-D surface builder.
Definition: Surface3.h:106
Builder & WithSurfaces(const std::vector< ImplicitSurface3Ptr > &surfaces)
Returns builder with surfaces.
Definition: pybind11Utils.h:24
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
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
const ImplicitSurface3Ptr & SurfaceAt(size_t i) const
Returns the i-th implicit surface.
void AddSurface(const ImplicitSurface3Ptr &surface)
Adds an implicit surface instance.
ImplicitSurfaceSet3 Build() const
Builds ImplicitSurfaceSet3.
void AddExplicitSurface(const Surface3Ptr &surface)
Adds an explicit surface instance.
Class for 3-D ray.
Definition: Ray3.h:23
void UpdateQueryEngine() override
Updates internal spatial query engine.
std::shared_ptr< ImplicitSurfaceSet3 > ImplicitSurfaceSet3Ptr
Shared pointer type for the ImplicitSurfaceSet3.
Definition: ImplicitSurfaceSet3.h:94