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
16#include "pxr/base/gf/vec2d.h"
17#include "pxr/base/tf/preprocessorUtilsLite.h"
18
19#include <cstdint>
20#include <optional>
21#include <vector>
22
23PXR_NAMESPACE_OPEN_SCOPE
24
32#define TS_SPLINE_SUPPORTED_VALUE_TYPES \
33 ((Double, double)) \
34 ((Float, float)) \
35 ((Half, GfHalf)) \
36 ((TimeCode, GfTimeCode))
37
38#define TS_SPLINE_STORAGE_VALUE_TYPES \
39 ((Double, double)) \
40 ((Float, float)) \
41 ((Half, GfHalf))
42
43#define TS_SPLINE_SAMPLE_VERTEX_TYPES \
44 ((Vec2d, GfVec2d)) \
45 ((Vec2f, GfVec2f)) \
46 ((Vec2h, GfVec2h))
47
48#define TS_SPLINE_VALUE_TYPE_NAME(x) TF_PP_TUPLE_ELEM(0, x)
49#define TS_SPLINE_VALUE_CPP_TYPE(x) TF_PP_TUPLE_ELEM(1, x)
50
52template <class T>
53inline constexpr bool
54TsSplineIsValidDataType = false;
55
56#define _TS_SUPPORT_DATA_TYPE(unused, tuple) \
57 template <> \
58 inline constexpr bool \
59 TsSplineIsValidDataType< TS_SPLINE_VALUE_CPP_TYPE(tuple) > = true;
60TF_PP_SEQ_FOR_EACH(_TS_SUPPORT_DATA_TYPE,
61 ~,
62 TS_SPLINE_SUPPORTED_VALUE_TYPES)
63#undef _TS_SUPPORT_DATA_TYPE
64
67template <class T>
68inline constexpr bool
69TsSplineIsValidSampleType = false;
70
71#define _TS_SUPPORT_SAMPLE_TYPE(unused, tuple) \
72 template <> \
73 inline constexpr bool \
74 TsSplineIsValidSampleType< TS_SPLINE_VALUE_CPP_TYPE(tuple) > = true;
75TF_PP_SEQ_FOR_EACH(_TS_SUPPORT_SAMPLE_TYPE,
76 ~,
77 TS_SPLINE_SAMPLE_VERTEX_TYPES)
78#undef _TS_SUPPORT_SAMPLE_TYPE
79
80// Times are encoded as double.
81using TsTime = double;
82
84// ** NOTE TO MAINTAINERS **
85//
86// The following enum values are used in the binary crate format.
87// Do not change them; only add.
88
91enum TsInterpMode
92{
93 TsInterpValueBlock = 0, //< No value in this segment.
94 TsInterpHeld = 1, //< Constant value in this segment.
95 TsInterpLinear = 2, //< Linear interpolation.
96 TsInterpCurve = 3 //< Bezier or Hermite, depends on curve type.
97};
98
101enum TsCurveType
102{
103 TsCurveTypeBezier = 0, //< Bezier curve, free tangent widths.
104 TsCurveTypeHermite = 1 //< Hermite curve, like Bezier but fixed tan width.
105};
106
112enum TsExtrapMode
113{
114 TsExtrapValueBlock = 0, //< No value in this region.
115 TsExtrapHeld = 1, //< Constant value in this region.
116 TsExtrapLinear = 2, //< Linear interpolation based on edge knots.
117 TsExtrapSloped = 3, //< Linear interpolation with specified slope.
118 TsExtrapLoopRepeat = 4, //< Knot curve repeated, offset so ends meet.
119 TsExtrapLoopReset = 5, //< Curve repeated exactly, discontinuous joins.
120 TsExtrapLoopOscillate = 6 //< Like Reset, but every other copy reversed.
121};
122
129enum TsSplineSampleSource
130{
131 TsSourcePreExtrap, //< Extrapolation before the first knot
132 TsSourcePreExtrapLoop, //< Looped extrapolation before the first knot
133 TsSourceInnerLoopPreEcho, //< Echoed copy of an inner loop prototype
134 TsSourceInnerLoopProto, //< This is the inner loop prototype
135 TsSourceInnerLoopPostEcho, //< Echoed copy of an inner loop prototype
136 TsSourceKnotInterp, //< "Normal" knot interpolation
137 TsSourcePostExtrap, //< Extrapolation after the last knot
138 TsSourcePostExtrapLoop, //< Looped extrapolation after the last knot
139};
140
164enum TsTangentAlgorithm
165{
166 TsTangentAlgorithmNone,
167 TsTangentAlgorithmCustom,
168 TsTangentAlgorithmAutoEase
169};
170
204{
205public:
206 TsTime protoStart = 0.0;
207 TsTime protoEnd = 0.0;
208 int32_t numPreLoops = 0;
209 int32_t numPostLoops = 0;
210 double valueOffset = 0.0;
211
212public:
213 TS_API
214 bool operator==(const TsLoopParams &other) const;
215
216 TS_API
217 bool operator!=(const TsLoopParams &other) const;
218
220 TS_API
222
224 TS_API
226};
227
231{
232public:
233 TsExtrapMode mode = TsExtrapHeld;
234
235 // Used only in TsExtrapSloped mode. Specifies slope of the extrapolated
236 // segment.
237 double slope = 0.0;
238
239 // Used only in looping extrapolation modes to optionally specify a
240 // subsection of the spline.
241 //
242 // This setting is incompatible with inner looping. Attempts to set
243 // extrapolation with a non-null loopBoundaryTime on a spline with inner
244 // looping, and vice versa, will cause a TF_CODING_ERROR to be issued.
245 //
246 // When this has no value, this extrapolation loops the full knot region.
247 //
248 // When this has a value that is exactly a knot time,
249 // this extrapolation loops the knot subregion demarcated by
250 // loopBoundaryTime and the knot subregion's start for post-extrapolation
251 // or end for pre-extrapolation.
252 //
253 // There are a few degenerate cases.
254 // - This has a value that isn't exactly a knot time. The resulting
255 // extrapolation is value block.
256 // - This has a value that is the start knot time for pre-extrapolation,
257 // or end knot time for post-extrapolation. The resulting extrapolation
258 // is held, and has the same behavior as TsExtrapHeld.
259 std::optional<double> loopBoundaryTime;
260
261public:
262 TS_API
264
265 TS_API
266 TsExtrapolation(TsExtrapMode mode);
267
272 TS_API
273 TsExtrapolation(TsExtrapMode mode, double slope);
274
275 TS_API
276 bool operator==(const TsExtrapolation &other) const;
277
278 TS_API
279 bool operator!=(const TsExtrapolation &other) const;
280
282 TS_API
283 bool IsLooping() const;
284};
285
293template <typename Vertex>
295{
296public:
297 static_assert(TsSplineIsValidSampleType<Vertex>,
298 "The Vertex template parameter to TsSplineSamples must be one"
299 " of GfVec2d, GfVec2f, or GfVec2h.");
300
301 using Polyline = std::vector<Vertex>;
302
303 std::vector<Polyline> polylines;
304};
305
316template <typename Vertex>
318{
319public:
320 static_assert(TsSplineIsValidSampleType<Vertex>,
321 "The Vertex template parameter to TsSplineSamplesWithSources"
322 " must be one of GfVec2d, GfVec2f, or GfVec2h.");
323
324 using Polyline = std::vector<Vertex>;
325
326 std::vector<Polyline> polylines;
327 std::vector<TsSplineSampleSource> sources;
328};
329
335enum TsAntiRegressionMode
336{
339 TsAntiRegressionNone,
340
345 TsAntiRegressionContain,
346
351 TsAntiRegressionKeepRatio,
352
356 TsAntiRegressionKeepStart
357};
358
359
360PXR_NAMESPACE_CLOSE_SCOPE
361
362#endif
A basic mathematical interval class.
Definition interval.h:33
Extrapolation parameters for the ends of a spline beyond the knots.
Definition types.h:231
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:204
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:295
TsSplineSamplesWithSources<Vertex> is a TsSplineSamples<Vertex> that also includes source information...
Definition types.h:318