Loading...
Searching...
No Matches
tsTest_SampleTimes.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_TS_TEST_SAMPLE_TIMES_H
9#define PXR_BASE_TS_TS_TEST_SAMPLE_TIMES_H
10
11#include "pxr/pxr.h"
12#include "pxr/base/ts/api.h"
13#include "pxr/base/ts/tsTest_SplineData.h"
14
15#include <vector>
16#include <set>
17
18PXR_NAMESPACE_OPEN_SCOPE
19
20class TsTest_SampleTimes
21{
22public:
23 // A time at which to perform evaluation. Typically just a time, but can
24 // also be a "pre" time, which at a dual-valued knot can differ from the
25 // ordinary value.
26 class SampleTime
27 {
28 public:
29 double time = 0.0;
30 bool pre = false;
31
32 public:
33 TS_API
34 SampleTime();
35
36 TS_API
37 SampleTime(double time);
38
39 TS_API
40 SampleTime(double time, bool pre);
41
42 TS_API
43 SampleTime& operator=(double time);
44
45 TS_API
46 bool operator<(const SampleTime &other) const;
47
48 TS_API
49 bool operator==(const SampleTime &other) const;
50
51 TS_API
52 bool operator!=(const SampleTime &other) const;
53 };
54
55 using SampleTimeSet = std::set<SampleTime>;
56
57public:
58 // DIRECT SPECIFICATION
59
60 // Constructs a SampleTimes object for direct specification of times.
61 TS_API
62 TsTest_SampleTimes();
63
64 // Adds the specified times.
65 TS_API
66 void AddTimes(
67 const std::vector<double> &times);
68
69 // Adds the specified times.
70 TS_API
71 void AddTimes(
72 const std::vector<SampleTime> &times);
73
74 // SPLINE-DRIVEN
75
76 // Constructs a SampleTimes object for specification of times based on the
77 // contents of splineData.
78 TS_API
79 TsTest_SampleTimes(
80 const TsTest_SplineData &splineData);
81
82 // Adds a time for each knot in splineData. For dual-valued knots, adds
83 // both a pre-time and an ordinary time.
84 TS_API
85 void AddKnotTimes();
86
87 // Adds evenly spaced sample times within the frame range of splineData.
88 // The first sample is after the first knot, and the last sample is before
89 // the last knot.
90 TS_API
91 void AddUniformInterpolationTimes(
92 int numSamples);
93
94 // Determines the time range of the knots in splineData, extends it by
95 // extrapolationFactor on each end, and adds one pre-extrapolating and one
96 // post-extrapolating sample. For example, with a time range of 10, and an
97 // extrapolationFactor of 0.25, samples will be added 2.5 time units before
98 // the first knot and 2.5 time units after the last. For looping
99 // extrapolation regions, this method does nothing; call
100 // AddExtrapolatingLoopTimes instead or in addition.
101 TS_API
102 void AddExtrapolationTimes(
103 double extrapolationFactor);
104
105 // Adds times to handle extrapolating loops, if there are any.
106 TS_API
107 void AddExtrapolatingLoopTimes(
108 int numIterations,
109 int numSamplesPerIteration);
110
111 // MACRO
112
113 // Calls AddKnotTimes(), AddUniformInterpolationTimes(200),
114 // AddExtrapolationTimes(0.2), and AddExtrapolatingLoopTimes(3, 200).
115 TS_API
116 void AddStandardTimes();
117
118 // ACCESSORS
119
120 // Returns the set of sample times.
121 TS_API
122 const SampleTimeSet&
123 GetTimes() const;
124
125 // Return the min time
126 TS_API
127 double
128 GetMinTime() const;
129
130 // Return the max time
131 TS_API
132 double
133 GetMaxTime() const;
134
135private:
136 SampleTimeSet _GetKnotTimes() const;
137
138private:
139 const bool _haveSplineData;
140 const TsTest_SplineData _splineData;
141
142 SampleTimeSet _times;
143};
144
145PXR_NAMESPACE_CLOSE_SCOPE
146
147#endif