Loading...
Searching...
No Matches
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
16namespace CubbyFlow
17{
25template <size_t N>
26class Box final : public Surface<N>
27{
28 public:
29 class Builder;
30
34
36 Box() : Box(Transform<N>{})
37 {
38 // Do nothing
39 }
40
42 explicit Box(const Transform<N>& _transform, bool _isNormalFlipped = false);
43
45 Box(const Vector<double, N>& lowerCorner,
46 const Vector<double, N>& upperCorner,
47 const Transform<N>& _transform = Transform<N>{},
48 bool _isNormalFlipped = false);
49
51 explicit Box(const BoundingBox<double, N>& boundingBox,
52 const Transform<N>& _transform = Transform<N>{},
53 bool _isNormalFlipped = false);
54
56 ~Box() override = default;
57
59 Box(const Box& other);
60
62 Box(Box&& other) noexcept;
63
65 Box& operator=(const Box& other);
66
68 Box& operator=(Box&& other) noexcept;
69
72
73 protected:
75 const Vector<double, N>& otherPoint) const override;
76
77 [[nodiscard]] bool IntersectsLocal(
78 const Ray<double, N>& ray) const override;
79
80 [[nodiscard]] BoundingBox<double, N> BoundingBoxLocal() const override;
81
83 const Vector<double, N>& otherPoint) const override;
84
86 const Ray<double, N>& ray) const override;
87};
88
90using Box2 = Box<2>;
91
93using Box3 = Box<3>;
94
96using Box2Ptr = std::shared_ptr<Box2>;
97
99using Box3Ptr = std::shared_ptr<Box3>;
100
104template <size_t N>
105class Box<N>::Builder final
106 : public SurfaceBuilderBase<N, typename Box<N>::Builder>
107{
108 public:
111
114
117
119 Box Build() const;
120
122 std::shared_ptr<Box<N>> MakeShared() const;
123
124 private:
126 using Base::m_isNormalFlipped;
127 using Base::m_transform;
128
129 Vector<double, N> m_lowerCorner;
131};
132} // namespace CubbyFlow
133
134#endif
N-D axis-aligned bounding box class.
Definition BoundingBox.hpp:47
Front-end to create Box objects step by step.
Definition Box.hpp:107
Builder & WithUpperCorner(const Vector< double, N > &pt)
Returns builder with upper corner set.
std::shared_ptr< Box< N > > MakeShared() const
Builds shared pointer of Box instance.
Box Build() const
Builds Box.
Builder & WithLowerCorner(const Vector< double, N > &pt)
Returns builder with lower corner set.
Builder & WithBoundingBox(const BoundingBox< double, N > &bbox)
Returns builder with bounding box.
N-D box geometry.
Definition Box.hpp:27
static Builder GetBuilder()
Returns builder fox Box.
Box(Box &&other) noexcept
Move constructor.
Vector< double, N > ClosestNormalLocal(const Vector< double, N > &otherPoint) const override
bool IntersectsLocal(const Ray< double, N > &ray) const override
Vector< double, N > ClosestPointLocal(const Vector< double, N > &otherPoint) const override
Box(const Box &other)
Copy constructor.
Box & operator=(const Box &other)
Copy assignment operator.
BoundingBox< double, N > BoundingBoxLocal() const override
Returns the bounding box of this surface object in local frame.
Box(const Vector< double, N > &lowerCorner, const Vector< double, N > &upperCorner, const Transform< N > &_transform=Transform< N >{}, bool _isNormalFlipped=false)
Constructs a box with given lowerCorner and upperCorner.
Box & operator=(Box &&other) noexcept
Move assignment operator.
Box(const Transform< N > &_transform, bool _isNormalFlipped=false)
Constructs (0, 0, ...) x (1, 1, ...) box with a transform.
Box(const BoundingBox< double, N > &boundingBox, const Transform< N > &_transform=Transform< N >{}, bool _isNormalFlipped=false)
Constructs a box with BoundingBox instance.
Box()
Constructs (0, 0, ...) x (1, 1, ...) box.
Definition Box.hpp:36
SurfaceRayIntersection< N > ClosestIntersectionLocal(const Ray< double, N > &ray) const override
Returns the closest intersection point for given ray in local frame.
BoundingBox< double, N > bound
Bounding box of this box.
Definition Box.hpp:32
~Box() override=default
Default virtual destructor.
static std::enable_if_t< IsMatrixSizeStatic< Rows, Cols >(), D > MakeConstant(ValueType val)
Makes a static matrix with constant entries.
Definition MatrixDenseBase-Impl.hpp:152
Definition Matrix.hpp:30
Class for N-D ray.
Definition Ray.hpp:26
Base class for N-D surface builder.
Definition Surface.hpp:154
Abstract base class for N-D surface.
Definition Surface.hpp:39
Represents N-D rigid body transform.
Definition Transform.hpp:83
Definition pybind11Utils.hpp:22
std::shared_ptr< Box3 > Box3Ptr
Shared pointer type for the Box3.
Definition Box.hpp:99
std::shared_ptr< Box2 > Box2Ptr
Shared pointer type for the Box2.
Definition Box.hpp:96
Struct that represents ray-surface intersection point.
Definition Surface.hpp:26