Box.hpp
Go to the documentation of this file.
1 // This code is based on Jet framework.
2 // Copyright (c) 2018 Doyub Kim
3 // CubbyFlow is voxel-based fluid simulation engine for computer games.
4 // Copyright (c) 2020 CubbyFlow Team
5 // Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6 // AI Part: Dongheon Cho, Minseo Kim
7 // We are making my contributions/submissions to this project solely in our
8 // personal capacity and are not conveying any rights to any intellectual
9 // property of any third parties.
10 
11 #ifndef CUBBYFLOW_BOX_HPP
12 #define CUBBYFLOW_BOX_HPP
13 
15 
16 namespace CubbyFlow
17 {
25 template <size_t N>
26 class Box final : public Surface<N>
27 {
28  public:
29  class Builder;
30 
34 
36  Box(const Transform<N>& _transform = Transform<N>{},
37  bool _isNormalFlipped = false);
38 
40  Box(const Vector<double, N>& lowerCorner,
41  const Vector<double, N>& upperCorner,
42  const Transform<N>& _transform = Transform<N>{},
43  bool _isNormalFlipped = false);
44 
46  Box(const BoundingBox<double, N>& boundingBox,
47  const Transform<N>& _transform = Transform<N>{},
48  bool _isNormalFlipped = false);
49 
51  ~Box() override = default;
52 
54  Box(const Box& other);
55 
57  Box(Box&& other) noexcept;
58 
60  Box& operator=(const Box& other);
61 
63  Box& operator=(Box&& other) noexcept;
64 
66  static Builder GetBuilder();
67 
68  protected:
70  const Vector<double, N>& otherPoint) const override;
71 
72  [[nodiscard]] bool IntersectsLocal(
73  const Ray<double, N>& ray) const override;
74 
75  [[nodiscard]] BoundingBox<double, N> BoundingBoxLocal() const override;
76 
78  const Vector<double, N>& otherPoint) const override;
79 
81  const Ray<double, N>& ray) const override;
82 };
83 
85 using Box2 = Box<2>;
86 
88 using Box3 = Box<3>;
89 
91 using Box2Ptr = std::shared_ptr<Box2>;
92 
94 using Box3Ptr = std::shared_ptr<Box3>;
95 
99 template <size_t N>
100 class Box<N>::Builder final
101  : public SurfaceBuilderBase<N, typename Box<N>::Builder>
102 {
103  public:
105  Builder& WithLowerCorner(const Vector<double, N>& pt);
106 
108  Builder& WithUpperCorner(const Vector<double, N>& pt);
109 
111  Builder& WithBoundingBox(const BoundingBox<double, N>& bbox);
112 
114  Box Build() const;
115 
117  std::shared_ptr<Box<N>> MakeShared() const;
118 
119  private:
121  using Base::m_isNormalFlipped;
122  using Base::m_transform;
123 
124  Vector<double, N> m_lowerCorner;
126 };
127 } // namespace CubbyFlow
128 
129 #endif
BoundingBox< double, N > BoundingBoxLocal() const override
Returns the bounding box of this surface object in local frame.
Class for N-D ray.
Definition: Ray.hpp:25
Front-end to create Box objects step by step.
Definition: Box.hpp:100
N-D box geometry.
Definition: Box.hpp:26
SurfaceRayIntersection< N > ClosestIntersectionLocal(const Ray< double, N > &ray) const override
Returns the closest intersection point for given ray in local frame.
Represents N-D rigid body transform.
Definition: Transform.hpp:82
Definition: Matrix.hpp:27
static std::enable_if_t< IsMatrixSizeStatic< Rows, Cols >), D > MakeConstant(ValueType val)
Makes a static matrix with constant entries.
Definition: MatrixDenseBase-Impl.hpp:152
Box & operator=(const Box &other)
Copy assignment operator.
Definition: pybind11Utils.hpp:20
Abstract base class for N-D surface.
Definition: Surface.hpp:38
Box(const Transform< N > &_transform=Transform< N >{}, bool _isNormalFlipped=false)
Constructs (0, 0, ...) x (1, 1, ...) box.
Struct that represents ray-surface intersection point.
Definition: Surface.hpp:25
Vector< double, N > ClosestPointLocal(const Vector< double, N > &otherPoint) const override
static Builder GetBuilder()
Returns builder fox Box.
~Box() override=default
Default virtual destructor.
std::shared_ptr< Box2 > Box2Ptr
Shared pointer type for the Box2.
Definition: Box.hpp:91
Vector< double, N > ClosestNormalLocal(const Vector< double, N > &otherPoint) const override
std::shared_ptr< Box3 > Box3Ptr
Shared pointer type for the Box3.
Definition: Box.hpp:94
BoundingBox< double, N > bound
Bounding box of this box.
Definition: Box.hpp:32
Base class for N-D surface builder.
Definition: Surface.hpp:153
bool IntersectsLocal(const Ray< double, N > &ray) const override