Jet  v1.3.3
surface_set3.h
Go to the documentation of this file.
1 // Copyright (c) 2018 Doyub Kim
2 //
3 // I am making my contributions/submissions to this project solely in my
4 // personal capacity and am not conveying any rights to any intellectual
5 // property of any third parties.
6 
7 #ifndef INCLUDE_JET_SURFACE_SET3_H_
8 #define INCLUDE_JET_SURFACE_SET3_H_
9 
10 #include <jet/bvh3.h>
11 #include <jet/surface3.h>
12 
13 #include <vector>
14 
15 namespace jet {
16 
24 class SurfaceSet3 final : public Surface3 {
25  public:
26  class Builder;
27 
30 
32  explicit SurfaceSet3(const std::vector<Surface3Ptr>& others,
33  const Transform3& transform = Transform3(),
34  bool isNormalFlipped = false);
35 
37  SurfaceSet3(const SurfaceSet3& other);
38 
40  void updateQueryEngine() override;
41 
43  bool isBounded() const override;
44 
46  bool isValidGeometry() const override;
47 
49  size_t numberOfSurfaces() const;
50 
52  const Surface3Ptr& surfaceAt(size_t i) const;
53 
55  void addSurface(const Surface3Ptr& surface);
56 
58  static Builder builder();
59 
60  private:
61  std::vector<Surface3Ptr> _surfaces;
62  std::vector<Surface3Ptr> _unboundedSurfaces;
63  mutable Bvh3<Surface3Ptr> _bvh;
64  mutable bool _bvhInvalidated = true;
65 
66  // Surface3 implementations
67 
68  Vector3D closestPointLocal(const Vector3D& otherPoint) const override;
69 
70  BoundingBox3D boundingBoxLocal() const override;
71 
72  double closestDistanceLocal(const Vector3D& otherPoint) const override;
73 
74  bool intersectsLocal(const Ray3D& ray) const override;
75 
76  Vector3D closestNormalLocal(const Vector3D& otherPoint) const override;
77 
78  SurfaceRayIntersection3 closestIntersectionLocal(
79  const Ray3D& ray) const override;
80 
81  bool isInsideLocal(const Vector3D& otherPoint) const override;
82 
83  void invalidateBvh();
84 
85  void buildBvh() const;
86 };
87 
89 typedef std::shared_ptr<SurfaceSet3> SurfaceSet3Ptr;
90 
95  : public SurfaceBuilderBase3<SurfaceSet3::Builder> {
96  public:
98  Builder& withSurfaces(const std::vector<Surface3Ptr>& others);
99 
102 
105 
106  private:
107  std::vector<Surface3Ptr> _surfaces;
108 };
109 
110 } // namespace jet
111 
112 #endif // INCLUDE_JET_SURFACE_SET3_H_
jet::SurfaceSet3::surfaceAt
const Surface3Ptr & surfaceAt(size_t i) const
Returns the i-th surface.
jet::SurfaceSet3::Builder::build
SurfaceSet3 build() const
Builds SurfaceSet3.
jet::SurfaceSet3::SurfaceSet3
SurfaceSet3()
Constructs an empty surface set.
jet::SurfaceSet3::isValidGeometry
bool isValidGeometry() const override
Returns true if the surface is a valid geometry.
surface3.h
jet::BoundingBox< T, 3 >
3-D axis-aligned bounding box class.
Definition: bounding_box3.h:41
jet::SurfaceBuilderBase3
Base class for 3-D surface builder.
Definition: surface3.h:115
jet::SurfaceSet3
3-D surface set.
Definition: surface_set3.h:24
jet::Surface3::isNormalFlipped
bool isNormalFlipped
Flips normal when calling Surface3::closestNormal(...).
Definition: surface3.h:33
jet::Surface3Ptr
std::shared_ptr< Surface3 > Surface3Ptr
Shared pointer for the Surface3 type.
Definition: surface3.h:109
jet::SurfaceSet3::Builder
Front-end to create SurfaceSet3 objects step by step.
Definition: surface_set3.h:95
jet
Definition: advection_solver2.h:18
jet::SurfaceSet3::builder
static Builder builder()
Returns builder for SurfaceSet3.
jet::SurfaceSet3::SurfaceSet3
SurfaceSet3(const SurfaceSet3 &other)
Copy constructor.
jet::SurfaceSet3::Builder::withSurfaces
Builder & withSurfaces(const std::vector< Surface3Ptr > &others)
Returns builder with other surfaces.
jet::SurfaceSet3::addSurface
void addSurface(const Surface3Ptr &surface)
Adds a surface instance.
jet::SurfaceSet3::isBounded
bool isBounded() const override
Returns true if bounding box can be defined.
jet::Bvh3< Surface3Ptr >
bvh3.h
jet::Surface3::transform
Transform3 transform
Local-to-world transform.
Definition: surface3.h:30
jet::Ray< T, 3 >
Class for 2-D ray.
Definition: ray3.h:21
jet::SurfaceSet3::updateQueryEngine
void updateQueryEngine() override
Updates internal spatial query engine.
jet::SurfaceRayIntersection3
Struct that represents ray-surface intersection point.
Definition: surface3.h:19
jet::SurfaceSet3::SurfaceSet3
SurfaceSet3(const std::vector< Surface3Ptr > &others, const Transform3 &transform=Transform3(), bool isNormalFlipped=false)
Constructs with a list of other surfaces.
jet::Vector< T, 3 >
3-D vector class.
Definition: vector3.h:25
jet::Transform3
Represents 3-D rigid body transform.
Definition: transform3.h:20
jet::SurfaceSet3::Builder::makeShared
SurfaceSet3Ptr makeShared() const
Builds shared pointer of SurfaceSet3 instance.
jet::Surface3
Abstract base class for 3-D surface.
Definition: surface3.h:27
jet::SurfaceSet3::numberOfSurfaces
size_t numberOfSurfaces() const
Returns the number of surfaces.
jet::SurfaceSet3Ptr
std::shared_ptr< SurfaceSet3 > SurfaceSet3Ptr
Shared pointer for the SurfaceSet3 type.
Definition: surface_set3.h:89