38 #ifndef RiTypesHelper_h 39 #define RiTypesHelper_h 65 #include "pxrcore/ustring/ustring.h" 66 #include "pxrcore/paramlist/types.h" 69 static_assert(
sizeof(
RtFloat3) ==
sizeof(
float[3]),
"ensure compat with legacy c-layout");
88 inline RtFloat2(
float xx,
float yy) : x(xx), y(yy) {}
89 explicit inline RtFloat2(
float v) : x(v), y(v) {}
92 explicit inline RtFloat2(
const float *d) : x(d[0]), y(d[1]) {}
97 assert(i >= 0 && i<2);
102 assert(i >= 0 && i<2);
109 return x == rhs.
x && y == rhs.
y;
113 return x != rhs.
x || y != rhs.
y;
119 return (x < rhs.
x ?
true :
133 o << v.
x <<
" " << v.
y ;
205 float inv = 1.0f / rhs;
210 float inv = 1.0f / rhs;
228 return (1.0f-eps <= len && len <= 1.0f+eps);
237 len = std::sqrt(len);
272 return x * v2.
x + y * v2.
y;
282 return std::abs(this->
Dot(v2));
292 return x * v2.
y - y * v2.
x;
301 return (x + y) * .5f;
306 return std::min(x, y);
311 return std::max(x, y);
316 static_assert(
sizeof(
RtFloat2) ==
sizeof(
float[2]),
"ensure compat with legacy c-layout");
321 static_assert(
sizeof(RtFloat4) ==
sizeof(
float[4]),
"ensure compat with legacy c-layout");
332 inline RtBBox(
float minx,
float miny,
float minz,
333 float maxx,
float maxy,
float maxz)
335 min.x = minx; min.y = miny; min.z = minz;
336 max.x = maxx; max.y = maxy; max.z = maxz;
338 inline RtBBox(
const RtPoint3 &_min,
const RtPoint3 &_max)
344 inline void Expand(
const float expansion) {
350 d = expansion * (fabsf(min.x) + fabsf(max.x));
354 d = expansion * (fabsf(min.y) + fabsf(max.y));
358 d = expansion * (fabsf(min.z) + fabsf(max.z));
366 return ((max.x - min.x) *
374 RtVector3 diff(max - min);
375 return 2.0f * (diff.x * diff.y + diff.x * diff.z + diff.y * diff.z);
398 if (pt.x < min.x) min.x = pt.x;
399 if (pt.y < min.y) min.y = pt.y;
400 if (pt.z < min.z) min.z = pt.z;
401 if (pt.x > max.x) max.x = pt.x;
402 if (pt.y > max.y) max.y = pt.y;
403 if (pt.z > max.z) max.z = pt.z;
409 if (bbox.
min.x < min.x) min.x = bbox.
min.x;
410 if (bbox.
min.y < min.y) min.y = bbox.
min.y;
411 if (bbox.
min.z < min.z) min.z = bbox.
min.z;
412 if (bbox.
max.x > max.x) max.x = bbox.
max.x;
413 if (bbox.
max.y > max.y) max.y = bbox.
max.y;
414 if (bbox.
max.z > max.z) max.z = bbox.
max.z;
420 if (bbox.
min.x > min.x) min.x = bbox.
min.x;
421 if (bbox.
min.y > min.y) min.y = bbox.
min.y;
422 if (bbox.
min.z > min.z) min.z = bbox.
min.z;
423 if (bbox.
max.x < max.x) max.x = bbox.
max.x;
424 if (bbox.
max.y < max.y) max.y = bbox.
max.y;
425 if (bbox.
max.z < max.z) max.z = bbox.
max.z;
432 (min.x < pt.x && pt.x < max.x &&
433 min.y < pt.y && pt.y < max.y &&
434 min.z < pt.z && pt.z < max.z);
442 return (pt.x < min.x || max.x < pt.x ||
443 pt.y < min.y || max.y < pt.y ||
444 pt.z < min.z || max.z < pt.z);
450 return (bbox.
min.x >= min.x && bbox.
min.y >= min.y && bbox.
min.z >= min.z &&
451 bbox.
max.x <= max.x && bbox.
max.y <= max.y && bbox.
max.z <= max.z);
457 return !(max.x <= bbox.
min.x || bbox.
max.x <= min.x ||
458 max.y <= bbox.
min.y || bbox.
max.y <= min.y ||
459 max.z <= bbox.
min.z || bbox.
max.z <= min.z);
465 inline bool Intersects(
const RtPoint3 &org,
const RtVector3 &invdir,
466 float tmax,
float *dist0,
float *dist1)
const 472 if (invdir.x < 0.0f) {
473 t0 = (max.x - org.x) * invdir.x;
474 t1 = (min.x - org.x) * invdir.x;
476 t0 = (min.x - org.x) * invdir.x;
477 t1 = (max.x - org.x) * invdir.x;
482 if (t0 > tmin) tmin = t0;
483 if (t1 < tmax) tmax = t1;
488 if (invdir.y < 0.0f) {
489 t0 = (max.y - org.y) * invdir.y;
490 t1 = (min.y - org.y) * invdir.y;
492 t0 = (min.y - org.y) * invdir.y;
493 t1 = (max.y - org.y) * invdir.y;
495 if (t0 > tmin) tmin = t0;
496 if (t1 < tmax) tmax = t1;
501 if (invdir.z < 0.0f) {
502 t0 = (max.z - org.z) * invdir.z;
503 t1 = (min.z - org.z) * invdir.z;
505 t0 = (min.z - org.z) * invdir.z;
506 t1 = (max.z - org.z) * invdir.z;
508 if (t0 > tmin) tmin = t0;
509 if (t1 < tmax) tmax = t1;
520 static_assert(
sizeof(RtColorRGB) ==
sizeof(
float[3]),
"ensure compat with legacy c-layout");
579 if (that.m_ptr != m_ptr)
582 that.m_ptr->IncRef();
613 return m_ptr == that.m_ptr;
625 return m_ptr != that.m_ptr;
635 bool operator< (RixRefCntPtr<T>
const &that)
const 637 return m_ptr < that.m_ptr;
647 operator bool ()
const {
return m_ptr != NULL; }
654 T* operator-> () {
return m_ptr; }
655 T
const* operator-> ()
const {
return m_ptr; }
659 const T*
GetPtr()
const {
return m_ptr; }
665 int GetRefCnt()
const {
return m_ptr ? m_ptr->GetRefCnt() : 0; }
682 #define US_NULL RtUString() float Normalize(float eps=FLT_MIN)
pxrcore::ColorRGB RtColorRGB
RtFloat2 & operator-=(const RtFloat2 &rhs)
int operator!=(const RtFloat2 &rhs) const
RixRefCntPtr(RixRefCntPtr const &that)
RtFloat2 operator*(const RtFloat2 &rhs) const
void Union(const RtBBox &bbox)
bool operator<(const RtFloat2 &rhs) const
RtFloat2 & operator/=(float rhs)
void Intersect(const RtBBox &bbox)
int operator==(const RtFloat2 &rhs) const
RtFloat2 & operator*=(float rhs)
friend float AbsDot(const RtFloat2 &v1, const RtFloat2 &v2)
RtFloat2 & operator+=(const RtFloat2 &rhs)
bool Encloses(const RtBBox &bbox) const
friend float Cross(const RtFloat2 &v1, const RtFloat2 &v2)
float Cross(const RtFloat2 &v2) const
RtFloat2 & operator/=(const RtFloat2 &rhs)
float AbsDot(const RtFloat2 &v2) const
RtBBox(float minx, float miny, float minz, float maxx, float maxy, float maxz)
float Dot(const RtFloat2 &v2) const
RtFloat2(float xx, float yy)
friend float Normalize(RtFloat2 &v)
RtFloat2 NormalizeCopy(const RtFloat2 &v) const
RtBBox(const RtPoint3 &_min, const RtPoint3 &_max)
RtFloat2 operator*(float rhs) const
RtFloat2 & operator*=(const RtFloat2 &rhs)
RtFloat2 operator/(float rhs) const
friend RtFloat2 operator*(float lhs, const RtFloat2 &rhs)
float SurfaceArea() const
pxrcore::UString RtUString
RtFloat2 operator/(const RtFloat2 &rhs) const
friend RtFloat2 NormalizeCopy(const RtFloat2 &v)
bool IsUnitLength(float eps=0.005f) const
RtFloat2 operator-() const
pxrcore::Matrix4x4 RtMatrix4x4
void Expand(const float expansion)
friend float Dot(const RtFloat2 &v1, const RtFloat2 &v2)
bool Overlaps(const RtBBox &bbox) const
RtFloat2 operator+(const RtFloat2 &rhs) const
bool Contains(const RtPoint3 &pt) const
RtFloat2 operator-(const RtFloat2 &rhs) const
bool Intersects(const RtPoint3 &org, const RtVector3 &invdir, float tmax, float *dist0, float *dist1) const
friend std::ostream & operator<<(std::ostream &o, const RtFloat2 &v)
bool Outside(const RtPoint3 &pt) const
float & operator[](int i)
void Expand(const RtPoint3 &pt)