Jet  v1.3.3
surface_set2.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_SET2_H_
8 #define INCLUDE_JET_SURFACE_SET2_H_
9 
10 #include <jet/bvh2.h>
11 #include <jet/surface2.h>
12 
13 #include <vector>
14 
15 namespace jet {
16 
24 class SurfaceSet2 final : public Surface2 {
25  public:
26  class Builder;
27 
30 
32  explicit SurfaceSet2(const std::vector<Surface2Ptr>& others,
33  const Transform2& transform = Transform2(),
34  bool isNormalFlipped = false);
35 
37  SurfaceSet2(const SurfaceSet2& 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 Surface2Ptr& surfaceAt(size_t i) const;
53 
55  void addSurface(const Surface2Ptr& surface);
56 
58  static Builder builder();
59 
60  private:
61  std::vector<Surface2Ptr> _surfaces;
62  std::vector<Surface2Ptr> _unboundedSurfaces;
63  mutable Bvh2<Surface2Ptr> _bvh;
64  mutable bool _bvhInvalidated = true;
65 
66  // Surface2 implementations
67 
68  Vector2D closestPointLocal(const Vector2D& otherPoint) const override;
69 
70  BoundingBox2D boundingBoxLocal() const override;
71 
72  double closestDistanceLocal(const Vector2D& otherPoint) const override;
73 
74  bool intersectsLocal(const Ray2D& ray) const override;
75 
76  Vector2D closestNormalLocal(const Vector2D& otherPoint) const override;
77 
78  SurfaceRayIntersection2 closestIntersectionLocal(
79  const Ray2D& ray) const override;
80 
81  bool isInsideLocal(const Vector2D& otherPoint) const override;
82 
83  void invalidateBvh();
84 
85  void buildBvh() const;
86 };
87 
89 typedef std::shared_ptr<SurfaceSet2> SurfaceSet2Ptr;
90 
95  : public SurfaceBuilderBase2<SurfaceSet2::Builder> {
96  public:
98  Builder& withSurfaces(const std::vector<Surface2Ptr>& others);
99 
102 
105 
106  private:
107  std::vector<Surface2Ptr> _surfaces;
108 };
109 
110 } // namespace jet
111 
112 #endif // INCLUDE_JET_SURFACE_SET2_H_
surface2.h
jet::SurfaceRayIntersection2
Struct that represents ray-surface intersection point.
Definition: surface2.h:19
jet::Surface2::isNormalFlipped
bool isNormalFlipped
Flips normal.
Definition: surface2.h:33
jet::SurfaceSet2::isValidGeometry
bool isValidGeometry() const override
Returns true if the surface is a valid geometry.
jet::Transform2
Represents 2-D rigid body transform.
Definition: transform2.h:19
jet::SurfaceSet2::SurfaceSet2
SurfaceSet2()
Constructs an empty surface set.
jet::Ray< T, 2 >
Class for 2-D ray.
Definition: ray2.h:21
jet::SurfaceSet2::Builder::withSurfaces
Builder & withSurfaces(const std::vector< Surface2Ptr > &others)
Returns builder with other surfaces.
jet::SurfaceSet2Ptr
std::shared_ptr< SurfaceSet2 > SurfaceSet2Ptr
Shared pointer for the SurfaceSet2 type.
Definition: surface_set2.h:89
jet
Definition: advection_solver2.h:18
jet::Surface2::transform
Transform2 transform
Local-to-world transform.
Definition: surface2.h:30
jet::SurfaceSet2::Builder::build
SurfaceSet2 build() const
Builds SurfaceSet2.
jet::Surface2Ptr
std::shared_ptr< Surface2 > Surface2Ptr
Shared pointer for the Surface2 type.
Definition: surface2.h:109
bvh2.h
jet::Vector< T, 2 >
2-D vector class.
Definition: vector2.h:24
jet::SurfaceBuilderBase2
Base class for 2-D surface builder.
Definition: surface2.h:115
jet::SurfaceSet2
2-D surface set.
Definition: surface_set2.h:24
jet::Bvh2< Surface2Ptr >
jet::SurfaceSet2::updateQueryEngine
void updateQueryEngine() override
Updates internal spatial query engine.
jet::SurfaceSet2::numberOfSurfaces
size_t numberOfSurfaces() const
Returns the number of surfaces.
jet::SurfaceSet2::isBounded
bool isBounded() const override
Returns true if bounding box can be defined.
jet::SurfaceSet2::SurfaceSet2
SurfaceSet2(const std::vector< Surface2Ptr > &others, const Transform2 &transform=Transform2(), bool isNormalFlipped=false)
Constructs with a list of other surfaces.
jet::BoundingBox< T, 2 >
2-D axis-aligned bounding box class.
Definition: bounding_box2.h:41
jet::Surface2
Abstract base class for 2-D surface.
Definition: surface2.h:27
jet::SurfaceSet2::SurfaceSet2
SurfaceSet2(const SurfaceSet2 &other)
Copy constructor.
jet::SurfaceSet2::Builder
Front-end to create SurfaceSet2 objects step by step.
Definition: surface_set2.h:95
jet::SurfaceSet2::builder
static Builder builder()
Returns builder for SurfaceSet2.
jet::SurfaceSet2::Builder::makeShared
SurfaceSet2Ptr makeShared() const
Builds shared pointer of SurfaceSet2 instance.
jet::SurfaceSet2::addSurface
void addSurface(const Surface2Ptr &surface)
Adds a surface instance.
jet::SurfaceSet2::surfaceAt
const Surface2Ptr & surfaceAt(size_t i) const
Returns the i-th surface.