25 #ifndef PXR_BASE_TS_DATA_H
26 #define PXR_BASE_TS_DATA_H
107 const VtValue& slope)
const = 0;
140 template <
typename T>
152 const T& leftTangentSlope,
153 const T& rightTangentSlope);
162 Ts_Data const* kf2)
const override;
227 const TsTime dxInv = 1.0 / dx;
231 const T dy = y2 -
y1;
235 const T slope = dy * dxInv;
249 const T v = value.template Get<T>();
250 const T s = slope.template Get<T>();
264 T const& _GetRightValue()
const {
265 return _values.Get()._rhv;
267 T const& _GetLeftValue()
const {
268 return _values.Get()._lhv;
270 T const& _GetRightTangentSlope()
const {
271 return _values.Get()._rightTangentSlope;
273 T const& _GetLeftTangentSlope()
const {
274 return _values.Get()._leftTangentSlope;
277 void _SetRightValue(
T const& rhv) {
278 _values.GetMutable()._rhv = rhv;
280 void _SetLeftValue(
T const& lhv) {
281 _values.GetMutable()._lhv = lhv;
283 void _SetRightTangentSlope(
T const& rightTangentSlope) {
284 _values.GetMutable()._rightTangentSlope = rightTangentSlope;
286 void _SetLeftTangentSlope(
T const& leftTangentSlope) {
287 _values.GetMutable()._leftTangentSlope = leftTangentSlope;
307 _leftTangentSlope(leftTangentSlope),
308 _rightTangentSlope(rightTangentSlope)
317 V _leftTangentSlope, _rightTangentSlope;
327 static constexpr
size_t _size =
sizeof(_Values<double>);
328 static constexpr
bool _isSmall = (
sizeof(_Values<T>) <= _size);
333 _LocalStorage(_Values<T> &&
values)
334 : _data(std::move(
values)) {}
336 const _Values<T>& Get()
const {
return _data; }
337 _Values<T>& GetMutable() {
return _data; }
345 _HeapStorage(_Values<T> &&
values)
346 : _data(new _Values<
T>(std::move(
values))) {}
349 _HeapStorage(
const _HeapStorage &other)
350 : _data(new _Values<
T>(other.Get())) {}
352 const _Values<T>& Get()
const {
return *_data; }
353 _Values<T>& GetMutable() {
return *_data; }
355 std::unique_ptr<_Values<T>> _data;
360 typename std::conditional<
361 _isSmall, _LocalStorage, _HeapStorage>
::type;
365 explicit _ValuesHolder(_Values<T> &&
values)
366 : _storage(std::move(
values)) {}
369 _ValuesHolder(
const _ValuesHolder &other)
370 : _storage(other._storage) {}
373 ~_ValuesHolder() { _storage.~_Storage(); }
376 const _Values<T>& Get()
const {
return _storage.Get(); }
377 _Values<T>& GetMutable() {
return _storage.GetMutable(); }
383 char _padding[_size];
389 sizeof(_ValuesHolder) ==
sizeof(_Values<double>),
390 "_ValuesHolder does not have expected type-independent size");
393 _ValuesHolder _values;
396 TsTime _leftTangentLength, _rightTangentLength;
400 bool _tangentSymmetryBroken;
410 template <
typename T>
417 template <
typename T>
423 const T &leftTangentSlope,
424 const T &rightTangentSlope)
427 t, isDual, leftValue, rightValue,
428 leftTangentSlope, rightTangentSlope);
432 template <
typename T>
448 return reinterpret_cast<const Ts_Data*
>(&_storage);
454 return reinterpret_cast<Ts_Data*
>(&_storage);
461 typename std::aligned_storage<
471 template <
typename T>
473 _values(_Values<
T>(value,value)),
474 _leftTangentLength(0.0),
475 _rightTangentLength(0.0),
478 _tangentSymmetryBroken(false)
482 template <
typename T>
488 const T& leftTangentSlope,
489 const T& rightTangentSlope) :
490 _values(_Values<
T>(leftValue,rightValue,
491 leftTangentSlope,rightTangentSlope)),
492 _leftTangentLength(0.0),
493 _rightTangentLength(0.0),
496 _tangentSymmetryBroken(false)
501 template <
typename T>
508 template <
typename T>
509 std::shared_ptr<Ts_UntypedEvalCache>
518 return std::make_shared<
522 template <
typename T>
523 std::shared_ptr<Ts_EvalCache<T, TsTraits<T>::interpolatable> >
529 return std::shared_ptr<Ts_EvalCache<T, TsTraits<T>::interpolatable> >(
533 template <
typename T>
547 template <
typename T>
558 .EvalDerivative(time);
561 template <
typename T>
571 (!GetIsDualValued() || (GetLeftValue() == rhs.
GetLeftValue()));
579 (!GetIsDualValued() || (GetLeftValue() == rhs.
GetLeftValue())) &&
587 template <
typename T>
594 template <
typename T>
600 if (!CanSetKnotType(knotType, &reason)) {
605 _knotType = knotType;
608 template <
typename T>
614 if (!ValueCanBeInterpolated() && knotType !=
TsKnotHeld) {
616 *reason =
"Value cannot be interpolated; only 'held' " \
617 "key frames are allowed.";
626 "Cannot set keyframe type %s; values of type '%s' "
627 "do not support tangents.",
637 template <
typename T>
641 return VtValue(_GetRightValue());
644 template <
typename T>
649 return GetRightTangentSlope();
655 template <
typename T>
661 _SetRightValue(v.
Get<
T>());
662 if (!ValueCanBeInterpolated())
671 template <
typename T>
678 template <
typename T>
693 SetLeftValue(GetValue());
697 template <
typename T>
701 return VtValue(_isDual ? _GetLeftValue() : _GetRightValue());
704 template <
typename T>
709 return GetLeftTangentSlope();
715 template <
typename T>
724 if (!GetIsDualValued()) {
731 _SetLeftValue(v.
Get<
T>());
732 if (!ValueCanBeInterpolated())
741 template <
typename T>
748 template <
typename T>
755 template <
typename T>
762 template <
typename T>
769 template <
typename T>
778 template <
typename T>
788 return VtValue(_GetLeftTangentSlope());
791 template <
typename T>
801 return VtValue(_GetRightTangentSlope());
804 template <
typename T>
814 return _leftTangentLength;
817 template <
typename T>
827 return _rightTangentLength;
830 template <
typename T>
842 _SetLeftTangentSlope(val.
Get<
T>());
850 template <
typename T>
862 _SetRightTangentSlope(val.
Get<
T>());
864 TF_CODING_ERROR(
"cannot convert type '%s' to '%s' to assign to keyframe"
870 #define TS_LENGTH_EPSILON 1e-6
872 template <
typename T>
881 if (std::isnan(newLen)) {
885 if (std::isinf(newLen)) {
894 "Cannot set tangent length to negative value; ignoring");
899 _leftTangentLength = newLen;
902 template <
typename T>
911 if (std::isnan(newLen)) {
915 if (std::isinf(newLen)) {
924 "Cannot set tangent length to negative value; ignoring");
929 _rightTangentLength = newLen;
932 template <
typename T>
942 return _tangentSymmetryBroken;
945 template <
typename T>
955 if (_tangentSymmetryBroken != broken) {
956 _tangentSymmetryBroken =
broken;
957 if (!_tangentSymmetryBroken) {
958 _SetLeftTangentSlope(_GetRightTangentSlope());
963 template <
typename T>
virtual bool GetIsDualValued() const =0
TF_API std::string TfStringPrintf(const char *fmt,...)
VtValue EvalUncached(Ts_Data const *kf2, TsTime time) const override
virtual VtValue GetValueDerivative() const =0
bool HasTangents() const override
virtual VtValue GetSlope(const Ts_Data &) const =0
bool operator==(const Ts_Data &) const override
virtual void CloneInto(Ts_PolymorphicDataHolder *holder) const =0
void SetTangentSymmetryBroken(bool broken) override
virtual void SetIsDualValued(bool isDual)=0
virtual void SetKnotType(TsKnotType knotType)=0
virtual void SetRightTangentSlope(VtValue)=0
virtual VtValue Extrapolate(const VtValue &value, TsTime dt, const VtValue &slope) const =0
void CloneInto(Ts_PolymorphicDataHolder *holder) const override
GT_API const UT_StringHolder time
~Ts_TypedData() override=default
GLsizei const GLchar *const * string
GLsizei const GLfloat * value
A held-value knot; tangents will be ignored.
void SetLeftTangentLength(TsTime) override
virtual void ResetTangentSymmetryBroken()=0
ARCH_API std::string ArchGetDemangled(const std::string &typeName)
virtual bool HasTangents() const =0
std::shared_ptr< Ts_EvalCache< T, TsTraits< T >::interpolatable > > CreateTypedEvalCache(Ts_Data const *kf2) const
void SetRightTangentSlope(VtValue) override
VtValue GetSlope(const Ts_Data &right) const override
void SetTime(TsTime newTime)
bool ValueCanBeInterpolated() const override
virtual VtValue GetLeftTangentSlope() const =0
bool CanSetKnotType(TsKnotType knotType, std::string *reason) const override
virtual TsTime GetLeftTangentLength() const =0
virtual std::shared_ptr< Ts_UntypedEvalCache > CreateEvalCache(Ts_Data const *kf2) const =0
**But if you need a result
bool IsEmpty() const
Returns true iff this value is empty.
const Ts_Data * Get() const
virtual VtValue GetRightTangentSlope() const =0
virtual void SetRightTangentLength(TsTime)=0
bool ValueCanBeExtrapolated() const override
virtual bool GetTangentSymmetryBroken() const =0
#define TS_LENGTH_EPSILON
VtValue GetRightTangentSlope() const override
virtual void SetTangentSymmetryBroken(bool broken)=0
VtValue GetLeftValueDerivative() const override
virtual VtValue GetValue() const =0
TsTime GetRightTangentLength() const override
VtValue Extrapolate(const VtValue &value, TsTime dt, const VtValue &slope) const override
virtual void SetLeftTangentSlope(VtValue)=0
void New(const Ts_TypedData< T > &other)
TsKnotType
Keyframe knot types.
void New(const TsTime &t, bool isDual, const T &leftValue, const T &rightValue, const T &leftTangentSlope, const T &rightTangentSlope)
TsTime GetLeftTangentLength() const override
void SetKnotType(TsKnotType knotType) override
virtual VtValue GetZero() const =0
virtual void SetLeftTangentLength(TsTime)=0
SIM_API const UT_StringHolder broken
void SetIsDualValued(bool isDual) override
Specifies the value of an TsSpline object at a particular point in time.
VtValue GetZero() const override
virtual void SetValue(VtValue val)=0
virtual bool CanSetKnotType(TsKnotType knotType, std::string *reason) const =0
VtValue GetValue() const override
void SetLeftValue(VtValue) override
TsKnotType GetKnotType() const override
PXR_NAMESPACE_OPEN_SCOPE typedef double TsTime
The time type used by Ts.
void SetRightTangentLength(TsTime) override
virtual TsKnotType GetKnotType() const =0
VtValue GetValueDerivative() const override
virtual bool ValueCanBeInterpolated() const =0
virtual TsTime GetRightTangentLength() const =0
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
GLenum GLsizei GLsizei GLint * values
Holds the data for an TsKeyFrame.
static VtValue Cast(VtValue const &val)
virtual VtValue GetLeftValueDerivative() const =0
virtual VtValue GetLeftValue() const =0
static TF_API std::string GetDisplayName(TfEnum val)
virtual ~Ts_Data()=default
VtValue GetLeftValue() const override
bool GetIsDualValued() const override
virtual bool ValueCanBeExtrapolated() const =0
VT_API std::string GetTypeName() const
Return the type name of the held typeid.
#define PXR_NAMESPACE_CLOSE_SCOPE
VtValue GetLeftTangentSlope() const override
void SetValue(VtValue) override
bool ValueTypeSupportsTangents() const override
bool GetTangentSymmetryBroken() const override
GLdouble GLdouble GLdouble y2
virtual bool operator==(const Ts_Data &) const =0
void ResetTangentSymmetryBroken() override
void SetLeftTangentSlope(VtValue) override
virtual bool ValueTypeSupportsTangents() const =0
virtual VtValue EvalDerivativeUncached(Ts_Data const *kf2, TsTime time) const =0
VtValue EvalDerivativeUncached(Ts_Data const *kf2, TsTime time) const override
virtual VtValue EvalUncached(Ts_Data const *kf2, TsTime time) const =0
std::shared_ptr< Ts_UntypedEvalCache > CreateEvalCache(Ts_Data const *kf2) const override
virtual void SetLeftValue(VtValue)=0