20 #ifndef __UT_Vector4_h__
21 #define __UT_Vector4_h__
35 #ifndef UT_DISABLE_VECTORIZE_MATRIX
51 template <
typename T,
typename S>
57 template <
typename T,
typename S>
59 template <
typename T,
typename S>
61 template <
typename T,
typename S>
63 template <
typename T,
typename S>
65 template <
typename T,
typename S>
67 template <
typename T,
typename S>
69 template <
typename T,
typename S>
71 template <
typename T,
typename S>
98 template <
typename T,
typename S>
102 template <
typename T>
107 template <
typename T,
typename S>
110 template <
typename T>
114 template <
typename T,
typename S>
121 template <
typename T,
typename S>
124 {
return v0 * (1 - u -
v) + v1 * u + v2 *v; }
144 template <
typename T,
typename S>
146 template <
typename T,
typename S>
149 template <
typename T,
typename S>
151 template <
typename T,
typename S>
157 template <
typename T>
159 template <
typename T>
161 template <
typename T>
164 template <
typename T>
167 template <
typename T>
173 template <
typename T>
178 static constexpr
int tuple_size = 4;
188 vec{ vx, vy, vz, vw }
211 template <typename
S>
219 template <
typename S>
221 { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; vec[3] = v[3];
291 return SYSsqrt( length2() );
329 return (vec[0] >= -tol && vec[0] <= tol) &&
330 (vec[1] >= -tol && vec[1] <= tol) &&
331 (vec[2] >= -tol && vec[2] <= tol);
336 if (vec[0] >= -tol && vec[0] <= tol) vec[0] = 0;
337 if (vec[1] >= -tol && vec[1] <= tol) vec[1] = 0;
338 if (vec[2] >= -tol && vec[2] <= tol) vec[2] = 0;
339 if (vec[3] >= -tol && vec[3] <= tol) vec[3] = 0;
344 if (vec[0] >= -tol && vec[0] <= tol) vec[0] = 0;
345 if (vec[1] >= -tol && vec[1] <= tol) vec[1] = 0;
346 if (vec[2] >= -tol && vec[2] <= tol) vec[2] = 0;
350 { vec[0]= -vec[0]; vec[1]= -vec[1]; vec[2]= -vec[2]; }
398 template <
typename S>
401 template <
typename S>
411 template <
typename S>
421 template <
typename S>
426 template <
typename S>
429 template <
typename S>
518 unsigned hash()
const {
return SYSvector_hash(
data(), tuple_size); }
526 vec[0] = xx; vec[1] = yy; vec[2] = zz; vec[3] = ww;
534 if (
size == tuple_size) vec[3] = v[3];
549 T denom = 1.0f / vec[3];
557 void save(std::ostream &os,
int binary=0)
const;
582 #ifndef UT_DISABLE_VECTORIZE_MATRIX
583 if constexpr( SYS_IsSame_v< T, float > )
585 return dot4(
v4uf(
a.data() ),
v4uf(
b.data() ) );
641 friend std::ostream &operator<<(std::ostream &os, const UT_Vector4T<T> &
v)
663 template <
typename T>
671 template <
typename T>
680 template <
typename T>
683 for (
int i = 0; i != tuple_size; ++i )
691 #ifndef UT_DISABLE_VECTORIZE_MATRIX
692 template <>
inline void
699 vm_store(this->
data(), l.vector);
703 template <
typename T>
707 return ((vec[0]>=vect.
x()-tol) && (vec[0]<=vect.
x()+tol) &&
708 (vec[1]>=vect.
y()-tol) && (vec[1]<=vect.
y()+tol) &&
709 (vec[2]>=vect.
z()-tol) && (vec[2]<=vect.
z()+tol));
713 template <
typename T>
719 template <
typename T>
725 template <
typename T>
731 template <
typename T>
737 template <
typename T>
743 template <
typename T>
749 template <
typename T>
755 template <
typename T>
760 #ifndef UT_DISABLE_VECTORIZE_MATRIX
779 template <
typename T,
typename S>
784 template <
typename T,
typename S>
789 template <
typename T,
typename S>
794 template <
typename T,
typename S>
799 template <
typename T,
typename S>
804 template <
typename T,
typename S>
809 template <
typename T,
typename S>
814 T inv = ((
T)1) / scalar;
817 template <
typename T,
typename S>
823 template <
typename T>
826 return v1.
x()*v2.
x() + v1.
y()*v2.
y() + v1.
z()*v2.
z();
828 template <
typename T>
831 return v1.
x()*v2.
x() + v1.
y()*v2.
y() + v1.
z()*v2.
z();
833 template <
typename T>
845 template <
typename T>
857 template <
typename T>
869 template <
typename T,
typename S>
876 template <
typename T,
typename S>
886 #ifndef UT_DISABLE_VECTORIZE_MATRIX
898 template <
typename T>
912 template <
typename T,
typename S>
917 template <
typename T>
924 return SYSsqrt(x*x + y*y + z*z + w*w);
926 template <
typename T>
932 return SYSsqrt(x*x + y*y + z*z);
935 #ifndef UT_DISABLE_VECTORIZE_MATRIX
944 return SYSsqrt(result[0] + result[1] + result[2] + result[3]);
954 return SYSsqrt(result[0] + result[1] + result[2]);
958 template <
typename T>
968 template<
typename T, ex
int D >
982 template<
typename T >
985 template<
typename T >
988 template<
typename T >
995 template <
typename T>
998 template<
typename TS >
1008 template <
typename V >
1012 template <
typename T>
1019 template <
typename T>
1022 template<
typename TS >
1034 template<
typename TS >
1046 template <
typename V >
1050 template <
typename T>
UT_API size_t format(char *buffer, size_t buffer_size, const UT_Vector4T< T > &v)
Mat3< typename promote< S, T >::type > operator*(S scalar, const Mat3< T > &m)
Multiply each element of the given matrix by scalar and return the result.
UT_Vector4T< T > operator/(const UT_Vector4T< T > &v, S scalar)
typename UT_StorageNum< T >::MathFloat UT_StorageMathFloat_t
#define SYS_STATIC_ASSERT(expr)
constexpr SYS_FORCE_INLINE T distance(const UT_Vector4T &b) const noexcept
UT_FromUnbounded creates a V from an unbounded array-like type.
UT_Vector4T< T > SYSlerp(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2, S t)
Componentwise linear interpolation.
friend constexpr bool operator>=(const UT_Vector4T &a, const UT_Vector4T &b) noexcept
UT_Vector4T< T > SYSmin(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
Componentwise min and maximum.
unsigned hash() const
Compute a hash.
T operator()(unsigned i) const
constexpr SYS_FORCE_INLINE T & y() noexcept
void multiplyComponents(const UT_Vector4T< T > &v)
constexpr SYS_FORCE_INLINE T w() const noexcept
constexpr SYS_FORCE_INLINE T y() const noexcept
Mat3< typename promote< T0, T1 >::type > operator+(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Add corresponding elements of m0 and m1 and return the result.
bool SYSisFinite(fpreal64 f)
void homogenize()
Express the point in homogeneous coordinates or vice-versa.
friend constexpr auto dot(const UT_Vector4T &a, const UT_Vector4T &b) noexcept
#define SYS_DEPRECATED_HDK_REPLACE(__V__, __R__)
const GLuint GLenum const void * binary
GLdouble GLdouble GLdouble z
typename SYS_FixedArrayElement< T >::type SYS_FixedArrayElement_t
void colVecMult(const UT_Matrix4T< S > &m)
fpreal64 distance2(const UT_VectorD &v1, const UT_VectorD &v2)
Distance squared (L2) aka quadrance.
constexpr SYS_FORCE_INLINE T & z() noexcept
constexpr SYS_FORCE_INLINE bool isFinite() const noexcept
GLboolean GLboolean GLboolean GLboolean a
constexpr SYS_FORCE_INLINE UT_Vector4T(const int32 v[]) noexcept
JSON reader class which handles parsing of JSON or bJSON files.
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
Class which writes ASCII or binary JSON streams.
**But if you need a result
static const exint TupleSize
friend constexpr bool operator<=(const UT_Vector4T &a, const UT_Vector4T &b) noexcept
GLfloat GLfloat GLfloat v2
size_t hash_value(const UT_Vector4T< T > &val)
constexpr UT_Vector4T< SYS_FixedArrayElement_t< TS > > UTmakeVector4T(const TS &as) noexcept
constexpr SYS_FORCE_INLINE T & x() noexcept
friend constexpr bool operator!=(const UT_Vector4T &a, const UT_Vector4T &b) noexcept
UT_Vector4T< T > SYSmax(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
UT_API UT_Vector4T< T > colVecMult3(const UT_Matrix4T< S > &m, const UT_Vector4T< T > &v)
constexpr SYS_FORCE_INLINE bool isEqual(const UT_Vector4T &b, const T tolerance=SYS_FTOLERANCE) const noexcept
constexpr SYS_FORCE_INLINE UT_Vector4T(const T vx, const T vy, const T vz, const T vw=1.0f)
SYS_FORCE_INLINE UT_Vector4T< T > & operator=(const UT_Vector4T< T > &that)=default
UT_API UT_Vector4T< T > rowVecMult3(const UT_Vector4T< T > &v, const UT_Matrix4T< S > &m)
bool SYSisEqual(const UT_Vector4T< T > &a, const UT_Vector4T< T > &b, S tol=SYS_FTOLERANCE)
Componentwise equality.
void clampZero(T tol=0.00001f)
friend constexpr bool operator<(const UT_Vector4T &a, const UT_Vector4T &b) noexcept
Mat3< typename promote< T0, T1 >::type > operator-(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Subtract corresponding elements of m0 and m1 and return the result.
constexpr SYS_FORCE_INLINE bool isZero() const noexcept
T distance(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
constexpr SYS_FORCE_INLINE T & z() noexcept
typename UT_StorageAtLeast32Bit< T0, T1 >::type UT_StorageAtLeast32Bit_t
constexpr SYS_FORCE_INLINE T x() const noexcept
constexpr SYS_FORCE_INLINE UT_Vector4T(const int64 v[]) noexcept
static const bool isVectorType
constexpr SYS_FORCE_INLINE T minComponent() const noexcept
void multiply3(UT_Vector4T< T > &dest, const UT_Matrix4T< S > &mat) const
constexpr SYS_FORCE_INLINE UT_Vector4T & operator-=(const UT_Vector4T &a) noexcept
friend constexpr bool operator==(const UT_Vector4T &a, const UT_Vector4T &b) noexcept
UT_Vector4T< T > SYSinvlerp(const UT_Vector4T< T > &a, const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
constexpr SYS_FORCE_INLINE T z() const noexcept
constexpr SYS_FORCE_INLINE UT_Vector4T(const fpreal32 v[]) noexcept
constexpr SYS_FORCE_INLINE T dot(const UT_Vector4T &b) const noexcept
UT_API UT_Vector3T< T > cross(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
UT_API UT_Vector4T< T > colVecMult(const UT_Matrix4T< S > &m, const UT_Vector4T< T > &v)
T & operator()(unsigned i)
constexpr SYS_FORCE_INLINE const T & operator[](exint i) const noexcept
constexpr SYS_FORCE_INLINE UT_Vector4T(const fpreal64 v[]) noexcept
constexpr SYS_FORCE_INLINE UT_Vector4T & operator*=(const T &a) noexcept
GLboolean GLboolean GLboolean b
int findMinAbsAxis() const
These allow you to find out what indices to use for different axes.
constexpr SYS_FORCE_INLINE bool equalZero(const T tolerance=SYS_FTOLERANCE) const noexcept
UT_Vector4T< T > & operator*=(const UT_Matrix4T< S > &mat)
T distance4(const UT_Vector4T< T > &p1, const UT_Vector4T< T > &p2)
Compute the distance between two points.
constexpr SYS_FORCE_INLINE UT_Vector4T< T > operator()(const TS &as) const noexcept
SYS_FORCE_INLINE UT_Vector4T< T > & operator=(const UT_Vector4T< S > &v)
void assign(T xx=0.0f, T yy=0.0f, T zz=0.0f, T ww=1.0f)
Set the values of the vector components.
int findMaxAbsAxis() const
These allow you to find out what indices to use for different axes.
UT_Vector4T< T > SYSbilerp(const UT_Vector4T< T > &u0v0, const UT_Vector4T< T > &u1v0, const UT_Vector4T< T > &u0v1, const UT_Vector4T< T > &u1v1, S u, S v)
Bilinear interpolation.
constexpr SYS_FORCE_INLINE UT_Vector4T()=default
UT_FixedVector< T, 4 > FixedVectorType
void rowVecMult(const UT_Matrix4T< S > &m)
constexpr SYS_FORCE_INLINE T maxComponent() const noexcept
constexpr SYS_FORCE_INLINE T distance2(const UT_Vector4T &b) const noexcept
static int entries()
Returns the vector size.
friend constexpr auto distance2(const UT_Vector4T &a, const UT_Vector4T &b) noexcept
LeafData & operator=(const LeafData &)=delete
constexpr SYS_FORCE_INLINE const T * data() const noexcept
constexpr UT_Vector4T< T > operator-(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2) noexcept
constexpr SYS_FORCE_INLINE UT_Vector4T & operator/=(const T &a) noexcept
constexpr SYS_FORCE_INLINE T & w() noexcept
constexpr SYS_FORCE_INLINE T length2() const noexcept
UT_API UT_Vector4T< T > rowVecMult(const UT_Vector4T< T > &v, const UT_Matrix4T< S > &m)
constexpr SYS_FORCE_INLINE UT_Vector4T & operator+=(const UT_Vector4T &a) noexcept
UT_Vector4T< T > SYSabs(const UT_Vector4T< T > &v)
SYS_FORCE_INLINE UT_StorageMathFloat_t< T > normalize() noexcept
constexpr SYS_FORCE_INLINE T & operator[](exint i) noexcept
void assign(const T *v, int size=tuple_size)
Set the values of the vector components.
Class to store JSON objects as C++ objects.
constexpr SYS_FORCE_INLINE T * data() noexcept
void multiply3(const UT_Matrix4T< S > &mat)
UT_Vector4T< T > SYSbarycentric(const UT_Vector4T< T > &v0, const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2, S u, S v)
Barycentric interpolation.
GLubyte GLubyte GLubyte GLubyte w
T distance3d(const UT_Vector4T< T > &p1, const UT_Vector4T< T > &p2)
Compute the distance between two points.
void dehomogenize()
Express the point in homogeneous coordinates or vice-versa.
void clampZero3(T tol=0.00001f)
constexpr SYS_FORCE_INLINE T & y() noexcept
int equalZero3(T tol=0.00001f) const
constexpr SYS_FORCE_INLINE UT_Vector4T< T > operator()(const TS &as) const noexcept
T dot(const UT_Vector4T< T > &v1, const UT_Vector3T< T > &v2)
The dot product between two vectors.
friend constexpr bool isZero(const UT_Vector4T &a) noexcept
constexpr SYS_FORCE_INLINE T avgComponent() const noexcept
friend constexpr bool operator>(const UT_Vector4T &a, const UT_Vector4T &b) noexcept
constexpr SYS_FORCE_INLINE UT_Vector4T & operator*=(const UT_Vector4T &a) noexcept
void rowVecMult3(const UT_Matrix4T< S > &m)
bool SYSisInteger(const UT_Vector4T< T > &v1)
Componentwise integer test.
T distance3(const UT_Vector4T< T > &p1, const UT_Vector4T< T > &p2)
Compute the distance between two points.
constexpr SYS_FORCE_INLINE T length() const noexcept
constexpr SYS_FORCE_INLINE void negate() noexcept
friend constexpr auto length2(const UT_Vector4T &a) noexcept
constexpr SYS_FORCE_INLINE T & x() noexcept