Loading...
Searching...
No Matches
types.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_TYPES_H
9#define PXR_BASE_TS_TYPES_H
10
11#include "pxr/pxr.h"
12#include "pxr/base/ts/api.h"
13
14#include "pxr/base/gf/vec2d.h"
15#include "pxr/base/gf/vec3d.h"
16#include "pxr/base/gf/vec4d.h"
17#include "pxr/base/gf/vec4i.h"
18#include "pxr/base/gf/quatd.h"
19#include "pxr/base/gf/quatf.h"
20
26#include "pxr/base/gf/range1d.h"
28#include "pxr/base/tf/token.h"
29// Including weakPtrFacade.h before vt/value.h works around a problem
30// finding get_pointer.
31#include "pxr/base/tf/weakPtrFacade.h"
32#include "pxr/base/vt/array.h"
33#include "pxr/base/vt/value.h"
34#include <string>
35#include <map>
36
37PXR_NAMESPACE_OPEN_SCOPE
38
40typedef double TsTime;
41
47enum TsKnotType {
48 TsKnotHeld = 0,
49 TsKnotLinear,
50 TsKnotBezier,
51
52 TsKnotNumTypes
53};
54
60enum TsExtrapolationType {
61 TsExtrapolationHeld = 0,
62 TsExtrapolationLinear,
63
64 TsExtrapolationNumTypes
65};
66
69typedef std::pair<TsExtrapolationType,TsExtrapolationType>
70 TsExtrapolationPair;
71
73enum TsSide {
74 TsLeft,
75 TsRight
76};
77
81typedef struct TsValueSample {
82public:
83 TsValueSample(TsTime inLeftTime, const VtValue& inLeftValue,
84 TsTime inRightTime, const VtValue& inRightValue,
85 bool inBlur = false) :
86 isBlur(inBlur),
87 leftTime(inLeftTime),
88 rightTime(inRightTime),
89 leftValue(inLeftValue),
90 rightValue(inRightValue)
91 {}
92
93public:
94 bool isBlur;
95 TsTime leftTime;
96 TsTime rightTime;
100
102typedef std::vector<TsValueSample> TsSamples;
103
104// Traits for types used in TsSplines.
105//
106// Depending on a type's traits, different interpolation techniques are
107// available:
108//
109// * if not interpolatable, only TsKnotHeld can be used
110// * if interpolatable, TsKnotHeld and TsKnotLinear can be used
111// * if supportsTangents, any knot type can be used
112//
113template <typename T>
114struct TsTraits {
115 // True if this is a valid value type for splines.
116 // Default is false; set to true for all supported types.
117 static const bool isSupportedSplineValueType = false;
118
119 // True if the type can be interpolated by taking linear combinations.
120 // If this is false, only TsKnotHeld is isSupportedSplineValueType.
121 static const bool interpolatable = true;
122
123 // True if the value can be extrapolated outside of the keyframe
124 // range. If this is false we always use TsExtrapolateHeld behaviour.
125 // This is true if a slope can be computed from the line between two knots
126 // of this type.
127 static const bool extrapolatable = false;
128
129 // True if the value type supports tangents.
130 // If true, interpolatable must also be true.
131 static const bool supportsTangents = true;
132
133 // The origin or zero vector for this type.
134 static const T zero;
135};
136
137template <>
138struct TS_API TsTraits<std::string> {
139 static const bool isSupportedSplineValueType = true;
140 static const bool interpolatable = false;
141 static const bool extrapolatable = false;
142 static const bool supportsTangents = false;
143 static const std::string zero;
144};
145
146template <>
147struct TS_API TsTraits<double> {
148 static const bool isSupportedSplineValueType = true;
149 static const bool interpolatable = true;
150 static const bool extrapolatable = true;
151 static const bool supportsTangents = true;
152 static const double zero;
153};
154
155template <>
156struct TS_API TsTraits<float> {
157 static const bool isSupportedSplineValueType = true;
158 static const bool interpolatable = true;
159 static const bool extrapolatable = true;
160 static const bool supportsTangents = true;
161 static const float zero;
162};
163
164template <>
165struct TS_API TsTraits<int> {
166 static const bool isSupportedSplineValueType = true;
167 static const bool interpolatable = false;
168 static const bool extrapolatable = false;
169 static const bool supportsTangents = false;
170 static const int zero;
171};
172
173template <>
174struct TS_API TsTraits<bool> {
175 static const bool isSupportedSplineValueType = true;
176 static const bool interpolatable = false;
177 static const bool extrapolatable = false;
178 static const bool supportsTangents = false;
179 static const bool zero;
180};
181
182template <>
183struct TS_API TsTraits<GfVec2d> {
184 static const bool isSupportedSplineValueType = true;
185 static const bool interpolatable = true;
186 static const bool extrapolatable = true;
187 static const bool supportsTangents = false;
188 static const GfVec2d zero;
189};
190
191template <>
192struct TS_API TsTraits<GfVec2f> {
193 static const bool isSupportedSplineValueType = true;
194 static const bool interpolatable = true;
195 static const bool extrapolatable = true;
196 static const bool supportsTangents = false;
197 static const GfVec2f zero;
198};
199
200template <>
201struct TS_API TsTraits<GfVec3d> {
202 static const bool isSupportedSplineValueType = true;
203 static const bool interpolatable = true;
204 static const bool extrapolatable = true;
205 static const bool supportsTangents = false;
206 static const GfVec3d zero;
207};
208
209template <>
210struct TS_API TsTraits<GfVec3f> {
211 static const bool isSupportedSplineValueType = true;
212 static const bool interpolatable = true;
213 static const bool extrapolatable = true;
214 static const bool supportsTangents = false;
215 static const GfVec3f zero;
216};
217
218template <>
219struct TS_API TsTraits<GfVec4d> {
220 static const bool isSupportedSplineValueType = true;
221 static const bool interpolatable = true;
222 static const bool extrapolatable = true;
223 static const bool supportsTangents = false;
224 static const GfVec4d zero;
225};
226
227template <>
228struct TS_API TsTraits<GfVec4f> {
229 static const bool isSupportedSplineValueType = true;
230 static const bool interpolatable = true;
231 static const bool extrapolatable = true;
232 static const bool supportsTangents = false;
233 static const GfVec4f zero;
234};
235
236template <>
237struct TS_API TsTraits<GfQuatd> {
238 static const bool isSupportedSplineValueType = true;
239 static const bool interpolatable = true;
240 static const bool extrapolatable = false;
241 static const bool supportsTangents = false;
242 static const GfQuatd zero;
243};
244
245template <>
246struct TS_API TsTraits<GfQuatf> {
247 static const bool isSupportedSplineValueType = true;
248 static const bool interpolatable = true;
249 static const bool extrapolatable = false;
250 static const bool supportsTangents = false;
251 static const GfQuatf zero;
252};
253
254template <>
255struct TS_API TsTraits<GfMatrix2d> {
256 static const bool isSupportedSplineValueType = true;
257 static const bool interpolatable = true;
258 static const bool extrapolatable = true;
259 static const bool supportsTangents = false;
260 static const GfMatrix2d zero;
261};
262
263template <>
264struct TS_API TsTraits<GfMatrix3d> {
265 static const bool isSupportedSplineValueType = true;
266 static const bool interpolatable = true;
267 static const bool extrapolatable = true;
268 static const bool supportsTangents = false;
269 static const GfMatrix3d zero;
270};
271
272template <>
273struct TS_API TsTraits<GfMatrix4d> {
274 static const bool isSupportedSplineValueType = true;
275 static const bool interpolatable = true;
276 static const bool extrapolatable = true;
277 static const bool supportsTangents = false;
278 static const GfMatrix4d zero;
279};
280
281template <>
282struct TS_API TsTraits< VtArray<double> > {
283 static const bool isSupportedSplineValueType = true;
284 static const bool interpolatable = true;
285 static const bool extrapolatable = true;
286 static const bool supportsTangents = false;
287 static const VtArray<double> zero;
288};
289
290template <>
291struct TS_API TsTraits< VtArray<float> > {
292 static const bool isSupportedSplineValueType = true;
293 static const bool interpolatable = true;
294 static const bool extrapolatable = true;
295 static const bool supportsTangents = false;
296 static const bool supportsVaryingShapes = false;
297 static const VtArray<float> zero;
298};
299
300template <>
301struct TS_API TsTraits<TfToken> {
302 static const bool isSupportedSplineValueType = true;
303 static const bool interpolatable = false;
304 static const bool extrapolatable = false;
305 static const bool supportsTangents = false;
306 static const TfToken zero;
307};
308
309PXR_NAMESPACE_CLOSE_SCOPE
310
311#endif
Stores a 2x2 matrix of double elements.
Definition: matrix2d.h:45
Stores a 3x3 matrix of double elements.
Definition: matrix3d.h:65
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:71
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quatd.h:43
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quatf.h:43
Basic type for a vector of 2 double components.
Definition: vec2d.h:46
Basic type for a vector of 2 float components.
Definition: vec2f.h:46
Basic type for a vector of 3 double components.
Definition: vec3d.h:46
Basic type for a vector of 3 float components.
Definition: vec3f.h:46
Basic type for a vector of 4 double components.
Definition: vec4d.h:46
Basic type for a vector of 4 float components.
Definition: vec4f.h:46
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Represents an arbitrary dimensional rectangular container class.
Definition: array.h:211
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:147
STL namespace.
This file defines some macros that are useful for declaring and using static TfTokens.
An individual sample.
Definition: types.h:81
TsTime leftTime
Left side time (inclusive)
Definition: types.h:95
VtValue leftValue
Value at left or, for blur, min value.
Definition: types.h:97
bool isBlur
True if a blur sample.
Definition: types.h:94
TsTime rightTime
Right side time (exclusive)
Definition: types.h:96
VtValue rightValue
Value at right or, for blur, max value.
Definition: types.h:98
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...