Loading...
Searching...
No Matches
timeInterval.h
Go to the documentation of this file.
1//
2// Copyright 2025 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_EXEC_EF_TIME_INTERVAL_H
8#define PXR_EXEC_EF_TIME_INTERVAL_H
9
11
12#include "pxr/pxr.h"
13
14#include "pxr/exec/ef/api.h"
15#include "pxr/exec/ef/time.h"
16
19
20#include <initializer_list>
21#include <iosfwd>
22#include <string>
23#include <vector>
24
25PXR_NAMESPACE_OPEN_SCOPE
26
36{
37public:
38
39 explicit EfTimeInterval(
40 const GfMultiInterval &timeMultiInterval = GfMultiInterval(),
41 bool defaultTime = false) :
42 _timeMultiInterval(timeMultiInterval),
43 _defaultTime(defaultTime)
44 {}
45
46 explicit EfTimeInterval(
47 const GfInterval &timeInterval,
48 bool defaultTime = false) :
49 _timeMultiInterval(timeInterval),
50 _defaultTime(defaultTime)
51 {}
52
56 const std::vector<double> &times,
57 bool defaultTime = false) :
58 _defaultTime(defaultTime)
59 {
60 for(double t : times)
61 _timeMultiInterval.Add(GfInterval(t));
62 }
63
67 const std::initializer_list<double> &times,
68 bool defaultTime = false) :
69 _defaultTime(defaultTime)
70 {
71 for(double t : times)
72 _timeMultiInterval.Add(GfInterval(t));
73 }
74
77 void Clear() {
78 _timeMultiInterval.Clear();
79 _defaultTime = false;
80 }
81
84 bool IsEmpty() const {
85 return !_defaultTime && _timeMultiInterval.IsEmpty();
86 }
87
92 return _timeMultiInterval;
93 }
94
97 bool IsDefaultTimeSet() const {
98 return _defaultTime;
99 }
100
110 bool Contains(const EfTime &time) const {
111 return time.GetTimeCode().IsDefault()
112 ? _defaultTime
113 : _ContainsTime(time);
114 }
115
122 bool Contains(const EfTimeInterval &rhs) const {
123 if (!_defaultTime && rhs.IsDefaultTimeSet()) {
124 return false;
125 }
126 return _timeMultiInterval.Contains(rhs.GetTimeMultiInterval());
127 }
128
134 bool IsFullInterval() const {
135 return _defaultTime &&
136 _timeMultiInterval == GfMultiInterval::GetFullInterval();
137 }
138
143 }
144
145 bool operator==(const EfTimeInterval &rhs) const {
146 return _timeMultiInterval == rhs._timeMultiInterval &&
147 _defaultTime == rhs._defaultTime;
148 }
149
150 bool operator!=(const EfTimeInterval &rhs) const {
151 return !(*this == rhs);
152 }
153
156 void operator|=(const EfTimeInterval &rhs) {
157 _timeMultiInterval.Add(rhs._timeMultiInterval);
158 _defaultTime |= rhs._defaultTime;
159 }
160
163 void operator|=(const GfInterval &interval) {
164 _timeMultiInterval.Add(interval);
165 }
166
169 void operator|=(const EfTime &time) {
170 const UsdTimeCode timeCode = time.GetTimeCode();
171 if (timeCode.IsDefault()) {
172 _defaultTime = true;
173 } else {
174 _timeMultiInterval.Add(GfInterval(timeCode.GetValue()));
175 }
176 }
177
180 void operator&=(const EfTimeInterval &rhs) {
181 _timeMultiInterval.Intersect(rhs._timeMultiInterval);
182 _defaultTime &= rhs._defaultTime;
183 }
184
186 bool operator<(const EfTimeInterval &rhs) const {
187 if (_timeMultiInterval < rhs._timeMultiInterval) return true;
188 if (_timeMultiInterval != rhs._timeMultiInterval) return false;
189 if (_defaultTime != rhs._defaultTime) return _defaultTime;
190
191 // Equal
192 return false;
193 }
194
202 EfTimeInterval &Extend(double leftFrames, double rightFrames) {
203 const GfInterval extension( -leftFrames, +rightFrames, true, true);
204 _timeMultiInterval.ArithmeticAdd(extension);
205 return *this;
206 }
207
209 EF_API
210 std::string GetAsString() const;
211
212private:
213
214 // Returns true if this time is contained in _timeMultiInterval. If frame
215 // is "default" this returns false.
216 EF_API
217 bool _ContainsTime(const EfTime &time) const;
218
219 // The time multi interval.
220 GfMultiInterval _timeMultiInterval;
221
222 // Whether or not the default time is set.
223 bool _defaultTime;
224};
225
228EF_API
229std::ostream &operator<<(std::ostream &os, const EfTimeInterval &timeInterval);
230
231PXR_NAMESPACE_CLOSE_SCOPE
232
233#endif
A class that represents a point in time for execution.
Definition: time.h:37
const UsdTimeCode GetTimeCode() const
Returns the time code.
Definition: time.h:66
A class that represents an interval in EfTime.
Definition: timeInterval.h:36
static EfTimeInterval GetFullInterval()
Returns the full time interval: (-inf, inf) with the default time.
Definition: timeInterval.h:141
void operator|=(const GfInterval &interval)
Unions this time interval and the GfInterval interval.
Definition: timeInterval.h:163
bool Contains(const EfTime &time) const
Returns true if this time interval contains time, with special treatment for the default time and for...
Definition: timeInterval.h:110
EfTimeInterval & Extend(double leftFrames, double rightFrames)
Extends the interval by the specified number of frames in each direction.
Definition: timeInterval.h:202
bool Contains(const EfTimeInterval &rhs) const
Returns true if this time interval fully contains the time interval rhs.
Definition: timeInterval.h:122
bool IsFullInterval() const
Returns true if the time interval is the full interval.
Definition: timeInterval.h:134
EfTimeInterval(const std::vector< double > &times, bool defaultTime=false)
For convenience, constructs a multiInterval from the discrete times.
Definition: timeInterval.h:55
bool IsEmpty() const
Returns true if the interval is empty.
Definition: timeInterval.h:84
void Clear()
Clears the time interval to an empty interval.
Definition: timeInterval.h:77
bool operator<(const EfTimeInterval &rhs) const
Less-than operator.
Definition: timeInterval.h:186
void operator|=(const EfTime &time)
Unions this time interval and the EfTime time.
Definition: timeInterval.h:169
EfTimeInterval(const std::initializer_list< double > &times, bool defaultTime=false)
For convenience, constructs a multiInterval from the discrete times.
Definition: timeInterval.h:66
void operator&=(const EfTimeInterval &rhs)
Computes the intersection of this and the EfTimeInterval rhs.
Definition: timeInterval.h:180
EF_API std::string GetAsString() const
Get time interval as string, for debugging.
void operator|=(const EfTimeInterval &rhs)
Unions this time interval and the EfTimeInterval rhs.
Definition: timeInterval.h:156
const GfMultiInterval & GetTimeMultiInterval() const
Returns the multi interval that represents intervals on the frame timeline.
Definition: timeInterval.h:91
bool IsDefaultTimeSet() const
Returns true if the interval contains the default time.
Definition: timeInterval.h:97
A basic mathematical interval class.
Definition: interval.h:33
GfMultiInterval represents a subset of the real number line as an ordered set of non-intersecting GfI...
Definition: multiInterval.h:30
GF_API void Add(const GfInterval &i)
Add the given interval to the multi-interval.
GF_API void Clear()
Clear the multi-interval.
Definition: multiInterval.h:91
GF_API bool Contains(double d) const
Returns true if the multi-interval contains the given value.
GF_API void ArithmeticAdd(const GfInterval &i)
Uses the given interval to extend the multi-interval in the interval arithmetic sense.
GF_API bool IsEmpty() const
Returns true if the multi-interval is empty.
Definition: multiInterval.h:66
static GfMultiInterval GetFullInterval()
Returns the full interval (-inf, inf).
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:72
double GetValue() const
Return the numeric value for this time.
Definition: timeCode.h:157
bool IsDefault() const
Return true if this time represents the 'default' sentinel value, false otherwise.
Definition: timeCode.h:145
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].