25 #ifndef HERMES_GEOMETRY_BBOX_H
26 #define HERMES_GEOMETRY_BBOX_H
38 template<
typename T>
class BBox1 {
48 lower = Numbers::greatest<T>();
49 upper = Numbers::lowest<T>();
53 upper(std::max(p1, p2)) {}
84 template<
typename T>
class BBox2 {
96 lower =
Point2<T>(Numbers::greatest<T>());
101 #ifdef HERMES_DEVICE_ENABLED
105 lower =
Point2<T>(std::min(p1.
x, p2.
x), std::min(p1.
y, p2.
y));
106 upper =
Point2<T>(std::max(p1.
x, p2.
x), std::max(p1.
y, p2.
y));
118 lower = range.
lower();
119 upper = range.
upper();
129 return (i == 0) ? lower : upper;
133 #define ARITHMETIC_OP(OP, O) \
134 HERMES_DEVICE_CALLABLE BBox2& operator OP##= (const O& o) { *this = make_union(*this, o); return *this; } \
135 HERMES_DEVICE_CALLABLE BBox2 operator OP (const O& o) { return make_union(*this, o); }
141 return lower == b.lower && upper == b.upper;
147 return (p.
x >= lower.x && p.
x <= upper.x && p.
y >= lower.y
154 #ifdef HERMES_DEVICE_ENABLED
155 d = fmaxf(0, fminf(1, d));
157 d = std::max(0, std::min(1, d));
159 return upper[d] - lower[d];
162 return upper - lower;
165 return lower + (upper - lower) * .5f;
168 return lower * .5f +
vec2(upper * .5f);
202 lower =
Point3<T>(Numbers::greatest<T>());
219 #ifdef HERMES_DEVICE_ENABLED
225 lower =
Point3<T>(std::min(p1.
x, p2.
x), std::min(p1.
y, p2.
y),
226 std::min(p1.
z, p2.
z));
227 upper =
Point3<T>(std::max(p1.
x, p2.
x), std::max(p1.
y, p2.
y),
228 std::max(p1.
z, p2.
z));
240 return (p.
x >= lower.x && p.
x <= upper.x && p.
y >= lower.y &&
241 p.
y <= upper.y && p.
z >= lower.z && p.
z <= upper.z);
252 return (p.
x >= lower.x && p.
x < upper.x && p.
y >= lower.y && p.
y < upper.y
253 && p.
z >= lower.z && p.
z < upper.z);
266 return upper - lower;
271 if (diag.
x > diag.
y && diag.
x > diag.
z)
273 else if (diag.
y > diag.
z)
282 if (upper.x > lower.x)
283 o.
x /= upper.x - lower.x;
284 if (upper.y > lower.y)
285 o.
y /= upper.y - lower.y;
286 if (upper.z > lower.z)
287 o.
z /= upper.z - lower.z;
293 return 2 * (d.
x * d.
y + d.
x * d.
z + d.
y * d.
z);
298 return d.
x * d.
y * d.
z;
310 [[nodiscard]] std::vector<BBox3>
splitBy8()
const {
312 std::vector<BBox3 < T>>
314 children.emplace_back(lower, mid);
315 children.emplace_back(
Point3<T>(mid.x, lower.y, lower.z),
317 children.emplace_back(
Point3<T>(lower.x, mid.y, lower.z),
319 children.emplace_back(
Point3<T>(mid.x, mid.y, lower.z),
321 children.emplace_back(
Point3<T>(lower.x, lower.y, mid.z),
323 children.emplace_back(
Point3<T>(mid.x, lower.y, mid.z),
325 children.emplace_back(
Point3<T>(lower.x, mid.y, mid.z),
327 children.emplace_back(
Point3<T>(mid.x, mid.y, mid.z),
332 return lower + (upper - lower) * .5f;
335 return lower * .5f + vec3(upper * .5f);
338 return upper[d] - lower[d];
346 return (i == 0) ? lower : upper;
351 return (i == 0) ? lower : upper;
356 return Point3<T>((*
this)[(c & 1)].x, (*
this)[(c & 2) ? 1 : 0].y,
357 (*
this)[(c & 4) ? 1 : 0].z);
360 return BBox2<T>(lower.xy(), upper.xy());
363 return BBox2<T>(lower.yz(), upper.yz());
366 return BBox2<T>(lower.xz(), upper.xz());
371 Point3 <T> lower, upper;
380 ret.lower = std::min(b.lower, p);
381 ret.upper = std::max(b.upper, p);
386 BBox1 ret = make_union(a, b.lower);
387 return make_union(ret, b.upper);
393 #ifdef HERMES_DEVICE_ENABLED
394 ret.lower.x = fminf(b.lower.x, p.x);
395 ret.lower.y = fminf(b.lower.y, p.y);
396 ret.upper.x = fmaxf(b.upper.x, p.x);
397 ret.upper.y = fmaxf(b.upper.y, p.y);
399 ret.lower.x = std::min(b.lower.x, p.x);
400 ret.lower.y = std::min(b.lower.y, p.y);
401 ret.upper.x = std::max(b.upper.x, p.x);
402 ret.upper.y = std::max(b.upper.y, p.y);
409 BBox2<T> ret = make_union(a, b.lower);
410 return make_union(ret, b.upper);
419 bool x = (a.upper.x >= b.lower.x) && (a.lower.x <= b.upper.x);
420 bool y = (a.upper.y >= b.lower.y) && (a.lower.y <= b.upper.y);
421 bool z = (a.upper.z >= b.lower.z) && (a.lower.z <= b.upper.z);
422 return (x && y && z);
431 #ifdef HERMES_DEVICE_ENABLED
432 ret.lower.x = fminf(b.lower.x, p.x);
433 ret.lower.y = fminf(b.lower.y, p.y);
434 ret.lower.z = fminf(b.lower.z, p.z);
435 ret.upper.x = fmaxf(b.upper.x, p.x);
436 ret.upper.y = fmaxf(b.upper.y, p.y);
437 ret.upper.z = fmaxf(b.upper.z, p.z);
439 ret.lower.x = std::min(b.lower.x, p.x);
440 ret.lower.y = std::min(b.lower.y, p.y);
441 ret.lower.z = std::min(b.lower.z, p.z);
442 ret.upper.x = std::max(b.upper.x, p.x);
443 ret.upper.y = std::max(b.upper.y, p.y);
444 ret.upper.z = std::max(b.upper.z, p.z);
454 BBox3 <T> ret = make_union(a, b.lower);
455 return make_union(ret, b.upper);
463 #ifdef HERMES_DEVICE_ENABLED
465 Point3<T>(max(a.lower.x, b.lower.x), max(a.lower.x, b.lower.y),
466 max(a.lower.z, b.lower.z)),
467 Point3<T>(min(a.upper.x, b.upper.x), min(a.upper.x, b.upper.y),
468 min(a.upper.z, b.upper.z)));
471 Point3<T>(std::max(a.lower.x, b.lower.x), std::max(a.lower.x, b.lower.y),
472 std::max(a.lower.z, b.lower.z)),
473 Point3<T>(std::min(a.upper.x, b.upper.x), std::min(a.upper.x, b.upper.y),
474 std::min(a.upper.z, b.upper.z)));
481 std::ostream &
operator<<(std::ostream &os,
const BBox1<T> &b) {
482 os <<
"BBox1(" << b.lower <<
", " << b.upper <<
")";
486 std::ostream &
operator<<(std::ostream &os,
const BBox2<T> &b) {
487 os <<
"BBox2(" << b.lower <<
", " << b.upper <<
")";
491 std::ostream &
operator<<(std::ostream &os,
const BBox3<T> &b) {
492 os <<
"BBox3(" << b.lower <<
", " << b.upper <<
")";
499 typedef BBox1<real_t> bbox1;
500 typedef BBox2<real_t> bbox2;
501 typedef BBox3<real_t> bbox3;
502 typedef BBox3<float> bbox3f;
std::vector< BBox3 > splitBy8() const
Definition: bbox.h:310
HERMES_DEVICE_CALLABLE Vector3< T > diagonal() const
Definition: bbox.h:265
HERMES_DEVICE_CALLABLE bool containsExclusive(const Point3< T > &p) const
Definition: bbox.h:251
HERMES_DEVICE_CALLABLE Vector3< T > offset(const Point3< T > &p) const
Definition: bbox.h:280
HERMES_DEVICE_CALLABLE T surfaceArea() const
Definition: bbox.h:291
HERMES_DEVICE_CALLABLE bool contains(const BBox3 &b) const
Definition: bbox.h:245
HERMES_DEVICE_CALLABLE T volume() const
Definition: bbox.h:296
HERMES_DEVICE_CALLABLE Point3< T > & operator[](int i)
Definition: bbox.h:350
HERMES_DEVICE_CALLABLE BBox3(const Point3< T > &p)
Definition: bbox.h:207
HERMES_DEVICE_CALLABLE const Point3< T > & operator[](int i) const
Definition: bbox.h:345
HERMES_DEVICE_CALLABLE BBox3(const Point3< T > &c, real_t r)
Definition: bbox.h:211
HERMES_DEVICE_CALLABLE BBox3()
Creates an empty bounding box.
Definition: bbox.h:201
HERMES_DEVICE_CALLABLE BBox3(const Point3< T > &p1, const Point3< T > &p2)
Definition: bbox.h:218
HERMES_DEVICE_CALLABLE void expand(real_t delta)
Definition: bbox.h:260
HERMES_DEVICE_CALLABLE Point3< T > corner(int c) const
Definition: bbox.h:355
HERMES_DEVICE_CALLABLE int maxExtent() const
Definition: bbox.h:269
HERMES_DEVICE_CALLABLE bool contains(const Point3< T > &p) const
Definition: bbox.h:239
Represents a closed-open range of indices [lower, upper)
Definition: index.h:283
HERMES_DEVICE_CALLABLE const Index2< T > & upper() const
Definition: index.h:346
HERMES_DEVICE_CALLABLE const Index2< T > & lower() const
Definition: index.h:344
Geometric 2-dimensional point (x, y)
Definition: point.h:49
T y
1-th component
Definition: point.h:140
T x
0-th component
Definition: point.h:139
Geometric 3-dimensional vector (x, y, z)
Definition: point.h:148
T x
0-th component
Definition: point.h:270
T y
1-th component
Definition: point.h:271
T z
2-th component
Definition: point.h:272
Geometric 2-dimensional vector (x, y)
Definition: vector.h:54
T x
0-th component
Definition: vector.h:155
T y
1-th component
Definition: vector.h:156
Geometric 3-dimensional vector (x, y, z)
Definition: vector.h:166
T x
0-th component
Definition: vector.h:415
T z
2-th component
Definition: vector.h:417
T y
1-th component
Definition: vector.h:416
std::ostream & operator<<(std::ostream &o, const LaunchInfo &info)
LaunchInfo support for std::ostream << operator.
Definition: cuda_utils.h:234
float real_t
default floating point type
Definition: defs.h:75
#define HERMES_DEVICE_CALLABLE
Specifies that the function can be called from both host and device sides.
Definition: defs.h:45
uint32_t u32
32 bit size unsigned integer type
Definition: defs.h:88
#define ARITHMETIC_OP(OP)
asd
Definition: index.h:408
Holds 2-dimensional integer index coordinates.
Definition: index.h:50