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 <vector>
20
21PXR_NAMESPACE_OPEN_SCOPE
22
29#define TS_SPLINE_SUPPORTED_VALUE_TYPES \
30 ((Double, double)) \
31 ((Float, float)) \
32 ((Half, GfHalf))
33
34#define TS_SPLINE_SAMPLE_VERTEX_TYPES \
35 ((Vec2d, GfVec2d)) \
36 ((Vec2f, GfVec2f)) \
37 ((Vec2h, GfVec2h))
38
39#define TS_SPLINE_VALUE_TYPE_NAME(x) TF_PP_TUPLE_ELEM(0, x)
40#define TS_SPLINE_VALUE_CPP_TYPE(x) TF_PP_TUPLE_ELEM(1, x)
41
43template <class T>
44inline constexpr bool
45TsSplineIsValidDataType = false;
46
47#define _TS_SUPPORT_DATA_TYPE(unused, tuple) \
48 template <> \
49 inline constexpr bool \
50 TsSplineIsValidDataType< TS_SPLINE_VALUE_CPP_TYPE(tuple) > = true;
51TF_PP_SEQ_FOR_EACH(_TS_SUPPORT_DATA_TYPE,
52 ~,
53 TS_SPLINE_SUPPORTED_VALUE_TYPES)
54#undef _TS_SUPPORT_DATA_TYPE
55
58template <class T>
59inline constexpr bool
60TsSplineIsValidSampleType = false;
61
62#define _TS_SUPPORT_SAMPLE_TYPE(unused, tuple) \
63 template <> \
64 inline constexpr bool \
65 TsSplineIsValidSampleType< TS_SPLINE_VALUE_CPP_TYPE(tuple) > = true;
66TF_PP_SEQ_FOR_EACH(_TS_SUPPORT_SAMPLE_TYPE,
67 ~,
68 TS_SPLINE_SAMPLE_VERTEX_TYPES)
69#undef _TS_SUPPORT_SAMPLE_TYPE
70
71// Times are encoded as double.
72using TsTime = double;
73
75// ** NOTE TO MAINTAINERS **
76//
77// The following enum values are used in the binary crate format.
78// Do not change them; only add.
79
82enum TsInterpMode
83{
84 TsInterpValueBlock = 0, //< No value in this segment.
85 TsInterpHeld = 1, //< Constant value in this segment.
86 TsInterpLinear = 2, //< Linear interpolation.
87 TsInterpCurve = 3 //< Bezier or Hermite, depends on curve type.
88};
89
92enum TsCurveType
93{
94 TsCurveTypeBezier = 0, //< Bezier curve, free tangent widths.
95 TsCurveTypeHermite = 1 //< Hermite curve, like Bezier but fixed tan width.
96};
97
101enum TsExtrapMode
102{
103 TsExtrapValueBlock = 0, //< No value in this region.
104 TsExtrapHeld = 1, //< Constant value in this region.
105 TsExtrapLinear = 2, //< Linear interpolation based on edge knots.
106 TsExtrapSloped = 3, //< Linear interpolation with specified slope.
107 TsExtrapLoopRepeat = 4, //< Knot curve repeated, offset so ends meet.
108 TsExtrapLoopReset = 5, //< Curve repeated exactly, discontinuous joins.
109 TsExtrapLoopOscillate = 6 //< Like Reset, but every other copy reversed.
110};
111
118enum TsSplineSampleSource
119{
120 TsSourcePreExtrap, //< Extrapolation before the first knot
121 TsSourcePreExtrapLoop, //< Looped extrapolation before the first knot
122 TsSourceInnerLoopPreEcho, //< Echoed copy of an inner loop prototype
123 TsSourceInnerLoopProto, //< This is the inner loop prototype
124 TsSourceInnerLoopPostEcho, //< Echoed copy of an inner loop prototype
125 TsSourceKnotInterp, //< "Normal" knot interpolation
126 TsSourcePostExtrap, //< Extrapolation after the last knot
127 TsSourcePostExtrapLoop, //< Looped extrapolation after the last knot
128};
129
153enum TsTangentAlgorithm
154{
155 TsTangentAlgorithmNone,
156 TsTangentAlgorithmCustom,
157 TsTangentAlgorithmAutoEase
158};
159
193{
194public:
195 TsTime protoStart = 0.0;
196 TsTime protoEnd = 0.0;
197 int32_t numPreLoops = 0;
198 int32_t numPostLoops = 0;
199 double valueOffset = 0.0;
200
201public:
202 TS_API
203 bool operator==(const TsLoopParams &other) const;
204
205 TS_API
206 bool operator!=(const TsLoopParams &other) const;
207
209 TS_API
211
213 TS_API
215};
216
220{
221public:
222 TsExtrapMode mode = TsExtrapHeld;
223 double slope = 0.0;
224
225public:
226 TS_API
228
229 TS_API
230 TsExtrapolation(TsExtrapMode mode);
231
232 TS_API
233 bool operator==(const TsExtrapolation &other) const;
234
235 TS_API
236 bool operator!=(const TsExtrapolation &other) const;
237
239 TS_API
240 bool IsLooping() const;
241};
242
250template <typename Vertex>
252{
253public:
254 static_assert(TsSplineIsValidSampleType<Vertex>,
255 "The Vertex template parameter to TsSplineSamples must be one"
256 " of GfVec2d, GfVec2f, or GfVec2h.");
257
258 using Polyline = std::vector<Vertex>;
259
260 std::vector<Polyline> polylines;
261};
262
273template <typename Vertex>
275{
276public:
277 static_assert(TsSplineIsValidSampleType<Vertex>,
278 "The Vertex template parameter to TsSplineSamplesWithSources"
279 " must be one of GfVec2d, GfVec2f, or GfVec2h.");
280
281 using Polyline = std::vector<Vertex>;
282
283 std::vector<Polyline> polylines;
284 std::vector<TsSplineSampleSource> sources;
285};
286
287// Declare sampling classes as extern templates. They are explicitly
288// instantiated in types.cpp
289#define TS_SAMPLE_EXTERN_IMPL(unused, tuple) \
290 TS_API_TEMPLATE_CLASS( \
291 TsSplineSamples< TS_SPLINE_VALUE_CPP_TYPE(tuple) >); \
292 TS_API_TEMPLATE_CLASS( \
293 TsSplineSamplesWithSources< TS_SPLINE_VALUE_CPP_TYPE(tuple) >);
294TF_PP_SEQ_FOR_EACH(TS_SAMPLE_EXTERN_IMPL, ~, TS_SPLINE_SAMPLE_VERTEX_TYPES)
295#undef TS_SAMPLE_EXTERN_IMPL
296
302enum TsAntiRegressionMode
303{
306 TsAntiRegressionNone,
307
312 TsAntiRegressionContain,
313
318 TsAntiRegressionKeepRatio,
319
323 TsAntiRegressionKeepStart
324};
325
326
327PXR_NAMESPACE_CLOSE_SCOPE
328
329#endif
A basic mathematical interval class.
Definition: interval.h:33
Extrapolation parameters for the ends of a spline beyond the knots.
Definition: types.h:220
TS_API bool IsLooping() const
Returns whether our mode is one of the looping extrapolation modes.
Inner-loop parameters.
Definition: types.h:193
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:252
TsSplineSamplesWithSources<Vertex> is a TsSplineSamples<Vertex> that also includes source information...
Definition: types.h:275