12 #ifndef MI_MATH_BBOX_H
13 #define MI_MATH_BBOX_H
47 template <
typename T, Size DIM>
74 template <
typename T, Size DIM>
116 for(
Size i = 0; i < DIM; i++) {
209 template <
typename InputIterator>
216 template <
typename T2>
283 for(
Size i = 0; i < DIM; i++) {
301 for(
Size i = 0; i < DIM; i++)
302 rank += (
min[i] <
max[i]);
327 for(
Size i = 0; i < DIM; i++) {
328 if( vec[i] <
min[i] || vec[i] >
max[i])
338 for(
Size i = 0; i < DIM; i++) {
366 template <
typename InputIterator>
415 for(
Size i = 1; i < DIM; i++)
416 vol *= base::max MI_PREVENT_MACRO_EXPAND ( T(0), diag[i]);
437 for(
Size i = 1; i < DIM; i++) {
438 if (maxval < diag[i]) {
457 template <
typename T, Size DIM>
462 for(
Size i = 0; i < DIM; i++) {
463 (result.min)[i] = (bbox.
min)[i] - value;
464 (result.max)[i] = (bbox.
max)[i] + value;
473 template <
typename T, Size DIM>
478 for(
Size i = 0; i < DIM; i++) {
479 (result.min)[i] = (bbox.
min)[i] + value;
480 (result.max)[i] = (bbox.
max)[i] - value;
489 template <
typename T, Size DIM>
494 for(
Size i = 0; i < DIM; i++) {
495 (result.min)[i] = (bbox.
min)[i] * factor;
496 (result.max)[i] = (bbox.
max)[i] * factor;
505 template <
typename T, Size DIM>
511 for(
Size i = 0; i < DIM; i++) {
512 (result.
min)[i] = (bbox.
min)[i] / divisor;
513 (result.
max)[i] = (bbox.
max)[i] / divisor;
522 template <
typename T, Size DIM>
526 for(
Size i = 0; i < DIM; i++) {
527 (bbox.
min)[i] -= value;
528 (bbox.
max)[i] += value;
537 template <
typename T, Size DIM>
541 for(
Size i = 0; i < DIM; i++) {
542 (bbox.
min)[i] += value;
543 (bbox.
max)[i] -= value;
551 template <
typename T, Size DIM>
555 for(
Size i = 0; i < DIM; i++) {
556 (bbox.
min)[i] *= factor;
557 (bbox.
max)[i] *= factor;
565 template <
typename T, Size DIM>
570 for(
Size i = 0; i < DIM; i++) {
571 (bbox.
min)[i] /= divisor;
572 (bbox.
max)[i] /= divisor;
578 template <
typename T, Size DIM>
581 return (lhs.
min) == (rhs.
min) && (lhs.
max) == (rhs.
max);
585 template <
typename T, Size DIM>
588 return (lhs.
min) != (rhs.
min) || (lhs.
max) != (rhs.
max);
594 template <
typename T, Size DIM>
595 inline bool operator< ( const Bbox<T,DIM> & lhs,
const Bbox<T,DIM> & rhs)
597 for(
Size i = 0; i < DIM; i++) {
598 if ( (lhs.min)[i] < (rhs.min)[i])
600 if ( (lhs.min)[i] > (rhs.min)[i])
603 for(
Size i = 0; i < DIM; i++) {
604 if ( lhs.max[i] < rhs.max[i])
606 if ( lhs.max[i] > rhs.max[i])
615 template <
typename T, Size DIM>
616 inline bool operator<=( const Bbox<T,DIM>& lhs,
const Bbox<T,DIM>& rhs)
618 return ! (rhs < lhs);
624 template <
typename T, Size DIM>
633 template <
typename T, Size DIM>
636 return ! (lhs < rhs);
647 template <
typename T, Size DIM>
662 template <
typename T, Size DIM>
668 for(
Size i = 0; i < DIM; i++) {
671 if (result.
max[i] < result.
min[i]) {
692 template <
typename TT,
typename T>
693 Bbox<T,3>
transform_point(
const Matrix<TT,4,4>& mat,
const Bbox<T,3>& bbox);
704 template <
typename TT,
typename T>
705 Bbox<T,3>
transform_vector(
const Matrix<TT,4,4>& mat,
const Bbox<T,3>& bbox);
711 #ifndef MI_FOR_DOXYGEN_ONLY
713 template <
typename T, Size DIM>
714 template <
typename InputIterator>
717 for( ; first != last; ++first)
721 template <
typename T, Size DIM>
722 template <
typename InputIterator>
726 insert( first, last);
729 template <
typename T, Size DIM>
743 for(
Size i = 0; i < DIM; i++)
748 for(
Size i = 0; i < DIM; i++)
750 const T margin = max_dist * eps;
755 #endif // MI_FOR_DOXYGEN_ONLY
757 template <
typename TT,
typename T>
772 corners[0].x += T(mat.wx);
773 corners[0].y += T(mat.wy);
774 corners[0].z += T(mat.wz);
781 corners[1] = corners[0] + dz;
782 corners[2] = corners[0] + dy;
783 corners[3] = corners[0] + dy + dz;
784 corners[4] = corners[0] + dx;
785 corners[5] = corners[0] + dx + dz;
786 corners[6] = corners[0] + dx + dy;
787 corners[7] = corners[0] + dx + dy + dz;
793 T wx = T( mat.xw * ((bbox.
max).x - (bbox.
min).x));
794 T wy = T( mat.yw * ((bbox.
max).y - (bbox.
min).y));
795 T wz = T( mat.zw * ((bbox.
max).z - (bbox.
min).z));
798 w[0] = T(mat.xw * (bbox.
min).x + mat.yw * (bbox.
min).y + mat.zw * (bbox.
min).z + mat.ww);
801 w[3] = w[0] + wy + wz;
803 w[5] = w[0] + wx + wz;
804 w[6] = w[0] + wx + wy;
805 w[7] = w[0] + wx + wy + wz;
808 for(
unsigned int i=0; i<8; ++i) {
809 if( w[i]!=0 && w[i]!=1) {
820 template <
typename TT,
typename T>
834 corners[1] = corners[0] + dz;
835 corners[2] = corners[0] + dy;
836 corners[3] = corners[0] + dy + dz;
837 corners[4] = corners[0] + dx;
838 corners[5] = corners[0] + dx + dz;
839 corners[6] = corners[0] + dx + dy;
840 corners[7] = corners[0] + dx + dy + dz;
852 #endif // MI_MATH_BBOX_H