1 #ifndef BOUNDINGBOX_HPP
2 #define BOUNDINGBOX_HPP
17 typedef std::numeric_limits<T> limits;
42 if(limits::is_integer)
50 pts[0] =
Point(v, v, v);
54 pts[1] =
Point(0, 0, 0);
60 for(
size_t i = 0; i < N; ++i)
61 if(pts[0][i] >= pts[1][i])
67 operator bool()
const {
73 return pts[0] == other.pts[0] and pts[1] == other.pts[1];
78 return pts[0] != other.pts[0] or pts[1] != other.pts[1];
83 return pts[1] - pts[0];
92 for(
size_t i = 0; i < N; ++i) {
93 if(pts[0][i] < other.pts[0][i])
94 pts[0][i] = other.pts[0][i];
95 if(pts[1][i] > other.pts[1][i])
96 pts[1][i] = other.pts[1][i];
105 return copy &= other;
109 BoundingBox& operator*=(
const BoundingBox& other) {
110 return (*
this) &= (other);
114 BoundingBox operator*(
const BoundingBox& other)
const
116 BoundingBox copy(*
this);
117 return copy &= other;
126 for(
size_t i = 0; i < N; ++i) {
127 if(pts[0][i] > other.pts[0][i])
128 pts[0][i] = other.pts[0][i];
129 if(pts[1][i] < other.pts[1][i])
130 pts[1][i] = other.pts[1][i];
139 return copy |= other;
143 BoundingBox& operator+=(
const BoundingBox& other) {
144 return (*
this) |= (other);
148 BoundingBox operator+(
const BoundingBox& other)
const
150 BoundingBox copy(*
this);
151 return copy |= other;
160 for(
size_t i = 0; i < N; ++i) {
163 if(limits::is_integer) {
164 if(pts[1][i] < p[i] + 1)
165 pts[1][i] = p[i] + 1;
182 friend BoundingBox operator&(
const Point& p,
const BoundingBox& b)
189 const Point& operator[](
int i)
const
197 Point& operator[](
int i)
210 return (p.
x() >= pts[0].
x() and p.
y() >= pts[0].
y() and p.
z() >= pts[0].
z() and p.
x() < pts[1].
x()
211 and p.
y() < pts[1].
y() and p.
z() < pts[1].
z());
242 friend std::ostream& operator<<(std::ostream& s,
const BoundingBox& bbox)
244 s << bbox.pts[0] <<
" " << bbox.pts[1];
249 friend std::istream& operator>>(std::istream& s, BoundingBox& bbox)
251 s >> bbox.pts[0] >> bbox.pts[1];
258 s << bbox.pts[0] <<
" " << bbox.pts[1];
264 s >> bbox.pts[0] >> bbox.pts[1];
271 #endif // BOUNDINGBOX_HPP
Definition: BoundingBox.hpp:14
CU_HOST_DEVICE BoundingBox & operator|=(const Point &p)
Adding a point.
Definition: BoundingBox.hpp:158
CU_HOST_DEVICE void x(const T &v)
Short access to the first element.
Definition: Vector.hpp:651
CU_HOST_DEVICE void y(const T &v)
Short access to the second element.
Definition: Vector.hpp:660
CU_HOST_DEVICE void z(const T &v)
Short access to the third element.
Definition: Vector.hpp:669
CU_HOST_DEVICE bool contains(const Point &p) const
Check if a point is in the BoundingBox.
Definition: BoundingBox.hpp:208
CU_HOST_DEVICE BoundingBox & operator&=(const BoundingBox &other)
Bounding box intersection.
Definition: BoundingBox.hpp:90
CU_HOST_DEVICE BoundingBox & operator|=(const BoundingBox &other)
Bounding box union.
Definition: BoundingBox.hpp:124
Defines the Vector class template This file is shared by cuda, do not include headers that nvcc can't...