Loading...
Searching...
No Matches
tsTest_SampleTimes.h
1//
2// Copyright 2023 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 struct TS_API SampleTime
27 {
28 double time = 0.0;
29 bool pre = false;
30
31 public:
32 SampleTime();
33 SampleTime(double time);
34 SampleTime(double time, bool pre);
35 SampleTime(const SampleTime &other);
36 SampleTime& operator=(const SampleTime &other);
37 SampleTime& operator=(double time);
38 bool operator<(const SampleTime &other) const;
39 bool operator==(const SampleTime &other) const;
40 bool operator!=(const SampleTime &other) const;
41 };
42
43 using SampleTimeSet = std::set<SampleTime>;
44
45public:
46 // DIRECT SPECIFICATION
47
48 // Constructs a SampleTimes object for direct specification of times.
49 TS_API
50 TsTest_SampleTimes();
51
52 // Adds the specified times.
53 TS_API
54 void AddTimes(
55 const std::vector<double> &times);
56
57 // Adds the specified times.
58 TS_API
59 void AddTimes(
60 const std::vector<SampleTime> &times);
61
62 // SPLINE-DRIVEN
63
64 // Constructs a SampleTimes object for specification of times based on the
65 // contents of splineData.
66 TS_API
67 TsTest_SampleTimes(
68 const TsTest_SplineData &splineData);
69
70 // Adds a time for each knot in splineData. For dual-valued knots, adds
71 // both a pre-time and an ordinary time.
72 TS_API
73 void AddKnotTimes();
74
75 // Adds evenly spaced sample times within the frame range of splineData.
76 // The first sample is after the first knot, and the last sample is before
77 // the last knot.
78 TS_API
79 void AddUniformInterpolationTimes(
80 int numSamples);
81
82 // Determines the time range of the knots in splineData, extends it by
83 // extrapolationFactor on each end, and adds one pre-extrapolating and one
84 // post-extrapolating sample. For example, with a time range of 10, and an
85 // extrapolationFactor of 0.25, samples will be added 2.5 time units before
86 // the first knot and 2.5 time units after the last.
87 TS_API
88 void AddExtrapolationTimes(
89 double extrapolationFactor);
90
91 // MACRO
92
93 // Calls AddKnotTimes(), AddUniformInterpolationTimes(200), and
94 // AddExtrapolationTimes(0.2).
95 TS_API
96 void AddStandardTimes();
97
98 // ACCESSORS
99
100 // Returns the set of sample times.
101 TS_API
102 const SampleTimeSet&
103 GetTimes() const;
104
105private:
106 SampleTimeSet _GetKnotTimes() const;
107
108private:
109 const bool _haveSplineData;
110 const TsTest_SplineData _splineData;
111
112 SampleTimeSet _times;
113};
114
115PXR_NAMESPACE_CLOSE_SCOPE
116
117#endif