HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tsTest_SplineData.h
Go to the documentation of this file.
1 //
2 // Copyright 2023 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 
25 #ifndef PXR_BASE_TS_TS_TEST_SPLINE_DATA_H
26 #define PXR_BASE_TS_TS_TEST_SPLINE_DATA_H
27 
28 #include "pxr/pxr.h"
29 #include "pxr/base/ts/api.h"
30 
31 #include <string>
32 #include <set>
33 
35 
36 // A generic way of encoding spline control parameters. Allows us to pass the
37 // same data to different backends (Ts, mayapy, etc) for evaluation.
38 //
40 {
41 public:
42  // Interpolation method for a spline segment.
44  {
48  };
49 
50  // Extrapolation method for the ends of a spline beyond the knots.
52  {
57  };
58 
59  // Looping modes.
60  enum LoopMode
61  {
63  LoopContinue, // Used by inner loops. Copy whole knots.
64  LoopRepeat, // Used by extrap loops. Repeat with offset.
65  LoopReset, // Used by extrap loops. Repeat identically.
66  LoopOscillate // Used by extrap loops. Alternate forward / reverse.
67  };
68 
69  // Features that may be required by splines.
70  enum Feature
71  {
81  };
82  using Features = unsigned int;
83 
84  // One knot in a spline.
85  struct TS_API Knot
86  {
87  double time = 0;
88  InterpMethod nextSegInterpMethod = InterpHeld;
89  double value = 0;
90  bool isDualValued = false;
91  double preValue = 0;
92  double preSlope = 0;
93  double postSlope = 0;
94  double preLen = 0;
95  double postLen = 0;
96  bool preAuto = false;
97  bool postAuto = false;
98 
99  public:
100  Knot();
101  Knot(
102  const Knot &other);
103  Knot& operator=(
104  const Knot &other);
105  bool operator==(
106  const Knot &other) const;
107  bool operator!=(
108  const Knot &other) const;
109  bool operator<(
110  const Knot &other) const;
111  };
112  using KnotSet = std::set<Knot>;
113 
114  // Inner-loop parameters.
115  //
116  // The pre-looping interval is times [preLoopStart, protoStart).
117  // The prototype interval is times [protoStart, protoEnd).
118  // The post-looping interval is times [protoEnd, postLoopEnd],
119  // or, if closedEnd is false, the same interval, but open at the end.
120  // To decline pre-looping or post-looping, make that interval empty.
121  //
122  // The value offset specifies the difference between the value at the starts
123  // of consecutive iterations.
124  //
125  // It is common, but not required, to use a subset of functionality:
126  // - Knots at the start and end of the prototype interval
127  // - Whole numbers of loop iterations
128  // (sizes of looping intervals are multiples of size of proto interval)
129  // - Value offset initially set to original value difference
130  // between ends of prototype interval
131  // - closedEnd true
132  //
133  // A knot exactly at the end of the prototype interval is not part of the
134  // prototype. If there is post-looping, a knot at the end of the prototype
135  // interval is overwritten by a copy of the knot from the start of the
136  // prototype interval.
137  //
138  // Enabling inner looping can change the shape of the prototype interval
139  // (and thus all looped copies), because the first knot is echoed as the
140  // last. Inner looping does not aim to make copies of an existing shape; it
141  // aims to set up for continuity at loop joins.
142  //
143  // If closedEnd is true, and there is a whole number of post-iterations, and
144  // there is a knot at the prototype start time, then a final copy of the
145  // first prototype knot will be echoed at the end of the last
146  // post-iteration.
147  //
149  {
150  bool enabled = false;
151  double protoStart = 0;
152  double protoEnd = 0;
153  double preLoopStart = 0;
154  double postLoopEnd = 0;
155  bool closedEnd = true;
156  double valueOffset = 0;
157 
158  public:
159  InnerLoopParams();
161  const InnerLoopParams &other);
163  const InnerLoopParams &other);
164  bool operator==(
165  const InnerLoopParams &other) const;
166  bool operator!=(
167  const InnerLoopParams &other) const;
168 
169  bool IsValid() const;
170  };
171 
172  // Extrapolation parameters for the ends of a spline beyond the knots.
174  {
176  double slope = 0;
177  LoopMode loopMode = LoopNone;
178 
179  public:
180  Extrapolation();
181  Extrapolation(ExtrapMethod method);
183  const Extrapolation &other);
185  const Extrapolation &other);
186  bool operator==(
187  const Extrapolation &other) const;
188  bool operator!=(
189  const Extrapolation &other) const;
190  };
191 
192 public:
193  TS_API
195 
196  TS_API
198  const TsTest_SplineData &other);
199 
200  TS_API
202  operator=(
203  const TsTest_SplineData &other);
204 
205  TS_API
206  bool operator==(
207  const TsTest_SplineData &other) const;
208 
209  TS_API
210  bool operator!=(
211  const TsTest_SplineData &other) const;
212 
213  TS_API
214  void SetIsHermite(bool hermite);
215 
216  TS_API
217  void AddKnot(
218  const Knot &knot);
219 
220  TS_API
221  void SetKnots(
222  const KnotSet &knots);
223 
224  TS_API
225  void SetPreExtrapolation(
226  const Extrapolation &preExtrap);
227 
228  TS_API
230  const Extrapolation &postExtrap);
231 
232  TS_API
233  void SetInnerLoopParams(
234  const InnerLoopParams &params);
235 
236  TS_API
237  bool GetIsHermite() const;
238 
239  TS_API
240  const KnotSet&
241  GetKnots() const;
242 
243  TS_API
244  const Extrapolation&
245  GetPreExtrapolation() const;
246 
247  TS_API
248  const Extrapolation&
249  GetPostExtrapolation() const;
250 
251  TS_API
252  const InnerLoopParams&
253  GetInnerLoopParams() const;
254 
255  TS_API
257 
258  TS_API
260 
261 private:
262  bool _isHermite = false;
263  KnotSet _knots;
264  Extrapolation _preExtrap;
265  Extrapolation _postExtrap;
266  InnerLoopParams _innerLoopParams;
267 };
268 
270 
271 #endif
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
TS_API const Extrapolation & GetPreExtrapolation() const
GT_API const UT_StringHolder time
TS_API std::string GetDebugDescription() const
TS_API void SetIsHermite(bool hermite)
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
TS_API TsTest_SplineData()
std::set< Knot > KnotSet
TS_API void SetKnots(const KnotSet &knots)
TS_API const Extrapolation & GetPostExtrapolation() const
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition: glcorearb.h:2539
GLenum const GLfloat * params
Definition: glcorearb.h:105
TS_API Features GetRequiredFeatures() const
TS_API TsTest_SplineData & operator=(const TsTest_SplineData &other)
TS_API void SetPreExtrapolation(const Extrapolation &preExtrap)
TS_API void AddKnot(const Knot &knot)
unsigned int Features
bool operator<(const GU_TetrahedronFacet &a, const GU_TetrahedronFacet &b)
TS_API const KnotSet & GetKnots() const
TS_API bool operator==(const TsTest_SplineData &other) const
#define TS_API
Definition: api.h:41
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
TS_API bool GetIsHermite() const
TS_API void SetPostExtrapolation(const Extrapolation &postExtrap)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
TS_API const InnerLoopParams & GetInnerLoopParams() const
Definition: core.h:1131
TS_API bool operator!=(const TsTest_SplineData &other) const
TS_API void SetInnerLoopParams(const InnerLoopParams &params)