Box3.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: Box3.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 3-D box geometry.
6 > Created Time: 2017/06/21
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_BOX3_H
10 #define CUBBYFLOW_BOX3_H
11 
12 #include <Core/Surface/Surface3.h>
13 
14 namespace CubbyFlow
15 {
23  class Box3 final : public Surface3
24  {
25  public:
26  class Builder;
27 
30 
32  Box3(const Transform3& transform = Transform3(), bool isNormalFlipped = false);
33 
35  Box3(const Vector3D& lowerCorner, const Vector3D& upperCorner,
36  const Transform3& transform = Transform3(), bool isNormalFlipped = false);
37 
39  explicit Box3(const BoundingBox3D& boundingBox, const Transform3& transform = Transform3(), bool isNormalFlipped = false);
40 
42  Box3(const Box3& other);
43 
45  static Builder GetBuilder();
46 
47  protected:
48  // Surface3 implementations
49  Vector3D ClosestPointLocal(const Vector3D& otherPoint) const override;
50 
51  bool IntersectsLocal(const Ray3D& ray) const override;
52 
53  BoundingBox3D BoundingBoxLocal() const override;
54 
55  Vector3D ClosestNormalLocal(const Vector3D& otherPoint) const override;
56 
57  SurfaceRayIntersection3 ClosestIntersectionLocal(const Ray3D& ray) const override;
58  };
59 
61  using Box3Ptr = std::shared_ptr<Box3>;
62 
66  class Box3::Builder final : public SurfaceBuilderBase3<Box3::Builder>
67  {
68  public:
70  Builder& WithLowerCorner(const Vector3D& pt);
71 
73  Builder& WithUpperCorner(const Vector3D& pt);
74 
77 
79  Box3 Build() const;
80 
82  Box3Ptr MakeShared() const;
83 
84  private:
85  Vector3D m_lowerCorner{ 0, 0, 0 };
86  Vector3D m_upperCorner{ 1, 1, 1 };
87  };
88 }
89 
90 #endif
Builder & WithUpperCorner(const Vector3D &pt)
Returns builder with upper corner set.
3-D vector class.
Definition: Vector3.h:26
bool IntersectsLocal(const Ray3D &ray) const override
static Builder GetBuilder()
Returns builder fox Box3.
Builder & WithLowerCorner(const Vector3D &pt)
Returns builder with lower corner set.
Vector3D ClosestNormalLocal(const Vector3D &otherPoint) const override
Structure that represents ray-surface intersection point.
Definition: Surface3.h:23
BoundingBox3< double > BoundingBox3D
Double-type 3-D BoundingBox.
Definition: BoundingBox3.h:129
Base class for 3-D surface builder.
Definition: Surface3.h:106
Definition: pybind11Utils.h:24
Box3Ptr MakeShared() const
Builds shared pointer of Box3 instance.
Abstract base class for 3-D surface.
Definition: Surface3.h:32
Transform3 transform
Local-to-world transform.
Definition: Surface3.h:36
3-D axis-aligned bounding box class.
Definition: BoundingBox3.h:44
Box3 Build() const
Builds Box3.
Represents 3-D rigid body transform.
Definition: Transform3.h:22
bool isNormalFlipped
Flips normal when calling Surface3::closestNormal(...).
Definition: Surface3.h:39
Front-end to create Box3 objects step by step.
Definition: Box3.h:66
BoundingBox3D BoundingBoxLocal() const override
Returns the bounding box of this surface object in local frame.
BoundingBox3D bound
Bounding box of this box.
Definition: Box3.h:29
Builder & WithBoundingBox(const BoundingBox3D &bbox)
Returns builder with bounding box.
Class for 3-D ray.
Definition: Ray3.h:23
3-D box geometry.
Definition: Box3.h:23
std::shared_ptr< Box3 > Box3Ptr
Shared pointer type for the Box3.
Definition: Box3.h:61
Box3(const Transform3 &transform=Transform3(), bool isNormalFlipped=false)
Constructs (0, 0, 0) x (1, 1, 1) box.
Vector3D ClosestPointLocal(const Vector3D &otherPoint) const override
Vector3< double > Vector3D
Double-type 3D vector.
Definition: Vector3.h:353
SurfaceRayIntersection3 ClosestIntersectionLocal(const Ray3D &ray) const override
Returns the closest intersection point for given ray in local frame.