10 #ifndef INCLUDED_IMATHBOXALGO_H
11 #define INCLUDED_IMATHBOXALGO_H
20 IMATH_INTERNAL_NAMESPACE_HEADER_ENTER
33 for (
int i = 0; i <
int (box.min.dimensions()); i++)
35 if (p[i] < box.min[i])
37 else if (p[i] > box.max[i])
80 (d1.
y < d2.
y) ? d1.
y : d2.
y,
81 (d1.
z < d2.
z) ? d1.
z : d2.
z);
83 if (d.
x < d.
y && d.
x < d.
z)
85 q.
x = (d1.
x < d2.
x) ? box.min.x : box.max.x;
89 q.
y = (d1.
y < d2.
y) ? box.min.y : box.max.y;
93 q.
z = (d1.
z < d2.
z) ? box.min.z : box.max.z;
112 template <
class S,
class T>
116 if (box.isEmpty() || box.isInfinite())
124 if (m[0][3] == 0 && m[1][3] == 0 && m[2][3] == 0 && m[3][3] == 1)
128 for (
int i = 0; i < 3; i++)
130 newBox.
min[i] = newBox.
max[i] = (
S) m[3][i];
132 for (
int j = 0;
j < 3;
j++)
136 a = (
S) m[
j][i] * box.min[
j];
137 b = (
S) m[
j][i] * box.max[
j];
163 points[0][0] = points[1][0] = points[2][0] = points[3][0] = box.min[0];
164 points[4][0] = points[5][0] = points[6][0] = points[7][0] = box.max[0];
166 points[0][1] = points[1][1] = points[4][1] = points[5][1] = box.min[1];
167 points[2][1] = points[3][1] = points[6][1] = points[7][1] = box.max[1];
169 points[0][2] = points[2][2] = points[4][2] = points[6][2] = box.min[2];
170 points[1][2] = points[3][2] = points[5][2] = points[7][2] = box.max[2];
174 for (
int i = 0; i < 8; i++)
193 template <
class S,
class T>
197 if (box.isEmpty() || box.isInfinite())
207 if (m[0][3] == 0 && m[1][3] == 0 && m[2][3] == 0 && m[3][3] == 1)
209 for (
int i = 0; i < 3; i++)
213 for (
int j = 0;
j < 3;
j++)
217 a = (
S) m[
j][i] * box.min[
j];
218 b = (
S) m[
j][i] * box.max[
j];
244 points[0][0] = points[1][0] = points[2][0] = points[3][0] = box.min[0];
245 points[4][0] = points[5][0] = points[6][0] = points[7][0] = box.max[0];
247 points[0][1] = points[1][1] = points[4][1] = points[5][1] = box.min[1];
248 points[2][1] = points[3][1] = points[6][1] = points[7][1] = box.max[1];
250 points[0][2] = points[2][2] = points[4][2] = points[6][2] = box.min[2];
251 points[1][2] = points[3][2] = points[5][2] = points[7][2] = box.max[2];
253 for (
int i = 0; i < 8; i++)
254 result.extendBy (points[i] * m);
268 template <
class S,
class T>
272 if (box.isEmpty() || box.isInfinite())
277 for (
int i = 0; i < 3; i++)
279 newBox.
min[i] = newBox.
max[i] = (
S) m[3][i];
281 for (
int j = 0;
j < 3;
j++)
285 a = (
S) m[
j][i] * box.min[
j];
286 b = (
S) m[
j][i] * box.max[
j];
316 template <
class S,
class T>
326 if (box.isInfinite())
332 for (
int i = 0; i < 3; i++)
336 for (
int j = 0;
j < 3;
j++)
340 a = (
S) m[
j][i] * box.min[
j];
341 b = (
S) m[
j][i] * box.max[
j];
412 T d1 =
b.max.x -
r.pos.x;
413 T d2 =
b.min.x -
r.pos.x;
415 if (
r.dir.x > 1 || (
abs (d1) < TMAX *
r.dir.x &&
abs (d2) < TMAX *
r.dir.x))
425 exit.y =
clamp (
r.pos.y + t1 *
r.dir.y,
b.min.y,
b.max.y);
426 exit.z =
clamp (
r.pos.z + t1 *
r.dir.z,
b.min.z,
b.max.z);
434 entry.y =
clamp (
r.pos.y + t2 *
r.dir.y,
b.min.y,
b.max.y);
435 entry.z =
clamp (
r.pos.z + t2 *
r.dir.z,
b.min.z,
b.max.z);
438 else if (
r.pos.x <
b.min.x ||
r.pos.x >
b.max.x)
445 T d1 =
b.min.x -
r.pos.x;
446 T d2 =
b.max.x -
r.pos.x;
448 if (
r.dir.x < -1 || (
abs (d1) < -TMAX *
r.dir.x &&
abs (d2) < -TMAX *
r.dir.x))
458 exit.y =
clamp (
r.pos.y + t1 *
r.dir.y,
b.min.y,
b.max.y);
459 exit.z =
clamp (
r.pos.z + t1 *
r.dir.z,
b.min.z,
b.max.z);
467 entry.y =
clamp (
r.pos.y + t2 *
r.dir.y,
b.min.y,
b.max.y);
468 entry.z =
clamp (
r.pos.z + t2 *
r.dir.z,
b.min.z,
b.max.z);
471 else if (
r.pos.x <
b.min.x ||
r.pos.x >
b.max.x)
483 T d1 =
b.max.y -
r.pos.y;
484 T d2 =
b.min.y -
r.pos.y;
486 if (
r.dir.y > 1 || (
abs (d1) < TMAX *
r.dir.y &&
abs (d2) < TMAX *
r.dir.y))
495 exit.x =
clamp (
r.pos.x + t1 *
r.dir.x,
b.min.x,
b.max.x);
497 exit.z =
clamp (
r.pos.z + t1 *
r.dir.z,
b.min.z,
b.max.z);
504 entry.x =
clamp (
r.pos.x + t2 *
r.dir.x,
b.min.x,
b.max.x);
506 entry.z =
clamp (
r.pos.z + t2 *
r.dir.z,
b.min.z,
b.max.z);
509 else if (
r.pos.y <
b.min.y ||
r.pos.y >
b.max.y)
516 T d1 =
b.min.y -
r.pos.y;
517 T d2 =
b.max.y -
r.pos.y;
519 if (
r.dir.y < -1 || (
abs (d1) < -TMAX *
r.dir.y &&
abs (d2) < -TMAX *
r.dir.y))
528 exit.x =
clamp (
r.pos.x + t1 *
r.dir.x,
b.min.x,
b.max.x);
530 exit.z =
clamp (
r.pos.z + t1 *
r.dir.z,
b.min.z,
b.max.z);
537 entry.x =
clamp (
r.pos.x + t2 *
r.dir.x,
b.min.x,
b.max.x);
539 entry.z =
clamp (
r.pos.z + t2 *
r.dir.z,
b.min.z,
b.max.z);
542 else if (
r.pos.y <
b.min.y ||
r.pos.y >
b.max.y)
554 T d1 =
b.max.z -
r.pos.z;
555 T d2 =
b.min.z -
r.pos.z;
557 if (
r.dir.z > 1 || (
abs (d1) < TMAX *
r.dir.z &&
abs (d2) < TMAX *
r.dir.z))
566 exit.x =
clamp (
r.pos.x + t1 *
r.dir.x,
b.min.x,
b.max.x);
567 exit.y =
clamp (
r.pos.y + t1 *
r.dir.y,
b.min.y,
b.max.y);
575 entry.x =
clamp (
r.pos.x + t2 *
r.dir.x,
b.min.x,
b.max.x);
576 entry.y =
clamp (
r.pos.y + t2 *
r.dir.y,
b.min.y,
b.max.y);
580 else if (
r.pos.z <
b.min.z ||
r.pos.z >
b.max.z)
587 T d1 =
b.min.z -
r.pos.z;
588 T d2 =
b.max.z -
r.pos.z;
590 if (
r.dir.z < -1 || (
abs (d1) < -TMAX *
r.dir.z &&
abs (d2) < -TMAX *
r.dir.z))
599 exit.x =
clamp (
r.pos.x + t1 *
r.dir.x,
b.min.x,
b.max.x);
600 exit.y =
clamp (
r.pos.y + t1 *
r.dir.y,
b.min.y,
b.max.y);
608 entry.x =
clamp (
r.pos.x + t2 *
r.dir.x,
b.min.x,
b.max.x);
609 entry.y =
clamp (
r.pos.y + t2 *
r.dir.y,
b.min.y,
b.max.y);
613 else if (
r.pos.z <
b.min.z ||
r.pos.z >
b.max.z)
619 return tFrontMax <= tBackMin;
653 if (
b.intersects (
r.pos))
687 if (
r.pos.x >
b.max.x)
690 T d =
b.max.x -
r.pos.x;
692 if (
r.dir.x > 1 || d < TMAX *
r.dir.x)
700 if (
r.pos.x <=
b.min.x)
702 T d =
b.min.x -
r.pos.x;
703 T t = (
r.dir.x > 1 || d < TMAX *
r.dir.x) ? d /
r.dir.x : TMAX;
710 ip.y =
clamp (
r.pos.y + t *
r.dir.y,
b.min.y,
b.max.y);
711 ip.z =
clamp (
r.pos.z + t *
r.dir.z,
b.min.z,
b.max.z);
715 else if (
r.dir.x < 0)
717 if (
r.pos.x <
b.min.x)
720 T d =
b.min.x -
r.pos.x;
722 if (
r.dir.x < -1 || d > TMAX *
r.dir.x)
730 if (
r.pos.x >=
b.max.x)
732 T d =
b.max.x -
r.pos.x;
733 T t = (
r.dir.x < -1 || d > TMAX *
r.dir.x) ? d /
r.dir.x : TMAX;
740 ip.y =
clamp (
r.pos.y + t *
r.dir.y,
b.min.y,
b.max.y);
741 ip.z =
clamp (
r.pos.z + t *
r.dir.z,
b.min.z,
b.max.z);
747 if (
r.pos.x <
b.min.x ||
r.pos.x >
b.max.x)
757 if (
r.pos.y >
b.max.y)
760 T d =
b.max.y -
r.pos.y;
762 if (
r.dir.y > 1 || d < TMAX *
r.dir.y)
770 if (
r.pos.y <=
b.min.y)
772 T d =
b.min.y -
r.pos.y;
773 T t = (
r.dir.y > 1 || d < TMAX *
r.dir.y) ? d /
r.dir.y : TMAX;
779 ip.x =
clamp (
r.pos.x + t *
r.dir.x,
b.min.x,
b.max.x);
781 ip.z =
clamp (
r.pos.z + t *
r.dir.z,
b.min.z,
b.max.z);
785 else if (
r.dir.y < 0)
787 if (
r.pos.y <
b.min.y)
790 T d =
b.min.y -
r.pos.y;
792 if (
r.dir.y < -1 || d > TMAX *
r.dir.y)
800 if (
r.pos.y >=
b.max.y)
802 T d =
b.max.y -
r.pos.y;
803 T t = (
r.dir.y < -1 || d > TMAX *
r.dir.y) ? d /
r.dir.y : TMAX;
809 ip.x =
clamp (
r.pos.x + t *
r.dir.x,
b.min.x,
b.max.x);
811 ip.z =
clamp (
r.pos.z + t *
r.dir.z,
b.min.z,
b.max.z);
817 if (
r.pos.y <
b.min.y ||
r.pos.y >
b.max.y)
827 if (
r.pos.z >
b.max.z)
830 T d =
b.max.z -
r.pos.z;
832 if (
r.dir.z > 1 || d < TMAX *
r.dir.z)
840 if (
r.pos.z <=
b.min.z)
842 T d =
b.min.z -
r.pos.z;
843 T t = (
r.dir.z > 1 || d < TMAX *
r.dir.z) ? d /
r.dir.z : TMAX;
849 ip.x =
clamp (
r.pos.x + t *
r.dir.x,
b.min.x,
b.max.x);
850 ip.y =
clamp (
r.pos.y + t *
r.dir.y,
b.min.y,
b.max.y);
855 else if (
r.dir.z < 0)
857 if (
r.pos.z <
b.min.z)
860 T d =
b.min.z -
r.pos.z;
862 if (
r.dir.z < -1 || d > TMAX *
r.dir.z)
870 if (
r.pos.z >=
b.max.z)
872 T d =
b.max.z -
r.pos.z;
873 T t = (
r.dir.z < -1 || d > TMAX *
r.dir.z) ? d /
r.dir.z : TMAX;
879 ip.x =
clamp (
r.pos.x + t *
r.dir.x,
b.min.x,
b.max.x);
880 ip.y =
clamp (
r.pos.y + t *
r.dir.y,
b.min.y,
b.max.y);
887 if (
r.pos.z <
b.min.z ||
r.pos.z >
b.max.z)
891 return tFrontMax <= tBackMin;
906 IMATH_INTERNAL_NAMESPACE_HEADER_EXIT
908 #endif // INCLUDED_IMATHBOXALGO_H
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
GLdouble GLdouble GLint GLint const GLdouble * points
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool findEntryAndExitPoints(const Line3< T > &r, const Box< Vec3< T >> &b, Vec3< T > &entry, Vec3< T > &exit) IMATH_NOEXCEPT
IMATH_HOSTDEVICE constexpr T closestPointInBox(const T &p, const Box< T > &box) IMATH_NOEXCEPT
IMATH_HOSTDEVICE void extendBy(const V &point) IMATH_NOEXCEPT
Extend the box to include the given point.
GLboolean GLboolean GLboolean GLboolean a
**But if you need a result
GLdouble GLdouble GLdouble q
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Vec3< T > closestPointOnBox(const Vec3< T > &p, const Box< Vec3< T >> &box) IMATH_NOEXCEPT
IMATH_HOSTDEVICE Box< Vec3< S > > transform(const Box< Vec3< S >> &box, const Matrix44< T > &m) IMATH_NOEXCEPT
V max
The maximum value of the box.
V min
The minimum value of the box.
GLboolean GLboolean GLboolean b
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool intersects(const Box< Vec3< T >> &b, const Line3< T > &r, Vec3< T > &ip) IMATH_NOEXCEPT
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER IMATH_HOSTDEVICE constexpr T abs(T a) IMATH_NOEXCEPT
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER IMATH_HOSTDEVICE IMATH_CONSTEXPR14 T clip(const T &p, const Box< T > &box) IMATH_NOEXCEPT
IMATH_HOSTDEVICE Box< Vec3< S > > affineTransform(const Box< Vec3< S >> &box, const Matrix44< T > &m) IMATH_NOEXCEPT