45template <
typename T, Size DIM>
72template <
typename T, Size DIM>
114 for(
Size i = 0; i < DIM; i++) {
131#if (__cplusplus >= 201103L)
209 template <
typename InputIterator>
216 template <
typename T2>
225 template <
typename T2>
292 for(
Size i = 0; i < DIM; i++) {
310 for(
Size i = 0; i < DIM; i++)
336 for(
Size i = 0; i < DIM; i++) {
337 if( vec[i] <
min[i] || vec[i] >
max[i])
347 for(
Size i = 0; i < DIM; i++) {
375 template <
typename InputIterator>
424 for(
Size i = 1; i < DIM; i++)
446 for(
Size i = 1; i < DIM; i++) {
447 if (maxval < diag[i]) {
469template <
typename T, Size DIM>
474 for(
Size i = 0; i < DIM; i++) {
475 (result.
min)[i] = (bbox.
min)[i] - value;
476 (result.
max)[i] = (bbox.
max)[i] + value;
485template <
typename T, Size DIM>
490 for(
Size i = 0; i < DIM; i++) {
491 (result.
min)[i] = (bbox.
min)[i] + value;
492 (result.
max)[i] = (bbox.
max)[i] - value;
501template <
typename T, Size DIM>
506 for(
Size i = 0; i < DIM; i++) {
507 (result.
min)[i] = (bbox.
min)[i] * factor;
508 (result.
max)[i] = (bbox.
max)[i] * factor;
517template <
typename T, Size DIM>
523 for(
Size i = 0; i < DIM; i++) {
524 (result.
min)[i] = (bbox.
min)[i] / divisor;
525 (result.
max)[i] = (bbox.
max)[i] / divisor;
534template <
typename T, Size DIM>
538 for(
Size i = 0; i < DIM; i++) {
539 (bbox.
min)[i] -= value;
540 (bbox.
max)[i] += value;
549template <
typename T, Size DIM>
553 for(
Size i = 0; i < DIM; i++) {
554 (bbox.
min)[i] += value;
555 (bbox.
max)[i] -= value;
563template <
typename T, Size DIM>
567 for(
Size i = 0; i < DIM; i++) {
568 (bbox.
min)[i] *= factor;
569 (bbox.
max)[i] *= factor;
577template <
typename T, Size DIM>
582 for(
Size i = 0; i < DIM; i++) {
583 (bbox.
min)[i] /= divisor;
584 (bbox.
max)[i] /= divisor;
590template <
typename T, Size DIM>
593 return (lhs.
min) == (rhs.
min) && (lhs.
max) == (rhs.
max);
597template <
typename T, Size DIM>
600 return (lhs.
min) != (rhs.
min) || (lhs.
max) != (rhs.
max);
606template <
typename T, Size DIM>
609 for(
Size i(0u); i < DIM; ++i) {
610 if( (lhs.
min)[i] < (rhs.
min)[i])
612 if( (lhs.
min)[i] > (rhs.
min)[i])
621template <
typename T, Size DIM>
624 for(
Size i(0u); i < DIM; ++i) {
625 if( (lhs.
min)[i] < (rhs.
min)[i])
627 if( (lhs.
min)[i] > (rhs.
min)[i])
636template <
typename T, Size DIM>
639 for(
Size i(0u); i < DIM; ++i) {
640 if( (lhs.
min)[i] > (rhs.
min)[i])
642 if( (lhs.
min)[i] < (rhs.
min)[i])
651template <
typename T, Size DIM>
654 for(
Size i(0u); i < DIM; ++i) {
655 if( (lhs.
min)[i] > (rhs.
min)[i])
657 if( (lhs.
min)[i] < (rhs.
min)[i])
671template <
typename T, Size DIM>
686template <
typename T, Size DIM>
692 for(
Size i = 0; i < DIM; i++) {
695 if (result.
max[i] < result.
min[i]) {
716template <
typename TT,
typename T>
717Bbox<T,3>
transform_point(
const Matrix<TT,4,4>& mat,
const Bbox<T,3>& bbox);
728template <
typename TT,
typename T>
729Bbox<T,3>
transform_vector(
const Matrix<TT,4,4>& mat,
const Bbox<T,3>& bbox);
735#ifndef MI_FOR_DOXYGEN_ONLY
737template <
typename T, Size DIM>
738template <
typename InputIterator>
741 for( ; first != last; ++first)
745template <
typename T, Size DIM>
746template <
typename InputIterator>
750 insert( first, last);
753template <
typename T, Size DIM>
767 for(
Size i = 0; i < DIM; i++)
772 for(
Size i = 0; i < DIM; i++)
774 const T margin = max_dist * eps;
781template <
typename TT,
typename T>
796 corners[0].x += T(mat.wx);
797 corners[0].y += T(mat.wy);
798 corners[0].z += T(mat.wz);
805 corners[1] = corners[0] + dz;
806 corners[2] = corners[0] + dy;
807 corners[3] = corners[0] + dy + dz;
808 corners[4] = corners[0] + dx;
809 corners[5] = corners[0] + dx + dz;
810 corners[6] = corners[0] + dx + dy;
811 corners[7] = corners[0] + dx + dy + dz;
817 T wx = T( mat.xw * ((bbox.
max).x - (bbox.
min).x));
818 T wy = T( mat.yw * ((bbox.
max).y - (bbox.
min).y));
819 T wz = T( mat.zw * ((bbox.
max).z - (bbox.
min).z));
822 w[0] = T(mat.xw * (bbox.
min).x + mat.yw * (bbox.
min).y + mat.zw * (bbox.
min).z + mat.ww);
825 w[3] = w[0] + wy + wz;
827 w[5] = w[0] + wx + wz;
828 w[6] = w[0] + wx + wy;
829 w[7] = w[0] + wx + wy + wz;
832 for(
unsigned int i=0; i<8; ++i) {
833 if( w[i]!=0 && w[i]!=1) {
844template <
typename TT,
typename T>
858 corners[1] = corners[0] + dz;
859 corners[2] = corners[0] + dy;
860 corners[3] = corners[0] + dy + dz;
861 corners[4] = corners[0] + dx;
862 corners[5] = corners[0] + dx + dz;
863 corners[6] = corners[0] + dx + dy;
864 corners[7] = corners[0] + dx + dy + dz;
Axis-aligned N-dimensional bounding box class template of fixed dimension.
Definition: bbox.h:74
NxM-dimensional matrix class template of fixed dimensions.
Definition: matrix.h:367
Fixed-size math vector class template with generic operations.
Definition: vector.h:286
Math functions and function templates on simple types or generic container and vector concepts.
#define mi_static_assert(expr)
Compile time assertion that raises a compilation error if the constant expression expr evaluates to f...
Definition: assert.h:58
#define MI_PREVENT_MACRO_EXPAND
Empty macro that can be used after function names to prevent macro expansion that happen to have the ...
Definition: config.h:97
static T negative_max()
Returns the smallest finite negative value for T.
Definition: types.h:404
Sint64 Difference
Signed integral type that is large enough to hold the difference of two pointers.
Definition: types.h:122
Uint64 Size
Unsigned integral type that is large enough to hold the size of all types.
Definition: types.h:112
bool lexicographically_less(const V &lhs, const V &rhs)
Returns true if vector lhs is lexicographically less than vector rhs, and false otherwise.
Definition: function.h:1174
bool lexicographically_less_or_equal(const V &lhs, const V &rhs)
Returns true if vector lhs is lexicographically less than or equal to vector rhs, and false otherwise...
Definition: function.h:1190
bool lexicographically_greater_or_equal(const V &lhs, const V &rhs)
Returns true if vector lhs is lexicographically greater than or equal to vector rhs,...
Definition: function.h:1222
Float32 length(Float32 a)
Returns the Euclidean norm of the scalar a (its absolute value).
Definition: function.h:1107
bool lexicographically_greater(const V &lhs, const V &rhs)
Returns true if vector lhs is lexicographically greater than vector rhs, and false otherwise.
Definition: function.h:1206
#define mi_math_assert_msg(expr, msg)
Math API assertion macro (with message).
Definition: assert.h:80
bool operator>=(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is lexicographically greater than or equal to rhs.
Definition: bbox.h:652
Bbox(Uninitialized_tag)
Bounding box with its elements not initialized.
Definition: bbox.h:129
Bbox(T min_x, T min_y, T max_x, T max_y)
2D bounding box (interval) initialized to the new extreme corner vectors, (min_x,min_y) and (max_x,...
Definition: bbox.h:174
Vector max
Elementwise maximal bounding box corner.
Definition: bbox.h:104
Bbox<T, DIM> operator+(const Bbox<T, DIM> &bbox, T value)
Returns a bounding box that is the bbox increased by a constant value at each face,...
Definition: bbox.h:470
Vector extent() const
Returns the size of the bounding box.
Definition: bbox.h:459
void insert(InputIterator first, InputIterator last)
Inserts a range [first,last) of items into this bounding box.
bool operator<(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is lexicographically less than rhs.
Definition: bbox.h:607
Bbox add_motionbox(const Bbox &vbox, T t) const
Returns the translation of this bounding box by vectors that are inside the scaled bounding box of ve...
Definition: bbox.h:388
Bbox(const Vector &nmin, const Vector &nmax)
Bounding box initialized to the new extreme corner vectors, nmin and nmax.
Definition: bbox.h:150
void insert(const Vector &point)
Assigns the union of this bounding box and the point to this bounding box.
Definition: bbox.h:362
Bbox()
Bounding box initialized to the empty space, see also the clear function.
Definition: bbox.h:126
void robust_grow(T eps=T(1.0e-5f))
Robustly grows the bounding box by a value computed automatically from the bounding box dimensions an...
Bbox(const Bbox<T2, DIM> &other)
Template constructor that allows explicit conversions from other bounding boxes with assignment compa...
Definition: bbox.h:217
Vector center() const
Returns the center point of the bounding box.
Definition: bbox.h:456
bool is_volume() const
Returns true the bounding box has a volume.
Definition: bbox.h:331
Bbox<T, DIM> & operator*=(Bbox<T, DIM> &bbox, T factor)
Scales bbox by factor, i.e., bbox.max and bbox.min are multiplied by factor.
Definition: bbox.h:564
Bbox(const Vector &point)
Bounding box initialized to a single point.
Definition: bbox.h:144
void push_back(const Bbox &other)
Assigns the union of this bounding box and the other bounding box to this bounding box.
Definition: bbox.h:403
const Vector & const_reference
Const reference to vector.
Definition: bbox.h:84
Bbox<T, DIM> & operator+=(Bbox<T, DIM> &bbox, T value)
Increases bbox by a constant value at each face, i.e., value is added to bbox.max and subtracted from...
Definition: bbox.h:535
static const Size DIMENSION
Constant dimension of the vectors.
Definition: bbox.h:86
bool is_line() const
Returns true the bounding box is an axis-aligned line.
Definition: bbox.h:321
const Vector * end() const
Returns the past-the-end pointer.
Definition: bbox.h:271
Vector & operator[](Size i)
Returns the vector min for i==0, and the vector max for i==1.
Definition: bbox.h:274
Vector min
Elementwise minimal bounding box corner.
Definition: bbox.h:103
Bbox(const Bbox_struct<T2, DIM> &other)
Template constructor that allows explicit conversions from other POD type with assignment compatible ...
Definition: bbox.h:226
Bbox(T min_x, T min_y, T min_z, T max_x, T max_y, T max_z)
3D bounding box (interval) initialized to the new extreme corner vectors, (min_x,min_y,...
Definition: bbox.h:189
Bbox & operator=(const Bbox_struct<T, DIM> &other)
Assignment from corresponding POD type.
Definition: bbox.h:241
bool operator==(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is elementwise equal to rhs.
Definition: bbox.h:591
Bbox & operator=(const Bbox &other)
Assignment.
Definition: bbox.h:233
static Size max_size()
Constant maximum size of the bounding box.
Definition: bbox.h:93
Size size_type
Size type, unsigned.
Definition: bbox.h:79
Vector * end()
Returns the past-the-end pointer.
Definition: bbox.h:266
T volume() const
Returns the volume of the bounding box.
Definition: bbox.h:420
bool operator>(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is lexicographically greater than rhs.
Definition: bbox.h:637
Bbox<T, DIM> & operator/=(Bbox<T, DIM> &bbox, T divisor)
Divide bbox by divisor, i.e., bbox.max and bbox.min are divided by divisor.
Definition: bbox.h:578
Bbox(InputIterator first, InputIterator last)
Constructs a bounding box from a range [first, last) of items.
Bbox<T, DIM> operator/(const Bbox<T, DIM> &bbox, T divisor)
Returns a bounding box that is a version of bbox divided by divisor, i.e., bbox.max and bbox....
Definition: bbox.h:518
Bbox<T, DIM> clip(const Bbox<T, DIM> &bbox1, const Bbox<T, DIM> &bbox2)
Clip bbox1 at bbox2 and return the result.
Definition: bbox.h:687
bool operator!=(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is elementwise not equal to rhs.
Definition: bbox.h:598
bool empty() const
Returns true if the box is empty.
Definition: bbox.h:290
Uninitialized_tag
Enum type used to tag a special constructor that does not initialize the elements of the constructed ...
Definition: bbox.h:97
Vector * begin()
Returns the pointer to the first vector, min.
Definition: bbox.h:258
Vector value_type
Coordinate type.
Definition: bbox.h:78
bool contains(const Vector &vec) const
Returns true if the point is inside or on the boundary of the bounding box.
Definition: bbox.h:334
bool is_point() const
Returns true the bounding box is a single point.
Definition: bbox.h:316
static const Size SIZE
Constant size of the bounding box.
Definition: bbox.h:87
static Size size()
Constant size of the bounding box.
Definition: bbox.h:90
Vector_struct<T, DIM> max
Elementwise maximal bounding box corner.
Definition: bbox.h:49
void clear()
Reinitializes this bounding box to the empty space.
Definition: bbox.h:112
math::Vector<T, DIM> Vector
Corresponding vector type.
Definition: bbox.h:76
Size largest_extent_index() const
Returns the index of the dimension in which the bounding box has its largest extent,...
Definition: bbox.h:441
bool operator<=(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is lexicographically less than or equal to rhs.
Definition: bbox.h:622
Bbox_struct<T, DIM> Pod_type
POD class corresponding to this bounding box.
Definition: bbox.h:77
Bbox(T min_x, T max_x)
1D bounding box (interval) initialized to the new extreme corner vectors, (min_x) and (max_x).
Definition: bbox.h:161
bool is_plane() const
Returns true the bounding box is an axis-aligned plane.
Definition: bbox.h:326
Size rank() const
Returns the rank of the bounding box.
Definition: bbox.h:307
Vector & reference
Mutable reference to vector.
Definition: bbox.h:83
Bbox<T, 3> transform_vector(const Matrix<TT, 4, 4> &mat, const Bbox<T, 3> &bbox)
Returns the 3D bounding box transformed by a matrix.
Definition: bbox.h:845
const Vector * const_pointer
Const pointer to vector.
Definition: bbox.h:82
Bbox<T, DIM> & operator-=(Bbox<T, DIM> &bbox, T value)
Shrinks bbox by a constant value at each face, i.e., value is subtracted from bbox....
Definition: bbox.h:550
Bbox(const Bbox<T, DIM> &other)=default
Default copy constructor.
Bbox<T, 3> transform_point(const Matrix<TT, 4, 4> &mat, const Bbox<T, 3> &bbox)
Returns the 3D bounding box transformed by a matrix.
Definition: bbox.h:782
Vector_struct<T, DIM> min
Elementwise minimal bounding box corner.
Definition: bbox.h:48
const Vector & operator[](Size i) const
Returns the vector min for i==0, and the vector max for i==1.
Definition: bbox.h:281
Difference difference_type
Difference type, signed.
Definition: bbox.h:80
Vector * pointer
Mutable pointer to vector.
Definition: bbox.h:81
Bbox(const Bbox_struct<T, DIM> &bbox_struct)
Bounding box initialized from corresponding POD type.
Definition: bbox.h:137
void insert(const Bbox &other)
Assigns the union of this bounding box and the other bounding box to this bounding box.
Definition: bbox.h:355
bool intersects(const Bbox &other) const
Returns true if this bounding box and the other bounding box intersect in their interiors or on their...
Definition: bbox.h:345
const Vector * begin() const
Returns the pointer to the first vector, min.
Definition: bbox.h:261
T diagonal_length() const
Returns the length of the diagonal.
Definition: bbox.h:432
Bbox<T, DIM> operator-(const Bbox<T, DIM> &bbox, T value)
Returns a bounding box that is the bbox shrunk by a constant value at each face, i....
Definition: bbox.h:486
Bbox<T, DIM> operator*(const Bbox<T, DIM> &bbox, T factor)
Returns a bounding box that is a version of bbox scaled by factor, i.e., bbox.max and bbox....
Definition: bbox.h:502
Bbox<T, DIM> lerp(const Bbox<T, DIM> &bbox1, const Bbox<T, DIM> &bbox2, T t)
Returns the linear interpolation between bbox1 and bbox2, i.e., it returns (1-t) * bbox1 + t * bbox2.
Definition: bbox.h:672
@ UNINITIALIZED_TAG
Enum value used to call a special constructor that does not initialize the elements of the constructe...
Definition: bbox.h:100
Color abs(const Color &c)
Returns a color with the elementwise absolute values of the color c.
Definition: color.h:471
Color elementwise_min(const Color &lhs, const Color &rhs)
Returns elementwise min for each element in color lhs that is less than the corresponding element in ...
Definition: color.h:581
Color elementwise_max(const Color &lhs, const Color &rhs)
Returns elementwise max for each element in color lhs that is less than the corresponding element in ...
Definition: color.h:571
Assertions and compile-time assertions.
A NxM-dimensional matrix class template of fixed dimensions with supporting functions.
Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH.
Definition: math.h:22
Helper class to deduce properties of numeric types defined in this API.
Definition: types.h:428
Storage class for an axis-aligned N-dimensional bounding box class template of fixed dimension.
Definition: bbox.h:47
Generic storage class template for math vector representations storing DIM elements of type T.
Definition: vector.h:135
Math vector class template of fixed dimension with arithmetic operators and generic functions.