Loading...
Searching...
No Matches
types.h
1//
2// Copyright 2024 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
17#include "pxr/base/gf/vec2d.h"
18#include "pxr/base/tf/preprocessorUtilsLite.h"
19
20#include <cstdint>
21#include <optional>
22#include <vector>
23
24PXR_NAMESPACE_OPEN_SCOPE
25
34#define TS_SPLINE_SUPPORTED_VALUE_TYPES \
35 ((Double, double)) \
36 ((Float, float)) \
37 ((Half, GfHalf)) \
38 ((TimeCode, GfTimeCode)) \
39 ((Duration, GfDuration))
40
41#define TS_SPLINE_STORAGE_VALUE_TYPES \
42 ((Double, double)) \
43 ((Float, float)) \
44 ((Half, GfHalf))
45
46#define TS_SPLINE_SAMPLE_VERTEX_TYPES \
47 ((Vec2d, GfVec2d)) \
48 ((Vec2f, GfVec2f)) \
49 ((Vec2h, GfVec2h))
50
51#define TS_SPLINE_VALUE_TYPE_NAME(x) TF_PP_TUPLE_ELEM(0, x)
52#define TS_SPLINE_VALUE_CPP_TYPE(x) TF_PP_TUPLE_ELEM(1, x)
53
55template <class T>
56inline constexpr bool
57TsSplineIsValidDataType = false;
58
59#define _TS_SUPPORT_DATA_TYPE(unused, tuple) \
60 template <> \
61 inline constexpr bool \
62 TsSplineIsValidDataType< TS_SPLINE_VALUE_CPP_TYPE(tuple) > = true;
63TF_PP_SEQ_FOR_EACH(_TS_SUPPORT_DATA_TYPE,
64 ~,
65 TS_SPLINE_SUPPORTED_VALUE_TYPES)
66#undef _TS_SUPPORT_DATA_TYPE
67
70template <class T>
71inline constexpr bool
72TsSplineIsValidSampleType = false;
73
74#define _TS_SUPPORT_SAMPLE_TYPE(unused, tuple) \
75 template <> \
76 inline constexpr bool \
77 TsSplineIsValidSampleType< TS_SPLINE_VALUE_CPP_TYPE(tuple) > = true;
78TF_PP_SEQ_FOR_EACH(_TS_SUPPORT_SAMPLE_TYPE,
79 ~,
80 TS_SPLINE_SAMPLE_VERTEX_TYPES)
81#undef _TS_SUPPORT_SAMPLE_TYPE
82
83// Times are encoded as double.
84using TsTime = double;
85
87// ** NOTE TO MAINTAINERS **
88//
89// The following enum values are used in the binary crate format.
90// Do not change them; only add.
91
94enum TsInterpMode
95{
96 TsInterpValueBlock = 0, //< No value in this segment.
97 TsInterpHeld = 1, //< Constant value in this segment.
98 TsInterpLinear = 2, //< Linear interpolation.
99 TsInterpCurve = 3 //< Bezier or Hermite, depends on curve type.
100};
101
104enum TsCurveType
105{
106 TsCurveTypeBezier = 0, //< Bezier curve, free tangent widths.
107 TsCurveTypeHermite = 1 //< Hermite curve, like Bezier but fixed tan width.
108};
109
115enum TsExtrapMode
116{
117 TsExtrapValueBlock = 0, //< No value in this region.
118 TsExtrapHeld = 1, //< Constant value in this region.
119 TsExtrapLinear = 2, //< Linear interpolation based on edge knots.
120 TsExtrapSloped = 3, //< Linear interpolation with specified slope.
121 TsExtrapLoopRepeat = 4, //< Knot curve repeated, offset so ends meet.
122 TsExtrapLoopReset = 5, //< Curve repeated exactly, discontinuous joins.
123 TsExtrapLoopOscillate = 6 //< Like Reset, but every other copy reversed.
124};
125
132enum TsSplineSampleSource
133{
134 TsSourcePreExtrap, //< Extrapolation before the first knot
135 TsSourcePreExtrapLoop, //< Looped extrapolation before the first knot
136 TsSourceInnerLoopPreEcho, //< Echoed copy of an inner loop prototype
137 TsSourceInnerLoopProto, //< This is the inner loop prototype
138 TsSourceInnerLoopPostEcho, //< Echoed copy of an inner loop prototype
139 TsSourceKnotInterp, //< "Normal" knot interpolation
140 TsSourcePostExtrap, //< Extrapolation after the last knot
141 TsSourcePostExtrapLoop, //< Looped extrapolation after the last knot
142};
143
167enum TsTangentAlgorithm
168{
169 TsTangentAlgorithmNone,
170 TsTangentAlgorithmCustom,
171 TsTangentAlgorithmAutoEase
172};
173
207{
208public:
209 TsTime protoStart = 0.0;
210 TsTime protoEnd = 0.0;
211 int32_t numPreLoops = 0;
212 int32_t numPostLoops = 0;
213 double valueOffset = 0.0;
214
215public:
216 TS_API
217 bool operator==(const TsLoopParams &other) const;
218
219 TS_API
220 bool operator!=(const TsLoopParams &other) const;
221
223 TS_API
225
227 TS_API
229};
230
234{
235public:
236 TsExtrapMode mode = TsExtrapHeld;
237
238 // Used only in TsExtrapSloped mode. Specifies slope of the extrapolated
239 // segment.
240 double slope = 0.0;
241
242 // Used only in looping extrapolation modes to optionally specify a
243 // subsection of the spline.
244 //
245 // This setting is incompatible with inner looping. Attempts to set
246 // extrapolation with a non-null loopBoundaryTime on a spline with inner
247 // looping, and vice versa, will cause a TF_CODING_ERROR to be issued.
248 //
249 // When this has no value, this extrapolation loops the full knot region.
250 //
251 // When this has a value that is exactly a knot time,
252 // this extrapolation loops the knot subregion demarcated by
253 // loopBoundaryTime and the knot subregion's start for post-extrapolation
254 // or end for pre-extrapolation.
255 //
256 // There are a few degenerate cases.
257 // - This has a value that isn't exactly a knot time. The resulting
258 // extrapolation is value block.
259 // - This has a value that is the start knot time for pre-extrapolation,
260 // or end knot time for post-extrapolation. The resulting extrapolation
261 // is held, and has the same behavior as TsExtrapHeld.
262 std::optional<double> loopBoundaryTime;
263
264public:
265 TS_API
267
268 TS_API
269 TsExtrapolation(TsExtrapMode mode);
270
275 TS_API
276 TsExtrapolation(TsExtrapMode mode, double slope);
277
278 TS_API
279 bool operator==(const TsExtrapolation &other) const;
280
281 TS_API
282 bool operator!=(const TsExtrapolation &other) const;
283
285 TS_API
286 bool IsLooping() const;
287};
288
296template <typename Vertex>
298{
299public:
300 static_assert(TsSplineIsValidSampleType<Vertex>,
301 "The Vertex template parameter to TsSplineSamples must be one"
302 " of GfVec2d, GfVec2f, or GfVec2h.");
303
304 using Polyline = std::vector<Vertex>;
305
306 std::vector<Polyline> polylines;
307};
308
319template <typename Vertex>
321{
322public:
323 static_assert(TsSplineIsValidSampleType<Vertex>,
324 "The Vertex template parameter to TsSplineSamplesWithSources"
325 " must be one of GfVec2d, GfVec2f, or GfVec2h.");
326
327 using Polyline = std::vector<Vertex>;
328
329 std::vector<Polyline> polylines;
330 std::vector<TsSplineSampleSource> sources;
331};
332
338enum TsAntiRegressionMode
339{
342 TsAntiRegressionNone,
343
348 TsAntiRegressionContain,
349
354 TsAntiRegressionKeepRatio,
355
359 TsAntiRegressionKeepStart
360};
361
362
363PXR_NAMESPACE_CLOSE_SCOPE
364
365#endif
A basic mathematical interval class.
Definition interval.h:33
Extrapolation parameters for the ends of a spline beyond the knots.
Definition types.h:234
TS_API bool IsLooping() const
Returns whether our mode is one of the looping extrapolation modes.
TS_API TsExtrapolation(TsExtrapMode mode, double slope)
Construct a TsExtrapolation with the given mode and slope.
Inner-loop parameters.
Definition types.h:207
TS_API GfInterval GetLoopedInterval() const
Returns the union of the prototype region and the echo region(s).
TS_API GfInterval GetPrototypeInterval() const
Returns the prototype region, [protoStart, protoEnd).
TsSplineSamples<Vertex> holds a collection of piecewise linear polylines that approximate a TsSpline.
Definition types.h:298
TsSplineSamplesWithSources<Vertex> is a TsSplineSamples<Vertex> that also includes source information...
Definition types.h:321