37 #ifndef RiTypesHelper_h 38 #define RiTypesHelper_h 64 #include "pxrcore/ustring/ustring.h" 65 #include "pxrcore/paramlist/types.h" 66 #include "pxrcore/paramlist/paramlist.h" 67 #include "pxrcore/paramlist/primvarlist.h" 70 static_assert(
sizeof(
RtFloat3) ==
sizeof(
float[3]),
"ensure compat with legacy c-layout");
93 explicit inline RtFloat2(
const float *d) :
x(d[0]),
y(d[1]) {}
98 assert(i >= 0 && i<2);
103 assert(i >= 0 && i<2);
110 return x == rhs.
x &&
y == rhs.
y;
114 return x != rhs.
x ||
y != rhs.
y;
120 return (
x < rhs.
x ?
true :
134 o << v.
x <<
" " << v.
y ;
206 float inv = 1.0f / rhs;
211 float inv = 1.0f / rhs;
229 return (1.0f-eps <= len && len <= 1.0f+eps);
238 len = std::sqrt(len);
273 return x * v2.
x +
y * v2.
y;
283 return std::abs(this->
Dot(v2));
293 return x * v2.
y -
y * v2.
x;
302 return (
x +
y) * .5f;
307 return std::min(
x,
y);
312 return std::max(
x,
y);
317 static_assert(
sizeof(
RtFloat2) ==
sizeof(
float[2]),
"ensure compat with legacy c-layout");
322 static_assert(
sizeof(
RtFloat4) ==
sizeof(
float[4]),
"ensure compat with legacy c-layout");
333 inline RtBBox(
float minx,
float miny,
float minz,
334 float maxx,
float maxy,
float maxz)
336 min.x = minx;
min.y = miny;
min.z = minz;
337 max.x = maxx;
max.y = maxy;
max.z = maxz;
345 inline void Expand(
const float expansion) {
351 d = expansion * (fabsf(
min.x) + fabsf(
max.x));
355 d = expansion * (fabsf(
min.y) + fabsf(
max.y));
359 d = expansion * (fabsf(
min.z) + fabsf(
max.z));
376 return 2.0f * (diff.x * diff.y + diff.x * diff.z + diff.y * diff.z);
399 if (pt.x <
min.x)
min.x = pt.x;
400 if (pt.y <
min.y)
min.y = pt.y;
401 if (pt.z <
min.z)
min.z = pt.z;
402 if (pt.x >
max.x)
max.x = pt.x;
403 if (pt.y >
max.y)
max.y = pt.y;
404 if (pt.z >
max.z)
max.z = pt.z;
433 (
min.x < pt.x && pt.x <
max.x &&
434 min.y < pt.y && pt.y <
max.y &&
435 min.z < pt.z && pt.z <
max.z);
443 return (pt.x <
min.x ||
max.x < pt.x ||
444 pt.y <
min.y ||
max.y < pt.y ||
445 pt.z <
min.z ||
max.z < pt.z);
467 float tmax,
float *dist0,
float *dist1)
const 473 if (invdir.x < 0.0f) {
474 t0 = (
max.x - org.x) * invdir.x;
475 t1 = (
min.x - org.x) * invdir.x;
477 t0 = (
min.x - org.x) * invdir.x;
478 t1 = (
max.x - org.x) * invdir.x;
483 if (t0 > tmin) tmin = t0;
484 if (t1 < tmax) tmax = t1;
489 if (invdir.y < 0.0f) {
490 t0 = (
max.y - org.y) * invdir.y;
491 t1 = (
min.y - org.y) * invdir.y;
493 t0 = (
min.y - org.y) * invdir.y;
494 t1 = (
max.y - org.y) * invdir.y;
496 if (t0 > tmin) tmin = t0;
497 if (t1 < tmax) tmax = t1;
502 if (invdir.z < 0.0f) {
503 t0 = (
max.z - org.z) * invdir.z;
504 t1 = (
min.z - org.z) * invdir.z;
506 t0 = (
min.z - org.z) * invdir.z;
507 t1 = (
max.z - org.z) * invdir.z;
509 if (t0 > tmin) tmin = t0;
510 if (t1 < tmax) tmax = t1;
521 static_assert(
sizeof(
RtColorRGB) ==
sizeof(
float[3]),
"ensure compat with legacy c-layout");
580 if (that.m_ptr != m_ptr)
583 that.m_ptr->IncRef();
614 return m_ptr == that.m_ptr;
626 return m_ptr != that.m_ptr;
636 bool operator< (RixRefCntPtr<T>
const &that)
const 638 return m_ptr < that.m_ptr;
648 operator bool ()
const {
return m_ptr != NULL; }
660 const T*
GetPtr()
const {
return m_ptr; }
666 int GetRefCnt()
const {
return m_ptr ? m_ptr->GetRefCnt() : 0; }
683 #define US_NULL RtUString() RtFloat2(const float *d)
Definition: RiTypesHelper.h:93
RtFloat2 & operator*=(float rhs)
Definition: RiTypesHelper.h:196
RixRefCntPtr(T *ptr)
Definition: RiTypesHelper.h:556
int operator!=(const RtFloat2 &rhs) const
Definition: RiTypesHelper.h:112
float Dot(const RtFloat2 &v2) const
Definition: RiTypesHelper.h:271
~RixRefCntPtr()
Definition: RiTypesHelper.h:571
RtFloat2 & operator/=(const RtFloat2 &rhs)
Definition: RiTypesHelper.h:178
friend float Cross(const RtFloat2 &v1, const RtFloat2 &v2)
Definition: RiTypesHelper.h:295
pxrcore::Float4 RtFloat4
Definition: RiTypesHelper.h:321
float x
Definition: RiTypesHelper.h:86
float AbsDot(const RtFloat2 &v2) const
Definition: RiTypesHelper.h:281
friend float Dot(const RtFloat2 &v1, const RtFloat2 &v2)
Definition: RiTypesHelper.h:275
void Union(const RtBBox &bbox)
Definition: RiTypesHelper.h:408
bool operator==(RixRefCntPtr< T > const &that) const
Definition: RiTypesHelper.h:612
pxrcore::ColorRGB RtColorRGB
Definition: RiTypesHelper.h:520
RtFloat2 NormalizeCopy(const RtFloat2 &v) const
Definition: RiTypesHelper.h:251
friend RtFloat2 operator*(float lhs, const RtFloat2 &rhs)
Definition: RiTypesHelper.h:193
pxrcore::ParamList RtParamList
Definition: RiTypesHelper.h:687
T & operator*()
Definition: RiTypesHelper.h:651
RtFloat3 RtPoint3
Definition: RiTypesHelper.h:70
void Negate()
Definition: RiTypesHelper.h:264
bool operator<(const RtFloat2 &rhs) const
Definition: RiTypesHelper.h:118
RixRefCntPtr()
Definition: RiTypesHelper.h:551
float LengthSq() const
Definition: RiTypesHelper.h:216
bool IsUnitLength(float eps=0.005f) const
Definition: RiTypesHelper.h:226
bool Intersects(const RtPoint3 &org, const RtVector3 &invdir, float tmax, float *dist0, float *dist1) const
Definition: RiTypesHelper.h:466
float ChannelAvg() const
Definition: RiTypesHelper.h:300
RixRefCntPtr< T > & operator=(RixRefCntPtr< T > const &that)
Definition: RiTypesHelper.h:578
RtFloat2 operator/(const RtFloat2 &rhs) const
Definition: RiTypesHelper.h:174
RtFloat2 & operator/=(float rhs)
Definition: RiTypesHelper.h:209
float ChannelMax() const
Definition: RiTypesHelper.h:310
RtPoint3 min
Definition: RiTypesHelper.h:330
RtFloat2 operator-() const
Definition: RiTypesHelper.h:186
float Volume() const
Definition: RiTypesHelper.h:365
Definition: RiTypesHelper.h:82
pxrcore::DataType RtDataType
Definition: RiTypesHelper.h:685
bool Encloses(const RtBBox &bbox) const
Definition: RiTypesHelper.h:449
float Cross(const RtFloat2 &v2) const
Definition: RiTypesHelper.h:291
pxrcore::DetailType RtDetailType
Definition: RiTypesHelper.h:686
bool Contains(const RtPoint3 &pt) const
Definition: RiTypesHelper.h:430
bool operator<(RixRefCntPtr< T > const &that) const
Definition: RiTypesHelper.h:636
RtFloat2 operator*(float rhs) const
Definition: RiTypesHelper.h:189
RtBBox(const RtPoint3 &_min, const RtPoint3 &_max)
Definition: RiTypesHelper.h:339
bool Outside(const RtPoint3 &pt) const
Definition: RiTypesHelper.h:441
pxrcore::Float3 RtFloat3
Definition: RiTypesHelper.h:69
RtFloat2 & operator+=(const RtFloat2 &rhs)
Definition: RiTypesHelper.h:143
RtPoint3 max
Definition: RiTypesHelper.h:330
Definition: RiTypesHelper.h:327
pxrcore::PrimVarList RtPrimVarList
Definition: RiTypesHelper.h:688
int operator==(const RtFloat2 &rhs) const
Definition: RiTypesHelper.h:108
float Length() const
Definition: RiTypesHelper.h:220
int GetRefCnt() const
Definition: RiTypesHelper.h:666
RtFloat3 RtNormal3
Definition: RiTypesHelper.h:73
RtFloat2 operator/(float rhs) const
Definition: RiTypesHelper.h:204
Definition: RiTypesHelper.h:546
RtBBox(float minx, float miny, float minz, float maxx, float maxy, float maxz)
Definition: RiTypesHelper.h:333
bool Overlaps(const RtBBox &bbox) const
Definition: RiTypesHelper.h:456
friend float Normalize(RtFloat2 &v)
Definition: RiTypesHelper.h:245
RtFloat2 RtVector2
Definition: RiTypesHelper.h:319
RtBBox()
Definition: RiTypesHelper.h:332
float & operator[](int i)
Definition: RiTypesHelper.h:96
T * GetPtr()
Definition: RiTypesHelper.h:659
void SetPtr(T *ptr)
Definition: RiTypesHelper.h:663
T * operator->()
Definition: RiTypesHelper.h:655
float DiagonalSq() const
Definition: RiTypesHelper.h:386
float y
Definition: RiTypesHelper.h:86
const T * GetPtr() const
Definition: RiTypesHelper.h:660
float Normalize(float eps=FLT_MIN)
Definition: RiTypesHelper.h:233
void Expand(const float expansion)
Definition: RiTypesHelper.h:345
void Intersect(const RtBBox &bbox)
Definition: RiTypesHelper.h:419
RtFloat2 operator*(const RtFloat2 &rhs) const
Definition: RiTypesHelper.h:162
RtFloat4 RtPoint4
Definition: RiTypesHelper.h:322
RtFloat2 & operator-=(const RtFloat2 &rhs)
Definition: RiTypesHelper.h:154
RtFloat2(float v)
Definition: RiTypesHelper.h:90
bool operator!=(RixRefCntPtr< T > const &that) const
Definition: RiTypesHelper.h:624
pxrcore::Matrix4x4 RtMatrix4x4
Definition: RiTypesHelper.h:74
RtFloat2 operator-(const RtFloat2 &rhs) const
Definition: RiTypesHelper.h:150
friend RtFloat2 NormalizeCopy(const RtFloat2 &v)
Definition: RiTypesHelper.h:257
RtFloat2 & operator*=(const RtFloat2 &rhs)
Definition: RiTypesHelper.h:166
float ChannelMin() const
Definition: RiTypesHelper.h:305
void Expand(const RtPoint3 &pt)
Definition: RiTypesHelper.h:397
pxrcore::UString RtUString
Definition: RiTypesHelper.h:682
RixRefCntPtr(RixRefCntPtr const &that)
Definition: RiTypesHelper.h:563
friend std::ostream & operator<<(std::ostream &o, const RtFloat2 &v)
Definition: RiTypesHelper.h:132
float Diagonal() const
Definition: RiTypesHelper.h:380
RtFloat2(float xx, float yy)
Definition: RiTypesHelper.h:89
float SurfaceArea() const
Definition: RiTypesHelper.h:373
RtFloat3 RtVector3
Definition: RiTypesHelper.h:72
RtFloat2 operator+(const RtFloat2 &rhs) const
Definition: RiTypesHelper.h:139
RtFloat2 RtPoint2
Definition: RiTypesHelper.h:317
RtPoint3 Center() const
Definition: RiTypesHelper.h:391
friend float AbsDot(const RtFloat2 &v1, const RtFloat2 &v2)
Definition: RiTypesHelper.h:285