HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImathBox.h
Go to the documentation of this file.
1 //
2 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright Contributors to the OpenEXR Project.
4 //
5 
6 //
7 // Axis-aligned bounding box
8 //
9 
10 #ifndef INCLUDED_IMATHBOX_H
11 #define INCLUDED_IMATHBOX_H
12 
13 #include "ImathExport.h"
14 #include "ImathNamespace.h"
15 
16 #include "ImathVec.h"
17 
18 IMATH_INTERNAL_NAMESPACE_HEADER_ENTER
19 
20 ///
21 /// The `Box<V>` template represents an axis-aligned bounding box defined by
22 /// minimum and maximum values of type `V`. The `min` and `max` members are
23 /// public.
24 ///
25 /// The type `V` is typically an Imath vector (i.e. `V2i`, `V3f`, etc) and must
26 /// implement an index `operator[]` that returns a type (typically as scalar)
27 /// that supports assignment, comparison, and arithmetic operators.
28 ///
29 /// `V` must also provide a constructor that takes a float and/or double for
30 /// use in initializing the box.
31 ///
32 /// `V` must also provide a function `V::dimensions()` which returns the
33 /// number of dimensions in the class (since its assumed its a vector) --
34 /// preferably, this returns a constant expression, typically 2 or 3.
35 ///
36 
37 template <class V> class IMATH_EXPORT_TEMPLATE_TYPE Box
38 {
39 public:
40  /// @{
41  /// @name Direct access to bounds
42 
43  /// The minimum value of the box.
44  V min;
45 
46  /// The maximum value of the box.
47  V max;
48 
49  /// @}
50 
51  /// @{
52  /// @name Constructors
53 
54  /// Construct an empty bounding box. This initializes the mimimum to
55  /// std::numeric_limits<V::baseType>::max() and the maximum to
56  /// std::numeric_limits<V::baseType>::lowest().
57  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Box () IMATH_NOEXCEPT;
58 
59  /// Construct a bounding box that contains a single point.
60  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Box (const V& point) IMATH_NOEXCEPT;
61 
62  /// Construct a bounding box with the given minimum and maximum values.
63  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Box (const V& minV, const V& maxV)
64  IMATH_NOEXCEPT;
65 
66  /// @}
67 
68  /// @{
69  /// @name Comparison
70 
71  /// Equality
72  IMATH_HOSTDEVICE constexpr bool
73  operator== (const Box<V>& src) const IMATH_NOEXCEPT;
74 
75  /// Inequality
76  IMATH_HOSTDEVICE constexpr bool
77  operator!= (const Box<V>& src) const IMATH_NOEXCEPT;
78 
79  /// @}
80 
81  /// @{
82  /// @name Manipulation
83 
84  /// Set the box to be empty. A box is empty if the mimimum is greater
85  /// than the maximum. makeEmpty() sets the mimimum to `V::baseTypeMax()`
86  /// and the maximum to `V::baseTypeLowest()`.
87  IMATH_HOSTDEVICE void makeEmpty () IMATH_NOEXCEPT;
88 
89  /// Extend the box to include the given point.
90  IMATH_HOSTDEVICE void extendBy (const V& point) IMATH_NOEXCEPT;
91 
92  /// Extend the box to include the given box.
93  IMATH_HOSTDEVICE void extendBy (const Box<V>& box) IMATH_NOEXCEPT;
94 
95  /// Make the box include the entire range of `V`.
96  IMATH_HOSTDEVICE void makeInfinite () IMATH_NOEXCEPT;
97 
98  /// @}
99 
100  /// @{
101  /// @name Query
102 
103  /// Return the size of the box. The size is of type `V`, defined
104  /// as `(max-min)`. An empty box has a size of `V(0)`, i.e. 0 in
105  /// each dimension.
106  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 V size () const IMATH_NOEXCEPT;
107 
108  /// Return the center of the box. The center is defined as
109  /// `(max+min)/2`. The center of an empty box is undefined.
110  IMATH_HOSTDEVICE constexpr V center () const IMATH_NOEXCEPT;
111 
112  /// Return true if the given point is inside the box, false otherwise.
113  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool
114  intersects (const V& point) const IMATH_NOEXCEPT;
115 
116  /// Return true if the given box is inside the box, false otherwise.
117  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool
118  intersects (const Box<V>& box) const IMATH_NOEXCEPT;
119 
120  /// Return the major axis of the box. The major axis is the dimension with
121  /// the greatest difference between maximum and minimum.
122  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 unsigned int
123  majorAxis () const IMATH_NOEXCEPT;
124 
125  /// Return true if the box is empty, false otherwise. An empty box's
126  /// minimum is greater than its maximum.
127  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool isEmpty () const IMATH_NOEXCEPT;
128 
129  /// Return true if the box is larger than a single point, false otherwise.
130  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool hasVolume () const IMATH_NOEXCEPT;
131 
132  /// Return true if the box contains all points, false otherwise.
133  /// An infinite box has a mimimum of`V::baseTypeLowest()`
134  /// and a maximum of `V::baseTypeMax()`.
135  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool isInfinite () const IMATH_NOEXCEPT;
136 
137  /// @}
138 };
139 
140 //--------------------
141 // Convenient typedefs
142 //--------------------
143 
144 /// 2D box of base type `short`.
145 typedef Box<V2s> Box2s;
146 
147 /// 2D box of base type `int`.
148 typedef Box<V2i> Box2i;
149 
150 /// 2D box of base type `int64_t`.
151 typedef Box<V2i64> Box2i64;
152 
153 /// 2D box of base type `half`.
154 typedef Box<V2h> Box2h;
155 
156 /// 2D box of base type `float`.
157 typedef Box<V2f> Box2f;
158 
159 /// 2D box of base type `double`.
160 typedef Box<V2d> Box2d;
161 
162 /// 3D box of base type `short`.
163 typedef Box<V3s> Box3s;
164 
165 /// 3D box of base type `int`.
166 typedef Box<V3i> Box3i;
167 
168 /// 3D box of base type `int64_t`.
169 typedef Box<V3i64> Box3i64;
170 
171 /// 3D box of base type `half`.
172 typedef Box<V3h> Box3h;
173 
174 /// 3D box of base type `float`.
175 typedef Box<V3f> Box3f;
176 
177 /// 3D box of base type `double`.
178 typedef Box<V3d> Box3d;
179 
180 template <class V>
181 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline Box<V>::Box () IMATH_NOEXCEPT
182 {
183  makeEmpty ();
184 }
185 
186 template <class V>
188  IMATH_CONSTEXPR14 inline Box<V>::Box (const V& point) IMATH_NOEXCEPT
189 {
190  min = point;
191  max = point;
192 }
193 
194 template <class V>
195 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline Box<V>::Box (
196  const V& minV, const V& maxV) IMATH_NOEXCEPT
197 {
198  min = minV;
199  max = maxV;
200 }
201 
202 template <class V>
203 IMATH_HOSTDEVICE constexpr inline bool
205 {
206  return (min == src.min && max == src.max);
207 }
208 
209 template <class V>
210 IMATH_HOSTDEVICE constexpr inline bool
212 {
213  return (min != src.min || max != src.max);
214 }
215 
216 template <class V>
217 IMATH_HOSTDEVICE inline void
219 {
220  min = V (V::baseTypeMax ());
221  max = V (V::baseTypeLowest ());
222 }
223 
224 template <class V>
225 IMATH_HOSTDEVICE inline void
227 {
228  min = V (V::baseTypeLowest ());
229  max = V (V::baseTypeMax ());
230 }
231 
232 template <class V>
233 IMATH_HOSTDEVICE inline void
235 {
236  for (unsigned int i = 0; i < min.dimensions (); i++)
237  {
238  if (point[i] < min[i]) min[i] = point[i];
239 
240  if (point[i] > max[i]) max[i] = point[i];
241  }
242 }
243 
244 template <class V>
245 IMATH_HOSTDEVICE inline void
247 {
248  for (unsigned int i = 0; i < min.dimensions (); i++)
249  {
250  if (box.min[i] < min[i]) min[i] = box.min[i];
251 
252  if (box.max[i] > max[i]) max[i] = box.max[i];
253  }
254 }
255 
256 template <class V>
257 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
258 Box<V>::intersects (const V& point) const IMATH_NOEXCEPT
259 {
260  for (unsigned int i = 0; i < min.dimensions (); i++)
261  {
262  if (point[i] < min[i] || point[i] > max[i]) return false;
263  }
264 
265  return true;
266 }
267 
268 template <class V>
269 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
271 {
272  for (unsigned int i = 0; i < min.dimensions (); i++)
273  {
274  if (box.max[i] < min[i] || box.min[i] > max[i]) return false;
275  }
276 
277  return true;
278 }
279 
280 template <class V>
281 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline V
283 {
284  if (isEmpty ()) return V (0);
285 
286  return max - min;
287 }
288 
289 template <class V>
290 IMATH_HOSTDEVICE constexpr inline V
292 {
293  return (max + min) / 2;
294 }
295 
296 template <class V>
297 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
299 {
300  for (unsigned int i = 0; i < min.dimensions (); i++)
301  {
302  if (max[i] < min[i]) return true;
303  }
304 
305  return false;
306 }
307 
308 template <class V>
309 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
311 {
312  for (unsigned int i = 0; i < min.dimensions (); i++)
313  {
314  if (min[i] != V::baseTypeLowest () || max[i] != V::baseTypeMax ())
315  return false;
316  }
317 
318  return true;
319 }
320 
321 template <class V>
322 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
324 {
325  for (unsigned int i = 0; i < min.dimensions (); i++)
326  {
327  if (max[i] <= min[i]) return false;
328  }
329 
330  return true;
331 }
332 
333 template <class V>
334 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline unsigned int
336 {
337  unsigned int major = 0;
338  V s = size ();
339 
340  for (unsigned int i = 1; i < min.dimensions (); i++)
341  {
342  if (s[i] > s[major]) major = i;
343  }
344 
345  return major;
346 }
347 
348 //-------------------------------------------------------------------
349 //
350 // Partial class specializations for Imath::Vec2<T> and Imath::Vec3<T>
351 //
352 //-------------------------------------------------------------------
353 
354 template <typename V> class Box;
355 
356 ///
357 /// The Box<Vec2<T>> template represents a 2D bounding box defined by
358 /// minimum and maximum values of type Vec2<T>. The min and max members are
359 /// public.
360 ///
361 
362 template <class T> class IMATH_EXPORT_TEMPLATE_TYPE Box<Vec2<T>>
363 {
364 public:
365  /// @{
366  /// @name Direct access to bounds
367 
368  /// The minimum value of the box.
370 
371  /// The maximum value of the box.
373 
374  /// @}
375 
376  /// @{
377  /// @name Constructors and Assignment
378 
379  /// Empty by default
380  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Box () IMATH_NOEXCEPT;
381 
382  /// Construct a bounding box that contains a single point.
383  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Box (const Vec2<T>& point)
385 
386  /// Construct a bounding box with the given minimum and maximum points
387  IMATH_HOSTDEVICE IMATH_CONSTEXPR14
388  Box (const Vec2<T>& minT, const Vec2<T>& maxT) IMATH_NOEXCEPT;
389 
390  /// @}
391 
392  /// @{
393  /// @name Comparison
394 
395  /// Equality
396  IMATH_HOSTDEVICE constexpr bool
397  operator== (const Box<Vec2<T>>& src) const IMATH_NOEXCEPT;
398 
399  /// Inequality
400  IMATH_HOSTDEVICE constexpr bool
401  operator!= (const Box<Vec2<T>>& src) const IMATH_NOEXCEPT;
402 
403  /// @}
404 
405  /// @{
406  /// @name Manipulation
407 
408  /// Set the Box to be empty. A Box is empty if the mimimum is
409  /// greater than the maximum. makeEmpty() sets the mimimum to
410  /// std::numeric_limits<T>::max() and the maximum to
411  /// std::numeric_limits<T>::lowest().
412  IMATH_HOSTDEVICE void makeEmpty () IMATH_NOEXCEPT;
413 
414  /// Extend the Box to include the given point.
415  IMATH_HOSTDEVICE void extendBy (const Vec2<T>& point) IMATH_NOEXCEPT;
416 
417  /// Extend the Box to include the given box.
418  IMATH_HOSTDEVICE void extendBy (const Box<Vec2<T>>& box) IMATH_NOEXCEPT;
419 
420  /// Make the box include the entire range of T.
421  IMATH_HOSTDEVICE void makeInfinite () IMATH_NOEXCEPT;
422 
423  /// @}
424 
425  /// @{
426  /// @name Query
427 
428  /// Return the size of the box. The size is of type `V`, defined as
429  /// `(max-min)`. An empty box has a size of `V(0)`, i.e. 0 in each dimension.
430  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec2<T> size () const IMATH_NOEXCEPT;
431 
432  /// Return the center of the box. The center is defined as
433  /// `(max+min)/2`. The center of an empty box is undefined.
434  IMATH_HOSTDEVICE constexpr Vec2<T> center () const IMATH_NOEXCEPT;
435 
436  /// Return true if the given point is inside the box, false otherwise.
437  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool
438  intersects (const Vec2<T>& point) const IMATH_NOEXCEPT;
439 
440  /// Return true if the given box is inside the box, false otherwise.
441  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool
442  intersects (const Box<Vec2<T>>& box) const IMATH_NOEXCEPT;
443 
444  /// Return the major axis of the box. The major axis is the dimension with
445  /// the greatest difference between maximum and minimum.
446  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 unsigned int
447  majorAxis () const IMATH_NOEXCEPT;
448 
449  /// Return true if the box is empty, false otherwise. An empty box's
450  /// minimum is greater than its maximum.
451  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool isEmpty () const IMATH_NOEXCEPT;
452 
453  /// Return true if the box is larger than a single point, false otherwise.
454  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool hasVolume () const IMATH_NOEXCEPT;
455 
456  /// Return true if the box contains all points, false otherwise.
457  /// An infinite box has a mimimum of `V::baseTypeMin()`
458  /// and a maximum of `V::baseTypeMax()`.
459  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool isInfinite () const IMATH_NOEXCEPT;
460 
461  /// @}
462 };
463 
464 //----------------
465 // Implementation
466 //----------------
467 
468 template <class T>
469 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline Box<Vec2<T>>::Box () IMATH_NOEXCEPT
470 {
471  makeEmpty ();
472 }
473 
474 template <class T>
475 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline Box<Vec2<T>>::Box (
476  const Vec2<T>& point) IMATH_NOEXCEPT
477 {
478  min = point;
479  max = point;
480 }
481 
482 template <class T>
483 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline Box<Vec2<T>>::Box (
484  const Vec2<T>& minT, const Vec2<T>& maxT) IMATH_NOEXCEPT
485 {
486  min = minT;
487  max = maxT;
488 }
489 
490 template <class T>
491 IMATH_HOSTDEVICE constexpr inline bool
492 Box<Vec2<T>>::operator== (const Box<Vec2<T>>& src) const IMATH_NOEXCEPT
493 {
494  return (min == src.min && max == src.max);
495 }
496 
497 template <class T>
498 IMATH_HOSTDEVICE constexpr inline bool
499 Box<Vec2<T>>::operator!= (const Box<Vec2<T>>& src) const IMATH_NOEXCEPT
500 {
501  return (min != src.min || max != src.max);
502 }
503 
504 template <class T>
505 IMATH_HOSTDEVICE inline void
507 {
510 }
511 
512 template <class T>
513 IMATH_HOSTDEVICE inline void
514 Box<Vec2<T>>::makeInfinite () IMATH_NOEXCEPT
515 {
518 }
519 
520 template <class T>
521 IMATH_HOSTDEVICE inline void
522 Box<Vec2<T>>::extendBy (const Vec2<T>& point) IMATH_NOEXCEPT
523 {
524  min.x = std::min (min.x, point.x);
525  max.x = std::max (max.x, point.x);
526  min.y = std::min (min.y, point.y);
527  max.y = std::max (max.y, point.y);
528 }
529 
530 template <class T>
531 IMATH_HOSTDEVICE inline void
532 Box<Vec2<T>>::extendBy (const Box<Vec2<T>>& box) IMATH_NOEXCEPT
533 {
534  min.x = std::min (min.x, box.min.x);
535  max.x = std::max (max.x, box.max.x);
536  min.y = std::min (min.y, box.min.y);
537  max.y = std::max (max.y, box.max.y);
538 }
539 
540 template <class T>
541 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
543 {
544  return (point.x >= min.x) && (point.x <= max.x) &&
545  (point.y >= min.y) && (point.y <= max.y);
546 }
547 
548 template <class T>
549 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
551 {
552  return (box.min.x <= max.x) && (box.max.x >= min.x) &&
553  (box.min.y <= max.y) && (box.max.y >= min.y);
554 }
555 
556 template <class T>
557 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline Vec2<T>
559 {
560  if (isEmpty ()) return Vec2<T> (0);
561 
562  return max - min;
563 }
564 
565 template <class T>
566 IMATH_HOSTDEVICE constexpr inline Vec2<T>
567 Box<Vec2<T>>::center () const IMATH_NOEXCEPT
568 {
569  return (max + min) / 2;
570 }
571 
572 template <class T>
573 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
574 Box<Vec2<T>>::isEmpty () const IMATH_NOEXCEPT
575 {
576  return (max.x < min.x || max.y < min.y);
577 }
578 
579 template <class T>
580 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
582 {
583  if (min.x != std::numeric_limits<T>::lowest () ||
585  min.y != std::numeric_limits<T>::lowest () ||
587  return false;
588 
589  return true;
590 }
591 
592 template <class T>
593 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
594 Box<Vec2<T>>::hasVolume () const IMATH_NOEXCEPT
595 {
596  if (max.x <= min.x || max.y <= min.y) return false;
597 
598  return true;
599 }
600 
601 template <class T>
602 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline unsigned int
603 Box<Vec2<T>>::majorAxis () const IMATH_NOEXCEPT
604 {
605  Vec2<T> s = size ();
606 
607  return (s.x >= s.y) ? 0 : 1;
608 }
609 
610 ///
611 /// The Box<Vec3> template represents a 3D bounding box defined by
612 /// minimum and maximum values of type Vec3.
613 ///
614 template <class T> class IMATH_EXPORT_TEMPLATE_TYPE Box<Vec3<T>>
615 {
616 public:
617  /// @{
618  /// @name Direct access to bounds
619 
620  /// The minimum value of the box.
622 
623  /// The maximum value of the box.
625 
626  /// @}
627 
628  /// @{
629  /// @name Constructors
630 
631  /// Empty by default
632  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Box () IMATH_NOEXCEPT;
633 
634  /// Construct a bounding box that contains a single point.
635  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Box (const Vec3<T>& point)
637 
638  /// Construct a bounding box with the given minimum and maximum points
639  IMATH_HOSTDEVICE IMATH_CONSTEXPR14
640  Box (const Vec3<T>& minT, const Vec3<T>& maxT) IMATH_NOEXCEPT;
641 
642  /// @}
643 
644  /// Equality
645  IMATH_HOSTDEVICE constexpr bool
646  operator== (const Box<Vec3<T>>& src) const IMATH_NOEXCEPT;
647 
648  /// Inequality
649  IMATH_HOSTDEVICE constexpr bool
650  operator!= (const Box<Vec3<T>>& src) const IMATH_NOEXCEPT;
651 
652  /// Set the Box to be empty. A Box is empty if the mimimum is
653  /// greater than the maximum. makeEmpty() sets the mimimum to
654  /// std::numeric_limits<T>::max() and the maximum to
655  /// std::numeric_limits<T>::lowest().
656  IMATH_HOSTDEVICE void makeEmpty () IMATH_NOEXCEPT;
657 
658  /// Extend the Box to include the given point.
659  IMATH_HOSTDEVICE void extendBy (const Vec3<T>& point) IMATH_NOEXCEPT;
660  /// Extend the Box to include the given box.
661 
662  IMATH_HOSTDEVICE void extendBy (const Box<Vec3<T>>& box) IMATH_NOEXCEPT;
663 
664  /// Make the box include the entire range of T.
665  IMATH_HOSTDEVICE void makeInfinite () IMATH_NOEXCEPT;
666 
667  /// Return the size of the box. The size is of type `V`, defined as
668  /// (max-min). An empty box has a size of V(0), i.e. 0 in each dimension.
669  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec3<T> size () const IMATH_NOEXCEPT;
670 
671  /// Return the center of the box. The center is defined as
672  /// (max+min)/2. The center of an empty box is undefined.
673  IMATH_HOSTDEVICE constexpr Vec3<T> center () const IMATH_NOEXCEPT;
674 
675  /// Return true if the given point is inside the box, false otherwise.
676  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool
677  intersects (const Vec3<T>& point) const IMATH_NOEXCEPT;
678 
679  /// Return true if the given box is inside the box, false otherwise.
680  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool
681  intersects (const Box<Vec3<T>>& box) const IMATH_NOEXCEPT;
682 
683  /// Return the major axis of the box. The major axis is the dimension with
684  /// the greatest difference between maximum and minimum.
685  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 unsigned int
686  majorAxis () const IMATH_NOEXCEPT;
687 
688  /// Return true if the box is empty, false otherwise. An empty box's
689  /// minimum is greater than its maximum.
690  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool isEmpty () const IMATH_NOEXCEPT;
691 
692  /// Return true if the box is larger than a single point, false otherwise.
693  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool hasVolume () const IMATH_NOEXCEPT;
694 
695  /// Return true if the box contains all points, false otherwise.
696  /// An infinite box has a mimimum of`V::baseTypeMin()`
697  /// and a maximum of `V::baseTypeMax()`.
698  IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool isInfinite () const IMATH_NOEXCEPT;
699 };
700 
701 //----------------
702 // Implementation
703 //----------------
704 
705 template <class T>
706 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline Box<Vec3<T>>::Box () IMATH_NOEXCEPT
707 {
708  makeEmpty ();
709 }
710 
711 template <class T>
712 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline Box<Vec3<T>>::Box (
713  const Vec3<T>& point) IMATH_NOEXCEPT
714 {
715  min = point;
716  max = point;
717 }
718 
719 template <class T>
720 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline Box<Vec3<T>>::Box (
721  const Vec3<T>& minT, const Vec3<T>& maxT) IMATH_NOEXCEPT
722 {
723  min = minT;
724  max = maxT;
725 }
726 
727 template <class T>
728 IMATH_HOSTDEVICE constexpr inline bool
729 Box<Vec3<T>>::operator== (const Box<Vec3<T>>& src) const IMATH_NOEXCEPT
730 {
731  return (min == src.min && max == src.max);
732 }
733 
734 template <class T>
735 IMATH_HOSTDEVICE constexpr inline bool
736 Box<Vec3<T>>::operator!= (const Box<Vec3<T>>& src) const IMATH_NOEXCEPT
737 {
738  return (min != src.min || max != src.max);
739 }
740 
741 template <class T>
742 IMATH_HOSTDEVICE inline void
744 {
747 }
748 
749 template <class T>
750 IMATH_HOSTDEVICE inline void
751 Box<Vec3<T>>::makeInfinite () IMATH_NOEXCEPT
752 {
755 }
756 
757 template <class T>
758 IMATH_HOSTDEVICE inline void
759 Box<Vec3<T>>::extendBy (const Vec3<T>& point) IMATH_NOEXCEPT
760 {
761  min.x = std::min (min.x, point.x);
762  min.y = std::min (min.y, point.y);
763  min.z = std::min (min.z, point.z);
764  max.x = std::max (max.x, point.x);
765  max.y = std::max (max.y, point.y);
766  max.z = std::max (max.z, point.z);
767 }
768 
769 template <class T>
770 IMATH_HOSTDEVICE inline void
771 Box<Vec3<T>>::extendBy (const Box<Vec3<T>>& box) IMATH_NOEXCEPT
772 {
773  min.x = std::min (min.x, box.min.x);
774  min.y = std::min (min.y, box.min.y);
775  min.z = std::min (min.z, box.min.z);
776  max.x = std::max (max.x, box.max.x);
777  max.y = std::max (max.y, box.max.y);
778  max.z = std::max (max.z, box.max.z);
779 }
780 
781 template <class T>
782 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
784 {
785  return (point.x >= min.x) && (point.x <= max.x) &&
786  (point.y >= min.y) && (point.y <= max.y) &&
787  (point.z >= min.z) && (point.z <= max.z);
788 }
789 
790 template <class T>
791 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
793 {
794  return (box.min.x <= max.x) && (box.max.x >= min.x) &&
795  (box.min.y <= max.y) && (box.max.y >= min.y) &&
796  (box.min.z <= max.z) && (box.max.z >= min.z);
797 }
798 
799 template <class T>
800 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline Vec3<T>
802 {
803  if (isEmpty ()) return Vec3<T> (0);
804 
805  return max - min;
806 }
807 
808 template <class T>
809 IMATH_HOSTDEVICE constexpr inline Vec3<T>
810 Box<Vec3<T>>::center () const IMATH_NOEXCEPT
811 {
812  return (max + min) / 2;
813 }
814 
815 template <class T>
816 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
817 Box<Vec3<T>>::isEmpty () const IMATH_NOEXCEPT
818 {
819  return (max.x < min.x || max.y < min.y || max.z < min.z);
820 }
821 
822 template <class T>
823 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
825 {
826  if (min.x != std::numeric_limits<T>::lowest () ||
828  min.y != std::numeric_limits<T>::lowest () ||
830  min.z != std::numeric_limits<T>::lowest () ||
832  return false;
833 
834  return true;
835 }
836 
837 template <class T>
838 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
839 Box<Vec3<T>>::hasVolume () const IMATH_NOEXCEPT
840 {
841  if (max.x <= min.x || max.y <= min.y || max.z <= min.z) return false;
842 
843  return true;
844 }
845 
846 template <class T>
847 IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline unsigned int
848 Box<Vec3<T>>::majorAxis () const IMATH_NOEXCEPT
849 {
850  Vec3<T> s = size ();
851 
852  if (s.x >= s.y)
853  return (s.x >= s.z) ? 0 : 2;
854  return (s.y >= s.z) ? 1 : 2;
855 }
856 
857 IMATH_INTERNAL_NAMESPACE_HEADER_EXIT
858 
859 #endif // INCLUDED_IMATHBOX_H
IMATH_HOSTDEVICE constexpr bool operator!=(const Box< V > &src) const IMATH_NOEXCEPT
Inequality.
Definition: ImathBox.h:211
Vec2< T > max
The maximum value of the box.
Definition: ImathBox.h:372
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 V size() const IMATH_NOEXCEPT
Definition: ImathBox.h:282
T z
Definition: ImathVec.h:368
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool intersects(const V &point) const IMATH_NOEXCEPT
Return true if the given point is inside the box, false otherwise.
Definition: ImathBox.h:258
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Box() IMATH_NOEXCEPT
Definition: ImathBox.h:181
#define IMATH_NOEXCEPT
Definition: ImathConfig.h:78
Definition: ImathVec.h:40
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:632
Vec2< T > min
The minimum value of the box.
Definition: ImathBox.h:369
IMATH_HOSTDEVICE void makeEmpty() IMATH_NOEXCEPT
Definition: ImathBox.h:218
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool isEmpty() const IMATH_NOEXCEPT
Definition: ImathBox.h:298
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 unsigned int majorAxis() const IMATH_NOEXCEPT
Definition: ImathBox.h:335
IMATH_HOSTDEVICE void extendBy(const V &point) IMATH_NOEXCEPT
Extend the box to include the given point.
Definition: ImathBox.h:234
GLdouble s
Definition: glad.h:3009
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
#define IMATH_HOSTDEVICE
Definition: ImathConfig.h:108
IMATH_HOSTDEVICE void makeInfinite() IMATH_NOEXCEPT
Make the box include the entire range of V.
Definition: ImathBox.h:226
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool isInfinite() const IMATH_NOEXCEPT
Definition: ImathBox.h:310
T x
Definition: ImathVec.h:59
V max
The maximum value of the box.
Definition: ImathBox.h:47
T x
Definition: ImathVec.h:368
T y
Definition: ImathVec.h:59
bool isInfinite(const float x)
Return true if x is an infinity value (either positive infinity or negative infinity).
Definition: Math.h:402
Vec3< T > max
The maximum value of the box.
Definition: ImathBox.h:624
V min
The minimum value of the box.
Definition: ImathBox.h:44
Vec3< T > min
The minimum value of the box.
Definition: ImathBox.h:621
IMATH_HOSTDEVICE static constexpr T baseTypeMax() IMATH_NOEXCEPT
Largest possible positive value.
Definition: ImathVec.h:325
IMATH_HOSTDEVICE static constexpr T baseTypeMax() IMATH_NOEXCEPT
Largest possible positive value.
Definition: ImathVec.h:658
IMATH_HOSTDEVICE static constexpr T baseTypeLowest() IMATH_NOEXCEPT
Largest possible negative value.
Definition: ImathVec.h:319
GLsizeiptr size
Definition: glcorearb.h:664
Definition: ImathVec.h:39
IMATH_HOSTDEVICE constexpr bool operator==(const Box< V > &src) const IMATH_NOEXCEPT
Equality.
Definition: ImathBox.h:204
IMATH_HOSTDEVICE static constexpr T baseTypeLowest() IMATH_NOEXCEPT
Largest possible negative value.
Definition: ImathVec.h:652
#define IMATH_EXPORT_TEMPLATE_TYPE
Definition: ImathExport.h:61
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
IMATH_HOSTDEVICE constexpr V center() const IMATH_NOEXCEPT
Definition: ImathBox.h:291
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool hasVolume() const IMATH_NOEXCEPT
Return true if the box is larger than a single point, false otherwise.
Definition: ImathBox.h:323
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool intersects(const Box< Vec3< T >> &b, const Line3< T > &r, Vec3< T > &ip) IMATH_NOEXCEPT
Definition: ImathBoxAlgo.h:649
T y
Definition: ImathVec.h:368
Definition: ImathBox.h:37
GLenum src
Definition: glcorearb.h:1793