Loading...
Searching...
No Matches
types.h
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
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.
48#include "pxr/base/tf/weakPtrFacade.h"
49#include "pxr/base/vt/array.h"
50#include "pxr/base/vt/value.h"
51#include <string>
52#include <map>
53
54PXR_NAMESPACE_OPEN_SCOPE
55
57typedef double TsTime;
58
64enum TsKnotType {
65 TsKnotHeld = 0,
66 TsKnotLinear,
67 TsKnotBezier,
68
69 TsKnotNumTypes
70};
71
77enum TsExtrapolationType {
78 TsExtrapolationHeld = 0,
79 TsExtrapolationLinear,
80
81 TsExtrapolationNumTypes
82};
83
86typedef std::pair<TsExtrapolationType,TsExtrapolationType>
87 TsExtrapolationPair;
88
90enum TsSide {
91 TsLeft,
92 TsRight
93};
94
98typedef struct TsValueSample {
99public:
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
110public:
111 bool isBlur;
112 TsTime leftTime;
113 TsTime rightTime;
117
119typedef 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//
130template <typename T>
131struct 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
154template <>
155struct 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
163template <>
164struct 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
172template <>
173struct TS_API TsTraits<float> {
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
181template <>
182struct 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
190template <>
191struct 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
199template <>
200struct TS_API TsTraits<GfVec2d> {
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
208template <>
209struct TS_API TsTraits<GfVec2f> {
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
217template <>
218struct TS_API TsTraits<GfVec3d> {
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
226template <>
227struct TS_API TsTraits<GfVec3f> {
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
235template <>
236struct TS_API TsTraits<GfVec4d> {
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
244template <>
245struct TS_API TsTraits<GfVec4f> {
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
253template <>
254struct TS_API TsTraits<GfQuatd> {
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
262template <>
263struct TS_API TsTraits<GfQuatf> {
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
271template <>
272struct TS_API TsTraits<GfMatrix2d> {
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
280template <>
281struct TS_API TsTraits<GfMatrix3d> {
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
289template <>
290struct TS_API TsTraits<GfMatrix4d> {
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
298template <>
299struct 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
307template <>
308struct TS_API TsTraits< VtArray<float> > {
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
317template <>
318struct TS_API TsTraits<TfToken> {
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
326PXR_NAMESPACE_CLOSE_SCOPE
327
328#endif
Stores a 2x2 matrix of double elements.
Definition: matrix2d.h:62
Stores a 3x3 matrix of double elements.
Definition: matrix3d.h:82
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quatd.h:60
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quatf.h:60
Basic type for a vector of 2 double components.
Definition: vec2d.h:63
Basic type for a vector of 2 float components.
Definition: vec2f.h:63
Basic type for a vector of 3 double components.
Definition: vec3d.h:63
Basic type for a vector of 3 float components.
Definition: vec3f.h:63
Basic type for a vector of 4 double components.
Definition: vec4d.h:63
Basic type for a vector of 4 float components.
Definition: vec4f.h:63
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
Represents an arbitrary dimensional rectangular container class.
Definition: array.h:228
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:164
STL namespace.
This file defines some macros that are useful for declaring and using static TfTokens.
An individual sample.
Definition: types.h:98
TsTime leftTime
Left side time (inclusive)
Definition: types.h:112
VtValue leftValue
Value at left or, for blur, min value.
Definition: types.h:114
bool isBlur
True if a blur sample.
Definition: types.h:111
TsTime rightTime
Right side time (exclusive)
Definition: types.h:113
VtValue rightValue
Value at right or, for blur, max value.
Definition: types.h:115
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...