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
163{
164public:
165 TsTime protoStart = 0.0;
166 TsTime protoEnd = 0.0;
167 int32_t numPreLoops = 0;
168 int32_t numPostLoops = 0;
169 double valueOffset = 0.0;
170
171public:
172 TS_API
173 bool operator==(const TsLoopParams &other) const;
174
175 TS_API
176 bool operator!=(const TsLoopParams &other) const;
177
179 TS_API
181
183 TS_API
185};
186
190{
191public:
192 TsExtrapMode mode = TsExtrapHeld;
193 double slope = 0.0;
194
195public:
196 TS_API
198
199 TS_API
200 TsExtrapolation(TsExtrapMode mode);
201
202 TS_API
203 bool operator==(const TsExtrapolation &other) const;
204
205 TS_API
206 bool operator!=(const TsExtrapolation &other) const;
207
209 TS_API
210 bool IsLooping() const;
211};
212
220template <typename Vertex>
222{
223public:
224 static_assert(TsSplineIsValidSampleType<Vertex>,
225 "The Vertex template parameter to TsSplineSamples must be one"
226 " of GfVec2d, GfVec2f, or GfVec2h.");
227
228 using Polyline = std::vector<Vertex>;
229
230 std::vector<Polyline> polylines;
231};
232
243template <typename Vertex>
245{
246public:
247 static_assert(TsSplineIsValidSampleType<Vertex>,
248 "The Vertex template parameter to TsSplineSamplesWithSources"
249 " must be one of GfVec2d, GfVec2f, or GfVec2h.");
250
251 using Polyline = std::vector<Vertex>;
252
253 std::vector<Polyline> polylines;
254 std::vector<TsSplineSampleSource> sources;
255};
256
257// Declare sampling classes as extern templates. They are explicitly
258// instantiated in types.cpp
259#define TS_SAMPLE_EXTERN_IMPL(unused, tuple) \
260 TS_API_TEMPLATE_CLASS( \
261 TsSplineSamples< TS_SPLINE_VALUE_CPP_TYPE(tuple) >); \
262 TS_API_TEMPLATE_CLASS( \
263 TsSplineSamplesWithSources< TS_SPLINE_VALUE_CPP_TYPE(tuple) >);
264TF_PP_SEQ_FOR_EACH(TS_SAMPLE_EXTERN_IMPL, ~, TS_SPLINE_SAMPLE_VERTEX_TYPES)
265#undef TS_SAMPLE_EXTERN_IMPL
266
272enum TsAntiRegressionMode
273{
276 TsAntiRegressionNone,
277
282 TsAntiRegressionContain,
283
288 TsAntiRegressionKeepRatio,
289
293 TsAntiRegressionKeepStart
294};
295
296
297PXR_NAMESPACE_CLOSE_SCOPE
298
299#endif
A basic mathematical interval class.
Definition: interval.h:33
Extrapolation parameters for the ends of a spline beyond the knots.
Definition: types.h:190
TS_API bool IsLooping() const
Returns whether our mode is one of the looping extrapolation modes.
Inner-loop parameters.
Definition: types.h:163
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:222
TsSplineSamplesWithSources<Vertex> is a TsSplineSamples<Vertex> that also includes source information...
Definition: types.h:245