HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
spline_KeyFrames.h
Go to the documentation of this file.
1 //
2 // Copyright 2023 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 
25 #ifndef PXR_BASE_TS_SPLINE_KEY_FRAMES_H
26 #define PXR_BASE_TS_SPLINE_KEY_FRAMES_H
27 
28 #include "pxr/pxr.h"
29 #include "pxr/base/ts/keyFrame.h"
31 #include "pxr/base/ts/loopParams.h"
32 #include "pxr/base/ts/types.h"
33 #include "pxr/base/vt/value.h"
34 
35 #include <vector>
36 #include <map>
37 #include <typeinfo>
38 
40 
41 /// \class TsSpline_KeyFrames
42 /// \brief Maintains the keyframes for a spline
43 ///
44 /// The TsSpline_KeyFrames is a private class that holds onto and provides
45 /// API for interacting with the spline's keyframes. Its principle duty
46 /// is to manage the looping/non-looping representations of the spline. This
47 /// class should only be held by TsSpline.
48 ///
50 {
51 public:
54 
55  /// Generalized copy constructor.
56  ///
57  /// If \a keyFrames is not NULL, this constructor has the same behavior
58  /// as first copying other, then calling SetKeyFrames with keyFrames.
60  TsKeyFrameMap const *keyFrames = NULL);
61 
62  /// Gets the looped or unlooped keys, according to whether the spline is
63  /// looping.
64  const TsKeyFrameMap & GetKeyFrames() const;
65 
66  /// If looping, just writes to the non unrolled intervals.
67  void SetKeyFrames(const TsKeyFrameMap&);
68 
69  /// Replaces the key frames of this spline with keyFrames, and replaces
70  /// the contents of keyFrames with the key frames in this spline. If
71  /// the spline is looping, the data put into keyFrames will be the key
72  /// frames from the looped view of the spline, and hidden keys will be
73  /// preserved when keyFrames is swapped into this spline.
74  void SwapKeyFrames(std::vector<TsKeyFrame>* keyFrames);
75 
76  /// If looping, just writes to the non unrolled intervals.
78  *intervalAffected=NULL );
79 
80  /// If looping, just affects the non unrolled intervals.
82  *intervalAffected=NULL );
83 
84  /// Clears both maps.
85  void Clear();
86 
87  /// Gets the underlying normal keys.
88  const TsKeyFrameMap & GetNormalKeyFrames() const;
89 
90  /// Get the loop parameters.
91  const TsLoopParams &GetLoopParams() const;
92 
93  /// Sets the loop parameters.
94  void SetLoopParams(const TsLoopParams &loopParams);
95 
96  /// Get the left and right extrapolation.
98 
99  /// Sets the left and right extrapolation.
100  void SetExtrapolation(const TsExtrapolationPair &extrapolation);
101 
102  bool operator==(const TsSpline_KeyFrames &rhs) const;
103 
104  // Bakes looped key frames out and turns looping off.
105  void BakeSplineLoops();
106 
107 private:
108  typedef std::pair<TsKeyFrameMap::iterator,
109  TsKeyFrameMap::iterator> _KeyFrameRange;
110 
111  // Get a pointer to the keyframes that lets us change them
112  TsKeyFrameMap *_GetKeyFramesMutable();
113 
114  // Returns the time interval affected by an edit to a keyframe at
115  // the given time.
116  GfInterval _GetTimeInterval( TsTime time );
117 
118  // Copy the normal to the looped and then unroll the master keys
119  void _SetLoopedFromNormal();
120 
121  // Copy the master, prepeat and repeated intervals from the looped keys to
122  // the normal keys
123  void _SetNormalFromLooped();
124 
125  // Unroll the master interval of the looped keys to itself; clears the
126  // entire unrolled region first
127  void _UnrollMaster();
128 
129  void _UnrollKeyFrames(TsKeyFrameMap *keyFrames,
130  const TsLoopParams &params);
131 
132  // Unroll the given range of _loopedKeyFrames. If times is given, return
133  // the times that were written. Does not clear the unrolled region before
134  // writing.
135  void _UnrollKeyFrameRange(TsKeyFrameMap *keyFrames,
136  const TsKeyFrameMap::iterator &k0,
137  const TsKeyFrameMap::iterator &k1,
138  const TsLoopParams &params,
139  std::vector<TsTime> *times = NULL);
140 
141  // Returns the range of keyframes including time as non-const iterators.
142  // If there is a keyframe at \p time then this is the keyframe before the
143  // keyframe at \p time to the keyframe after that one. If there isn't a
144  // keyframe at \p time then it's the closest keyframes before and after \p
145  // time.
146  _KeyFrameRange _GetKeyFrameRange( TsTime time );
147 
148  // Returns the range of keyframes including the time interval as non-const
149  // iterators. These are the key frames from the key frame before (not at)
150  // \p leftTime to the key frame after (not at) \p rightTime.
151  _KeyFrameRange _GetKeyFrameRange( TsTime leftTime, TsTime rightTime );
152 
153  // Returns the time interval that will be changed by removing a key frame
154  // at the given \p time.
155  GfInterval _FindRemoveKeyFrameChangedInterval(TsTime time);
156 
157  // Returns the time interval that will be changed by setting the given
158  // \p keyFrame on the spline.
159  GfInterval _FindSetKeyFrameChangedInterval(const TsKeyFrame &keyFrame);
160 
161  // Determine the effective extrapolation for \p keyframe on \p side
162  TsExtrapolationType _GetEffectiveExtrapolationType(
163  const TsKeyFrame &keyFrame,
164  const TsSide &side) const;
165 
166  /// The Spline calls these when the loop params have changed.
167  void _LoopParamsChanged(bool loopingChanged, bool valueOffsetChanged,
168  bool domainChanged);
169 
170 private:
171  friend class TsKeyFrameEvalUtil;
172  friend class TsSpline;
173 
174  TsExtrapolationPair _extrapolation;
175  TsLoopParams _loopParams;
176  TsKeyFrameMap _normalKeyFrames;
177  TsKeyFrameMap _loopedKeyFrames;
178 };
179 
181 
182 #endif
const TsExtrapolationPair & GetExtrapolation() const
Get the left and right extrapolation.
TsExtrapolationType
Spline extrapolation types.
Definition: types.h:77
const TsLoopParams & GetLoopParams() const
Get the loop parameters.
GT_API const UT_StringHolder time
void SetExtrapolation(const TsExtrapolationPair &extrapolation)
Sets the left and right extrapolation.
GLenum const GLfloat * params
Definition: glcorearb.h:105
An ordered sequence of keyframes with STL-compliant API for finding, inserting, and erasing keyframes...
Definition: keyFrameMap.h:50
friend class TsKeyFrameEvalUtil
void SetLoopParams(const TsLoopParams &loopParams)
Sets the loop parameters.
std::vector< TsKeyFrame >::iterator iterator
Definition: keyFrameMap.h:53
void RemoveKeyFrame(TsTime t, GfInterval *intervalAffected=NULL)
If looping, just affects the non unrolled intervals.
Specifies the value of an TsSpline object at a particular point in time.
Definition: keyFrame.h:66
GLdouble t
Definition: glad.h:2397
PXR_NAMESPACE_OPEN_SCOPE typedef double TsTime
The time type used by Ts.
Definition: types.h:57
void SwapKeyFrames(std::vector< TsKeyFrame > *keyFrames)
TsSide
Dual-value keyframe side.
Definition: types.h:90
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
Maintains the keyframes for a spline.
const TsKeyFrameMap & GetNormalKeyFrames() const
Gets the underlying normal keys.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
bool operator==(const TsSpline_KeyFrames &rhs) const
std::pair< TsExtrapolationType, TsExtrapolationType > TsExtrapolationPair
A pair of TsExtrapolationTypes indicating left and right extrapolation in first and second...
Definition: types.h:87
void SetKeyFrames(const TsKeyFrameMap &)
If looping, just writes to the non unrolled intervals.
void SetKeyFrame(TsKeyFrame kf, GfInterval *intervalAffected=NULL)
If looping, just writes to the non unrolled intervals.
const TsKeyFrameMap & GetKeyFrames() const
void Clear()
Clears both maps.