HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
types.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_TYPES_H
26 #define PXR_BASE_TS_TYPES_H
27 
28 #include "pxr/pxr.h"
29 #include "pxr/base/ts/api.h"
30 
31 #include "pxr/base/gf/vec2d.h"
32 #include "pxr/base/gf/vec3d.h"
33 #include "pxr/base/gf/vec4d.h"
34 #include "pxr/base/gf/vec4i.h"
35 #include "pxr/base/gf/quatd.h"
36 #include "pxr/base/gf/quatf.h"
37 
38 #include "pxr/base/gf/matrix2d.h"
39 #include "pxr/base/gf/matrix3d.h"
40 #include "pxr/base/gf/matrix4d.h"
41 #include "pxr/base/gf/interval.h"
43 #include "pxr/base/gf/range1d.h"
45 #include "pxr/base/tf/token.h"
46 // Including weakPtrFacade.h before vt/value.h works around a problem
47 // finding get_pointer.
49 #include "pxr/base/vt/array.h"
50 #include "pxr/base/vt/value.h"
51 #include <string>
52 #include <map>
53 
55 
56 /// The time type used by Ts.
57 typedef double TsTime;
58 
59 /// \brief Keyframe knot types.
60 ///
61 /// These specify the method used to interpolate keyframes.
62 /// This enum is registered with TfEnum for conversion to/from std::string.
63 ///
64 enum TsKnotType {
65  TsKnotHeld = 0, //!< A held-value knot; tangents will be ignored
66  TsKnotLinear, //!< A Linear knot; tangents will be ignored
67  TsKnotBezier, //!< A Bezier knot
68 
70 };
71 
72 /// \brief Spline extrapolation types.
73 ///
74 /// These specify the method used to extrapolate splines.
75 /// This enum is registered with TfEnum for conversion to/from std::string.
76 ///
78  TsExtrapolationHeld = 0, //!< Held; splines hold values at edges
79  TsExtrapolationLinear, //!< Linear; splines hold slopes at edges
80 
82 };
83 
84 /// \brief A pair of TsExtrapolationTypes indicating left
85 /// and right extrapolation in first and second, respectively.
86 typedef std::pair<TsExtrapolationType,TsExtrapolationType>
88 
89 /// \brief Dual-value keyframe side.
90 enum TsSide {
93 };
94 
95 /// \brief An individual sample. A sample is either a blur, defining a
96 /// rectangle, or linear, defining a line for linear interpolation.
97 /// In both cases the sample is half-open on the right.
98 typedef struct TsValueSample {
99 public:
100  TsValueSample(TsTime inLeftTime, const VtValue& inLeftValue,
101  TsTime inRightTime, const VtValue& inRightValue,
102  bool inBlur = false) :
103  isBlur(inBlur),
104  leftTime(inLeftTime),
105  rightTime(inRightTime),
106  leftValue(inLeftValue),
107  rightValue(inRightValue)
108  {}
109 
110 public:
111  bool isBlur; //!< True if a blur sample
112  TsTime leftTime; //!< Left side time (inclusive)
113  TsTime rightTime; //!< Right side time (exclusive)
114  VtValue leftValue; //!< Value at left or, for blur, min value
115  VtValue rightValue; //!< Value at right or, for blur, max value
116 } TsValueSample;
117 
118 /// A sequence of samples.
119 typedef std::vector<TsValueSample> TsSamples;
120 
121 // Traits for types used in TsSplines.
122 //
123 // Depending on a type's traits, different interpolation techniques are
124 // available:
125 //
126 // * if not interpolatable, only TsKnotHeld can be used
127 // * if interpolatable, TsKnotHeld and TsKnotLinear can be used
128 // * if supportsTangents, any knot type can be used
129 //
130 template <typename T>
131 struct TsTraits {
132  // True if this is a valid value type for splines.
133  // Default is false; set to true for all supported types.
134  static const bool isSupportedSplineValueType = false;
135 
136  // True if the type can be interpolated by taking linear combinations.
137  // If this is false, only TsKnotHeld is isSupportedSplineValueType.
138  static const bool interpolatable = true;
139 
140  // True if the value can be extrapolated outside of the keyframe
141  // range. If this is false we always use TsExtrapolateHeld behaviour.
142  // This is true if a slope can be computed from the line between two knots
143  // of this type.
144  static const bool extrapolatable = false;
145 
146  // True if the value type supports tangents.
147  // If true, interpolatable must also be true.
148  static const bool supportsTangents = true;
149 
150  // The origin or zero vector for this type.
151  static const T zero;
152 };
153 
154 template <>
155 struct TS_API TsTraits<std::string> {
156  static const bool isSupportedSplineValueType = true;
157  static const bool interpolatable = false;
158  static const bool extrapolatable = false;
159  static const bool supportsTangents = false;
160  static const std::string zero;
161 };
162 
163 template <>
164 struct TS_API TsTraits<double> {
165  static const bool isSupportedSplineValueType = true;
166  static const bool interpolatable = true;
167  static const bool extrapolatable = true;
168  static const bool supportsTangents = true;
169  static const double zero;
170 };
171 
172 template <>
174  static const bool isSupportedSplineValueType = true;
175  static const bool interpolatable = true;
176  static const bool extrapolatable = true;
177  static const bool supportsTangents = true;
178  static const float zero;
179 };
180 
181 template <>
182 struct TS_API TsTraits<int> {
183  static const bool isSupportedSplineValueType = true;
184  static const bool interpolatable = false;
185  static const bool extrapolatable = false;
186  static const bool supportsTangents = false;
187  static const int zero;
188 };
189 
190 template <>
191 struct TS_API TsTraits<bool> {
192  static const bool isSupportedSplineValueType = true;
193  static const bool interpolatable = false;
194  static const bool extrapolatable = false;
195  static const bool supportsTangents = false;
196  static const bool zero;
197 };
198 
199 template <>
201  static const bool isSupportedSplineValueType = true;
202  static const bool interpolatable = true;
203  static const bool extrapolatable = true;
204  static const bool supportsTangents = false;
205  static const GfVec2d zero;
206 };
207 
208 template <>
210  static const bool isSupportedSplineValueType = true;
211  static const bool interpolatable = true;
212  static const bool extrapolatable = true;
213  static const bool supportsTangents = false;
214  static const GfVec2f zero;
215 };
216 
217 template <>
219  static const bool isSupportedSplineValueType = true;
220  static const bool interpolatable = true;
221  static const bool extrapolatable = true;
222  static const bool supportsTangents = false;
223  static const GfVec3d zero;
224 };
225 
226 template <>
228  static const bool isSupportedSplineValueType = true;
229  static const bool interpolatable = true;
230  static const bool extrapolatable = true;
231  static const bool supportsTangents = false;
232  static const GfVec3f zero;
233 };
234 
235 template <>
237  static const bool isSupportedSplineValueType = true;
238  static const bool interpolatable = true;
239  static const bool extrapolatable = true;
240  static const bool supportsTangents = false;
241  static const GfVec4d zero;
242 };
243 
244 template <>
246  static const bool isSupportedSplineValueType = true;
247  static const bool interpolatable = true;
248  static const bool extrapolatable = true;
249  static const bool supportsTangents = false;
250  static const GfVec4f zero;
251 };
252 
253 template <>
255  static const bool isSupportedSplineValueType = true;
256  static const bool interpolatable = true;
257  static const bool extrapolatable = false;
258  static const bool supportsTangents = false;
259  static const GfQuatd zero;
260 };
261 
262 template <>
264  static const bool isSupportedSplineValueType = true;
265  static const bool interpolatable = true;
266  static const bool extrapolatable = false;
267  static const bool supportsTangents = false;
268  static const GfQuatf zero;
269 };
270 
271 template <>
273  static const bool isSupportedSplineValueType = true;
274  static const bool interpolatable = true;
275  static const bool extrapolatable = true;
276  static const bool supportsTangents = false;
277  static const GfMatrix2d zero;
278 };
279 
280 template <>
282  static const bool isSupportedSplineValueType = true;
283  static const bool interpolatable = true;
284  static const bool extrapolatable = true;
285  static const bool supportsTangents = false;
286  static const GfMatrix3d zero;
287 };
288 
289 template <>
291  static const bool isSupportedSplineValueType = true;
292  static const bool interpolatable = true;
293  static const bool extrapolatable = true;
294  static const bool supportsTangents = false;
295  static const GfMatrix4d zero;
296 };
297 
298 template <>
299 struct TS_API TsTraits< VtArray<double> > {
300  static const bool isSupportedSplineValueType = true;
301  static const bool interpolatable = true;
302  static const bool extrapolatable = true;
303  static const bool supportsTangents = false;
304  static const VtArray<double> zero;
305 };
306 
307 template <>
309  static const bool isSupportedSplineValueType = true;
310  static const bool interpolatable = true;
311  static const bool extrapolatable = true;
312  static const bool supportsTangents = false;
313  static const bool supportsVaryingShapes = false;
314  static const VtArray<float> zero;
315 };
316 
317 template <>
319  static const bool isSupportedSplineValueType = true;
320  static const bool interpolatable = false;
321  static const bool extrapolatable = false;
322  static const bool supportsTangents = false;
323  static const TfToken zero;
324 };
325 
327 
328 #endif
TsExtrapolationType
Spline extrapolation types.
Definition: types.h:77
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
TsTime rightTime
Right side time (exclusive)
Definition: types.h:113
Held; splines hold values at edges.
Definition: types.h:78
A Linear knot; tangents will be ignored.
Definition: types.h:66
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
An individual sample. A sample is either a blur, defining a rectangle, or linear, defining a line for...
Definition: types.h:98
A held-value knot; tangents will be ignored.
Definition: types.h:65
Definition: vec3f.h:62
static const GfVec4f zero
Definition: types.h:250
static const GfMatrix2d zero
Definition: types.h:277
A Bezier knot.
Definition: types.h:67
Definition: vec4d.h:62
static const int zero
Definition: types.h:187
Definition: types.h:92
static const GfQuatf zero
Definition: types.h:268
static const T zero
Definition: types.h:151
Definition: quatf.h:59
Definition: vec2d.h:62
VtValue leftValue
Value at left or, for blur, min value.
Definition: types.h:114
static const bool extrapolatable
Definition: types.h:144
static const GfVec3f zero
Definition: types.h:232
Definition: token.h:87
IMATH_NAMESPACE::V2f float
TsKnotType
Keyframe knot types.
Definition: types.h:64
std::vector< TsValueSample > TsSamples
A sequence of samples.
Definition: types.h:119
static const VtArray< float > zero
Definition: types.h:314
Linear; splines hold slopes at edges.
Definition: types.h:79
static const VtArray< double > zero
Definition: types.h:304
static const GfVec2d zero
Definition: types.h:205
VtValue rightValue
Value at right or, for blur, max value.
Definition: types.h:115
Definition: types.h:170
static const bool isSupportedSplineValueType
Definition: types.h:134
PXR_NAMESPACE_OPEN_SCOPE typedef double TsTime
The time type used by Ts.
Definition: types.h:57
#define TS_API
Definition: api.h:41
static const GfVec3d zero
Definition: types.h:223
Definition: vec4f.h:62
TsSide
Dual-value keyframe side.
Definition: types.h:90
static const bool interpolatable
Definition: types.h:138
static const GfQuatd zero
Definition: types.h:259
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
static const TfToken zero
Definition: types.h:323
static const bool zero
Definition: types.h:196
struct TsValueSample TsValueSample
An individual sample. A sample is either a blur, defining a rectangle, or linear, defining a line for...
Definition: vec2f.h:62
Definition: vec3d.h:62
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
TsTime leftTime
Left side time (inclusive)
Definition: types.h:112
std::pair< TsExtrapolationType, TsExtrapolationType > TsExtrapolationPair
A pair of TsExtrapolationTypes indicating left and right extrapolation in first and second...
Definition: types.h:87
static const GfMatrix3d zero
Definition: types.h:286
Definition: quatd.h:59
static const GfMatrix4d zero
Definition: types.h:295
static const std::string zero
Definition: types.h:160
Definition: types.h:91
static const float zero
Definition: types.h:178
TsValueSample(TsTime inLeftTime, const VtValue &inLeftValue, TsTime inRightTime, const VtValue &inRightValue, bool inBlur=false)
Definition: types.h:100
static const double zero
Definition: types.h:169
Definition: value.h:164
static const bool supportsTangents
Definition: types.h:148
bool isBlur
True if a blur sample.
Definition: types.h:111
static const GfVec2f zero
Definition: types.h:214
static const GfVec4d zero
Definition: types.h:241