24 #ifndef _GUSD_UT_GF_H_
25 #define _GUSD_UT_GF_H_
58 template <
class GF_OR_UT_TYPE>
67 template <
class GF_OR_UT_TYPE>
109 static inline const typename
113 static inline typename
117 static inline const typename
121 static inline typename
134 template <
class FROM,
class TO>
135 static inline const TO*
Cast(
const FROM*
val);
137 template <
class FROM,
class TO>
138 static inline TO*
Cast(FROM*
val);
140 template <
class FROM,
class TO>
141 static inline const TO&
Cast(
const FROM&
val);
143 template <
class FROM,
class TO>
144 static inline TO&
Cast(FROM&
val);
153 template <
class FROM,
class TO>
154 static inline void Convert(
const FROM& from, TO& to);
203 template <
class T,
class GFQUAT>
207 static inline void _AssertIsPodTuple();
209 template <
class FROM,
class TO>
210 static inline void _AssertCanCast();
215 "std::is_same<fpreal32,float>::value");
217 "std::is_same<fpreal64,double>::value");
222 #define _GUSDUT_DECLARE_UNCASTABLE(TYPE) \
224 struct GusdUT_Gf::Castable<TYPE> \
226 static const bool value = false; \
232 #define _GUSDUT_DECLARE_PARTIAL_EQUIVALENCE(TYPE,GFTYPE,UTTYPE,ALTTYPE) \
234 struct GusdUT_Gf::TypeEquivalence<TYPE> { \
235 static const bool isSpecialized = true; \
236 typedef GFTYPE GfType; \
237 typedef UTTYPE UtType; \
238 typedef ALTTYPE AltType; \
245 #define _GUSDUT_DECLARE_EQUIVALENCE(GFTYPE,UTTYPE) \
246 _GUSDUT_DECLARE_PARTIAL_EQUIVALENCE(GFTYPE,GFTYPE,UTTYPE,UTTYPE); \
247 _GUSDUT_DECLARE_PARTIAL_EQUIVALENCE(UTTYPE,GFTYPE,UTTYPE,GFTYPE);
357 GusdUT_Gf::_AssertIsPodTuple()
359 static_assert(GusdIsPodTuple<T>(),
"Type is not declared as a POD-tuple");
363 template <
class FROM,
class TO>
365 GusdUT_Gf::_AssertCanCast()
367 _AssertIsPodTuple<FROM>();
368 _AssertIsPodTuple<TO>();
371 static_assert(GusdPodTuplesAreBitwiseCompatible<FROM,TO>(),
372 "Types in cast are not bitwise compatible");
376 template <
class FROM,
class TO>
380 _AssertCanCast<FROM,TO>();
381 return reinterpret_cast<const TO*
>(
val);
385 template <
class FROM,
class TO>
389 _AssertCanCast<FROM,TO>();
390 return reinterpret_cast<TO*
>(
val);
394 template <
class FROM,
class TO>
398 _AssertCanCast<FROM,TO>();
399 return reinterpret_cast<const TO&
>(
val);
403 template <
class FROM,
class TO>
407 _AssertCanCast<FROM,TO>();
408 return reinterpret_cast<TO&
>(
val);
416 _AssertIsPodTuple<T>();
417 return Cast<T,typename TypeEquivalence<T>::AltType>(
val);
425 _AssertIsPodTuple<T>();
426 return Cast<T, typename TypeEquivalence<T>::AltType>(
val);
434 _AssertIsPodTuple<T>();
435 return Cast<T, typename TypeEquivalence<T>::AltType>(
val);
443 _AssertIsPodTuple<T>();
444 return Cast<T, typename TypeEquivalence<T>::AltType>(
val);
448 template <
class FROM,
class TO>
455 _AssertIsPodTuple<FROM>();
456 _AssertIsPodTuple<TO>();
457 static_assert(GusdPodTuplesAreCompatible<FROM,TO>(),
458 "Types are not compatible (mismatched tuple sizes)");
460 const auto*
src =
reinterpret_cast<const FromPodType*
>(&from);
461 ToPodType*
dst =
reinterpret_cast<ToPodType*
>(&to);
463 for (
int i = 0; i < GusdGetTupleSize<FROM>(); ++i) {
464 dst[i] =
static_cast<ToPodType
>(
src[i]);
469 template <
class T,
class GFQUAT>
474 to(3) = from.GetReal();
482 return _ConvertQuat(from, to);
490 return _ConvertQuat(from, to);
498 return _ConvertQuat(from, to);
506 return _ConvertQuat(from, to);
567 to =
GfVec4d(from.
w(), from.
x(), from.
y(), from.
z());
575 to =
GfVec4f(from.
w(), from.
x(), from.
y(), from.
z());
579 #undef _GUSDUT_DECLARE_UNCASTABLE
580 #undef _GUSDUT_DECLARE_PARTIAL_EQUIVALENCE
581 #undef _GUSDUT_DECLARE_EQUIVALENCE
Helpers for working with Gf types (vectors, matrices, etc.) within the HDK.
void SetReal(double real)
Sets the real part of the quaternion.
#define _GUSDUT_DECLARE_EQUIVALENCE(GFTYPE, UTTYPE)
GLsizei const GLfloat * value
void SetImaginary(const GfVec3h &imaginary)
Set the imaginary coefficients.
static const bool isSpecialized
static const TypeEquivalence< T >::AltType * Cast(const T *val)
void SetImaginary(const GfVec3f &imaginary)
Set the imaginary coefficients.
void SetReal(float real)
Set the real coefficient.
void SetImaginary(const GfVec3d &imaginary)
Sets the imaginary part of the quaternion.
pxr_half::half GfHalf
A 16-bit floating point data type.
GUSDUT_DECLARE_POD_TUPLE(class GfVec2h, fpreal16, 2)
Declare POD tuples for Gf types.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
void SetImaginary(const GfVec3d &imaginary)
Set the imaginary coefficients.
void SetReal(double real)
Set the real coefficient.
void SetReal(GfHalf real)
Set the real coefficient.
#define PXR_NAMESPACE_CLOSE_SCOPE
PXR_NAMESPACE_CLOSE_SCOPE SYS_DECLARE_IS_POD(PXR_NS::GfHalf)
#define _GUSDUT_DECLARE_UNCASTABLE(TYPE)
Declare a type as being uncastable.
static void Convert(const FROM &from, TO &to)