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
15#include "pxr/base/gf/vec2d.h"
16#include "pxr/base/tf/preprocessorUtilsLite.h"
17
18#include <cstdint>
19#include <optional>
20#include <vector>
21
22PXR_NAMESPACE_OPEN_SCOPE
23
30#define TS_SPLINE_SUPPORTED_VALUE_TYPES \
31 ((Double, double)) \
32 ((Float, float)) \
33 ((Half, GfHalf))
34
35#define TS_SPLINE_SAMPLE_VERTEX_TYPES \
36 ((Vec2d, GfVec2d)) \
37 ((Vec2f, GfVec2f)) \
38 ((Vec2h, GfVec2h))
39
40#define TS_SPLINE_VALUE_TYPE_NAME(x) TF_PP_TUPLE_ELEM(0, x)
41#define TS_SPLINE_VALUE_CPP_TYPE(x) TF_PP_TUPLE_ELEM(1, x)
42
44template <class T>
45inline constexpr bool
46TsSplineIsValidDataType = false;
47
48#define _TS_SUPPORT_DATA_TYPE(unused, tuple) \
49 template <> \
50 inline constexpr bool \
51 TsSplineIsValidDataType< TS_SPLINE_VALUE_CPP_TYPE(tuple) > = true;
52TF_PP_SEQ_FOR_EACH(_TS_SUPPORT_DATA_TYPE,
53 ~,
54 TS_SPLINE_SUPPORTED_VALUE_TYPES)
55#undef _TS_SUPPORT_DATA_TYPE
56
59template <class T>
60inline constexpr bool
61TsSplineIsValidSampleType = false;
62
63#define _TS_SUPPORT_SAMPLE_TYPE(unused, tuple) \
64 template <> \
65 inline constexpr bool \
66 TsSplineIsValidSampleType< TS_SPLINE_VALUE_CPP_TYPE(tuple) > = true;
67TF_PP_SEQ_FOR_EACH(_TS_SUPPORT_SAMPLE_TYPE,
68 ~,
69 TS_SPLINE_SAMPLE_VERTEX_TYPES)
70#undef _TS_SUPPORT_SAMPLE_TYPE
71
72// Times are encoded as double.
73using TsTime = double;
74
76// ** NOTE TO MAINTAINERS **
77//
78// The following enum values are used in the binary crate format.
79// Do not change them; only add.
80
83enum TsInterpMode
84{
85 TsInterpValueBlock = 0, //< No value in this segment.
86 TsInterpHeld = 1, //< Constant value in this segment.
87 TsInterpLinear = 2, //< Linear interpolation.
88 TsInterpCurve = 3 //< Bezier or Hermite, depends on curve type.
89};
90
93enum TsCurveType
94{
95 TsCurveTypeBezier = 0, //< Bezier curve, free tangent widths.
96 TsCurveTypeHermite = 1 //< Hermite curve, like Bezier but fixed tan width.
97};
98
104enum TsExtrapMode
105{
106 TsExtrapValueBlock = 0, //< No value in this region.
107 TsExtrapHeld = 1, //< Constant value in this region.
108 TsExtrapLinear = 2, //< Linear interpolation based on edge knots.
109 TsExtrapSloped = 3, //< Linear interpolation with specified slope.
110 TsExtrapLoopRepeat = 4, //< Knot curve repeated, offset so ends meet.
111 TsExtrapLoopReset = 5, //< Curve repeated exactly, discontinuous joins.
112 TsExtrapLoopOscillate = 6 //< Like Reset, but every other copy reversed.
113};
114
121enum TsSplineSampleSource
122{
123 TsSourcePreExtrap, //< Extrapolation before the first knot
124 TsSourcePreExtrapLoop, //< Looped extrapolation before the first knot
125 TsSourceInnerLoopPreEcho, //< Echoed copy of an inner loop prototype
126 TsSourceInnerLoopProto, //< This is the inner loop prototype
127 TsSourceInnerLoopPostEcho, //< Echoed copy of an inner loop prototype
128 TsSourceKnotInterp, //< "Normal" knot interpolation
129 TsSourcePostExtrap, //< Extrapolation after the last knot
130 TsSourcePostExtrapLoop, //< Looped extrapolation after the last knot
131};
132
156enum TsTangentAlgorithm
157{
158 TsTangentAlgorithmNone,
159 TsTangentAlgorithmCustom,
160 TsTangentAlgorithmAutoEase
161};
162
196{
197public:
198 TsTime protoStart = 0.0;
199 TsTime protoEnd = 0.0;
200 int32_t numPreLoops = 0;
201 int32_t numPostLoops = 0;
202 double valueOffset = 0.0;
203
204public:
205 TS_API
206 bool operator==(const TsLoopParams &other) const;
207
208 TS_API
209 bool operator!=(const TsLoopParams &other) const;
210
212 TS_API
214
216 TS_API
218};
219
223{
224public:
225 TsExtrapMode mode = TsExtrapHeld;
226
227 // Used only in TsExtrapSloped mode. Specifies slope of the extrapolated
228 // segment.
229 double slope = 0.0;
230
231 // Used only in looping extrapolation modes to optionally specify a
232 // subsection of the spline.
233 //
234 // This setting is incompatible with inner looping. Attempts to set
235 // extrapolation with a non-null loopBoundaryTime on a spline with inner
236 // looping, and vice versa, will cause a TF_CODING_ERROR to be issued.
237 //
238 // When this has no value, this extrapolation loops the full knot region.
239 //
240 // When this has a value that is exactly a knot time,
241 // this extrapolation loops the knot subregion demarcated by
242 // loopBoundaryTime and the knot subregion's start for post-extrapolation
243 // or end for pre-extrapolation.
244 //
245 // There are a few degenerate cases.
246 // - This has a value that isn't exactly a knot time. The resulting
247 // extrapolation is value block.
248 // - This has a value that is the start knot time for pre-extrapolation,
249 // or end knot time for post-extrapolation. The resulting extrapolation
250 // is held, and has the same behavior as TsExtrapHeld.
251 std::optional<double> loopBoundaryTime;
252
253public:
254 TS_API
256
257 TS_API
258 TsExtrapolation(TsExtrapMode mode);
259
264 TS_API
265 TsExtrapolation(TsExtrapMode mode, double slope);
266
267 TS_API
268 bool operator==(const TsExtrapolation &other) const;
269
270 TS_API
271 bool operator!=(const TsExtrapolation &other) const;
272
274 TS_API
275 bool IsLooping() const;
276};
277
285template <typename Vertex>
287{
288public:
289 static_assert(TsSplineIsValidSampleType<Vertex>,
290 "The Vertex template parameter to TsSplineSamples must be one"
291 " of GfVec2d, GfVec2f, or GfVec2h.");
292
293 using Polyline = std::vector<Vertex>;
294
295 std::vector<Polyline> polylines;
296};
297
308template <typename Vertex>
310{
311public:
312 static_assert(TsSplineIsValidSampleType<Vertex>,
313 "The Vertex template parameter to TsSplineSamplesWithSources"
314 " must be one of GfVec2d, GfVec2f, or GfVec2h.");
315
316 using Polyline = std::vector<Vertex>;
317
318 std::vector<Polyline> polylines;
319 std::vector<TsSplineSampleSource> sources;
320};
321
327enum TsAntiRegressionMode
328{
331 TsAntiRegressionNone,
332
337 TsAntiRegressionContain,
338
343 TsAntiRegressionKeepRatio,
344
348 TsAntiRegressionKeepStart
349};
350
351
352PXR_NAMESPACE_CLOSE_SCOPE
353
354#endif
A basic mathematical interval class.
Definition interval.h:33
Extrapolation parameters for the ends of a spline beyond the knots.
Definition types.h:223
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:196
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:287
TsSplineSamplesWithSources<Vertex> is a TsSplineSamples<Vertex> that also includes source information...
Definition types.h:310