Loading...
Searching...
No Matches
keyFrame.h
1//
2// Copyright 2023 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7
8#ifndef PXR_BASE_TS_KEY_FRAME_H
9#define PXR_BASE_TS_KEY_FRAME_H
10
11#include "pxr/pxr.h"
12#include "pxr/base/ts/api.h"
14#include "pxr/base/ts/types.h"
15#include "pxr/base/ts/data.h"
16#include "pxr/base/vt/value.h"
17#include "pxr/base/vt/traits.h"
20
21#include <iosfwd>
22#include <typeinfo>
23
24PXR_NAMESPACE_OPEN_SCOPE
25
26class TsSpline;
27
49class TsKeyFrame final
50{
51public: // methods
52
54 TS_API
56
63
65 template <typename T>
66 TsKeyFrame( const TsTime & time,
67 const T & val,
68 TsKnotType knotType = TsKnotLinear,
69 const T & leftTangentSlope = TsTraits<T>::zero,
70 const T & rightTangentSlope = TsTraits<T>::zero,
71 TsTime leftTangentLength = 0,
72 TsTime rightTangentLength = 0);
73
75 TS_API
76 TsKeyFrame( const TsTime & time,
77 const VtValue & val,
78 TsKnotType knotType = TsKnotLinear,
79 const VtValue & leftTangentSlope = VtValue(),
80 const VtValue & rightTangentSlope = VtValue(),
81 TsTime leftTangentLength = 0,
82 TsTime rightTangentLength = 0);
83
85 template <typename T>
86 TsKeyFrame( const TsTime & time,
87 const T & lhv,
88 const T & rhv,
89 TsKnotType knotType = TsKnotLinear,
90 const T & leftTangentSlope = TsTraits<T>::zero,
91 const T & rightTangentSlope = TsTraits<T>::zero,
92 TsTime leftTangentLength = 0,
93 TsTime rightTangentLength = 0);
94
96 TS_API
97 TsKeyFrame( const TsTime & time,
98 const VtValue & lhv,
99 const VtValue & rhv,
100 TsKnotType knotType = TsKnotLinear,
101 const VtValue & leftTangentSlope = VtValue(),
102 const VtValue & rightTangentSlope = VtValue(),
103 TsTime leftTangentLength = 0,
104 TsTime rightTangentLength = 0);
105
107 TS_API
108 TsKeyFrame( const TsKeyFrame & kf );
109
111
113 TS_API
115
118
120 TS_API
122
124 TS_API
125 bool operator==(const TsKeyFrame &) const;
126
127 TS_API
128 bool operator!=(const TsKeyFrame &) const;
129
134 TS_API
135 bool IsEquivalentAtSide(const TsKeyFrame &keyFrame, TsSide side) const;
136
138 TS_API
139 TsTime GetTime() const {
140 return _holder.Get()->GetTime();
141 }
142
144 TS_API
145 void SetTime( const TsTime & newTime ) {
146 _holder.GetMutable()->SetTime(newTime);
147 }
148
150 TS_API
152
154 TS_API
155 void SetValue( VtValue val );
156
158 TS_API
159 VtValue GetValue( TsSide side ) const;
160
162 TS_API
163 void SetValue( VtValue val, TsSide side );
164
166 TS_API
168
170 TS_API
172
174 TS_API
175 TsKnotType GetKnotType() const;
176
178 TS_API
179 void SetKnotType( TsKnotType knotType );
180
183 TS_API
184 bool CanSetKnotType( TsKnotType, std::string *reason=NULL ) const;
185
187
224
227 TS_API
228 bool GetIsDualValued() const;
229
232 TS_API
233 void SetIsDualValued( bool isDual );
234
237 TS_API
239
242 TS_API
244
248 TS_API
250
252
255
257 TS_API
258 bool IsInterpolatable() const;
259
263 TS_API
264 bool IsExtrapolatable() const;
265
272 TS_API
273 bool SupportsTangents() const;
274
277 TS_API
278 bool HasTangents() const;
279
282 TS_API
283 TsTime GetLeftTangentLength() const;
284
286 TS_API
288
291 TS_API
292 TsTime GetRightTangentLength() const;
293
295 TS_API
297
300 TS_API
301 void SetLeftTangentLength( TsTime );
302
305 TS_API
307
310 TS_API
311 void SetRightTangentLength( TsTime );
312
315 TS_API
317
324 TS_API
326
331 TS_API
332 void SetTangentSymmetryBroken( bool broken );
333
344 TS_API
346
347private:
348
349 // Give the rest of the library access to the Ts_Data object held
350 // in this keyframe through the Ts_GetKeyFrameData function.
351 friend Ts_Data* Ts_GetKeyFrameData(TsKeyFrame &kf);
352 friend Ts_Data const* Ts_GetKeyFrameData(TsKeyFrame const& kf);
353
354 // Shared initialization
355 void _Initialize(
356 const TsTime & time,
357 TsKnotType knotType,
358 const VtValue & leftTangentSlope,
359 const VtValue & rightTangentSlope,
360 TsTime leftTangentLength,
361 TsTime rightTangentLength);
362
363 // XXX: exported because called from inlined templated constructors
364 TS_API
365 void _InitializeKnotType(TsKnotType knotType);
366 TS_API
367 void _InitializeTangentLength(TsTime leftTangentLength,
368 TsTime rightTangentLength);
369
370 // Helper function which tests the setability of tangents for this knot,
371 // and reports an error if tangents not supported
372 bool _ValidateTangentSetting() const;
373
374private:
375
376 Ts_PolymorphicDataHolder _holder;
377};
378
380
381TS_API
382std::ostream& operator<<(std::ostream &out, const TsKeyFrame &val);
383
384template <typename T>
385TsKeyFrame::TsKeyFrame( const TsTime & time,
386 const T & val,
387 TsKnotType knotType,
388 const T & leftTangentSlope,
389 const T & rightTangentSlope,
390 TsTime leftTangentLength,
391 TsTime rightTangentLength)
392{
393 static_assert( TsTraits<T>::isSupportedSplineValueType );
394
395 _holder.New(time, false /*isDual*/,
396 val, val, leftTangentSlope, rightTangentSlope);
397
398 _InitializeKnotType(knotType);
399 _InitializeTangentLength(leftTangentLength,rightTangentLength);
400}
401
402template <typename T>
403TsKeyFrame::TsKeyFrame( const TsTime & time,
404 const T & lhv,
405 const T & rhv,
406 TsKnotType knotType,
407 const T & leftTangentSlope,
408 const T & rightTangentSlope,
409 TsTime leftTangentLength,
410 TsTime rightTangentLength)
411{
412 static_assert( TsTraits<T>::isSupportedSplineValueType );
413
414 _holder.New(time, true /*isDual*/, lhv, rhv,
415 leftTangentSlope, rightTangentSlope);
416
417 _InitializeKnotType(knotType);
418 _InitializeTangentLength(leftTangentLength,rightTangentLength);
419}
420
421PXR_NAMESPACE_CLOSE_SCOPE
422
423#endif
Low-level utilities for informing users of various internal and external diagnostic conditions.
Holds the data for an TsKeyFrame.
Definition: data.h:33
Specifies the value of an TsSpline object at a particular point in time.
Definition: keyFrame.h:50
TS_API bool IsInterpolatable() const
Gets whether the value type of this keyframe is interpolatable.
TS_API VtValue GetValueDerivative() const
Gets the value of the derivative at this keyframe.
TS_API TsKeyFrame(const TsTime &time, const VtValue &lhv, const VtValue &rhv, TsKnotType knotType=TsKnotLinear, const VtValue &leftTangentSlope=VtValue(), const VtValue &rightTangentSlope=VtValue(), TsTime leftTangentLength=0, TsTime rightTangentLength=0)
Constructs a dual-valued keyframe with VtValues.
TS_API void ResetTangentSymmetryBroken()
Sets the flag that enforces tangent symmetry based on whether the tangets are already symmetric.
TS_API TsKeyFrame(const TsKeyFrame &kf)
Constructs a keyframe by duplicating an existing TsKeyFrame.
TS_API bool IsExtrapolatable() const
Gets whether the value type of this keyframe is extrapolatable.
TS_API void SetRightTangentLength(TsTime)
Sets the right-side tangent length (in time) of this knot.
TS_API bool GetIsDualValued() const
Gets whether this knot is dual-valued.
TS_API void SetLeftTangentSlope(VtValue)
Sets the left-side tangent slope (in units per frame) of this knot.
TS_API TsKeyFrame & operator=(const TsKeyFrame &rhs)
Assignment operator.
TS_API void SetKnotType(TsKnotType knotType)
Sets the knot type.
TS_API ~TsKeyFrame()
Non-virtual destructor; this class should not be subclassed.
TS_API TsKnotType GetKnotType() const
Gets the knot type.
TS_API TsKeyFrame()
Constructs a default double keyframe.
TS_API void SetLeftValue(VtValue val)
Sets the left value of this dual-valued knot.
TS_API VtValue GetLeftValueDerivative() const
Gets the value of the derivative on the left side.
TS_API bool HasTangents() const
Gets whether the knot of this keyframe has tangents.
TS_API bool GetTangentSymmetryBroken() const
Gets whether tangent symmetry has been broken.
TS_API bool SupportsTangents() const
Gets whether the value type of this keyframe supports tangents.
TS_API void SetValue(VtValue val)
Sets the value at this keyframe.
TS_API bool CanSetKnotType(TsKnotType, std::string *reason=NULL) const
Checks whether the key frame's value type supports the given knot type.
TS_API void SetTangentSymmetryBroken(bool broken)
Sets whether tangent symmetry is broken.
TS_API TsKeyFrame(const TsTime &time, const VtValue &val, TsKnotType knotType=TsKnotLinear, const VtValue &leftTangentSlope=VtValue(), const VtValue &rightTangentSlope=VtValue(), TsTime leftTangentLength=0, TsTime rightTangentLength=0)
Constructs a single-valued keyframe with VtValues.
TS_API void SetLeftTangentLength(TsTime)
Sets the left-side tangent length (in time) of this knot.
TS_API void SetRightTangentSlope(VtValue newSlope)
Sets the right-side tangent slope (in units per frame) of this knot.
TS_API VtValue GetLeftValue() const
Gets the left value of this dual-valued knot.
TS_API void SetIsDualValued(bool isDual)
Sets whether this knot is dual-valued.
TS_API VtValue GetLeftTangentSlope() const
Gets the left-side tangent slope (in units per frame) of this knot.
TS_API TsTime GetRightTangentLength() const
Gets the length of the projection of the knot's right tangent onto the time axis.
TS_API VtValue GetRightTangentSlope() const
Gets the right-side tangent slope (in units per frame) of this knot.
TS_API VtValue GetValue(TsSide side) const
Gets the value at this keyframe on the given side.
TS_API void SetTime(const TsTime &newTime)
Sets the time of this keyframe.
Definition: keyFrame.h:145
TS_API VtValue GetValue() const
Gets the value at this keyframe.
TS_API TsTime GetLeftTangentLength() const
Gets the length of the projection of the knot's left tangent onto the time axis.
TS_API bool IsEquivalentAtSide(const TsKeyFrame &keyFrame, TsSide side) const
Gets whether this key frame is at the same time and is equivalent to keyFrame on the given side.
TS_API void SetValue(VtValue val, TsSide side)
Sets the value at this keyframe on the given side.
TS_API bool operator==(const TsKeyFrame &) const
Compare this keyframe with another.
TS_API TsTime GetTime() const
Gets the time of this keyframe.
Definition: keyFrame.h:139
TS_API VtValue GetZero() const
Gets a zero for this keyframe's value type.
Represents a spline value object.
Definition: spline.h:51
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:147
Demangle C++ typenames generated by the typeid() facility.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
Definitions of basic string utilities in tf.