This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
multiInterval.h
Go to the documentation of this file.
1//
2// Copyright 2016 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_BASE_GF_MULTI_INTERVAL_H
8#define PXR_BASE_GF_MULTI_INTERVAL_H
9
12
13#include "pxr/pxr.h"
15#include "pxr/base/gf/api.h"
16
17#include <iosfwd>
18#include <set>
19#include <vector>
20
21PXR_NAMESPACE_OPEN_SCOPE
22
30{
31public:
32 typedef std::set<GfInterval> Set;
33 typedef Set::const_iterator const_iterator;
34 typedef Set::const_iterator iterator;
35
39 GfMultiInterval() = default;
41 GF_API explicit GfMultiInterval(const GfInterval &i);
43 GF_API explicit GfMultiInterval(const std::vector<GfInterval> &intervals);
45
46 GF_API bool operator==(const GfMultiInterval &that) const { return _set == that._set; }
47 GF_API bool operator!=(const GfMultiInterval &that) const { return !(*this == that); }
48 GF_API bool operator<(const GfMultiInterval &that) const { return _set < that._set; }
49 GF_API bool operator>=(const GfMultiInterval &that) const { return !(*this < that); }
50 GF_API bool operator>(const GfMultiInterval &that) const { return (that < *this); }
51 GF_API bool operator<=(const GfMultiInterval &that) const { return !(that < *this); }
52
53
56 GF_API size_t Hash() const;
57
58 friend inline size_t hash_value(const GfMultiInterval &mi) {
59 return mi.Hash();
60 }
61
64
66 GF_API bool IsEmpty() const { return _set.empty(); }
67
69 GF_API size_t GetSize() const { return _set.size(); }
70
73 GF_API GfInterval GetBounds() const;
74
76 GF_API bool Contains(double d) const;
77
79 GF_API bool Contains(const GfInterval & i) const;
80
83 GF_API bool Contains(const GfMultiInterval & s) const;
84
86
89
91 GF_API void Clear() { _set.clear(); }
92
94 GF_API void Add( const GfInterval & i );
97 GF_API void Add( const GfMultiInterval &s );
98
101 GF_API void ArithmeticAdd( const GfInterval &i );
102
104 GF_API void Remove( const GfInterval & i );
106 GF_API void Remove( const GfMultiInterval &s );
107
108 GF_API void Intersect( const GfInterval & i );
109 GF_API void Intersect( const GfMultiInterval &s );
110
113
115
120
121 GF_API const_iterator begin() const { return _set.begin(); }
122 GF_API const_iterator end() const { return _set.end(); }
123
126 GF_API const_iterator lower_bound( double x ) const;
127
130 GF_API const_iterator upper_bound( double x ) const;
131
134 GF_API const_iterator GetNextNonContainingInterval( double x ) const;
135
138 GF_API const_iterator GetPriorNonContainingInterval( double x ) const;
139
142 GF_API const_iterator GetContainingInterval( double x ) const;
143
145
149 }
150
152 void swap(GfMultiInterval &other) { _set.swap(other._set); }
153
154private:
155 void _AssertInvariants() const;
156
157 Set _set;
158};
159
162GF_API std::ostream & operator<<(std::ostream &out, const GfMultiInterval &s);
163
164PXR_NAMESPACE_CLOSE_SCOPE
165
166#endif // PXR_BASE_GF_MULTI_INTERVAL_H
A basic mathematical interval class.
Definition: interval.h:33
static GfInterval GetFullInterval()
Returns the full interval (-inf, inf).
Definition: interval.h:325
GfMultiInterval represents a subset of the real number line as an ordered set of non-intersecting GfI...
Definition: multiInterval.h:30
GF_API const_iterator GetPriorNonContainingInterval(double x) const
Returns an iterator identifying the last (highest) interval whose maximum value is < x.
GF_API const_iterator GetNextNonContainingInterval(double x) const
Returns an iterator identifying the first (lowest) interval whose minimum value is > x.
GF_API void Add(const GfInterval &i)
Add the given interval to the multi-interval.
void swap(GfMultiInterval &other)
Swap two multi-intervals.
GF_API GfMultiInterval GetComplement() const
Return the complement of this set.
GF_API void Clear()
Clear the multi-interval.
Definition: multiInterval.h:91
GF_API const_iterator lower_bound(double x) const
Returns an iterator identifying the first (lowest) interval whose minimum value is >= x.
GF_API bool Contains(double d) const
Returns true if the multi-interval contains the given value.
GF_API const_iterator upper_bound(double x) const
Returns an iterator identifying the first (lowest) interval whose minimum value is > x.
GF_API void ArithmeticAdd(const GfInterval &i)
Uses the given interval to extend the multi-interval in the interval arithmetic sense.
GF_API GfMultiInterval(const std::vector< GfInterval > &intervals)
Constructs an multi-interval containing the given input intervals.
GF_API const_iterator GetContainingInterval(double x) const
Returns an iterator identifying the interval that contains x.
GF_API bool Contains(const GfMultiInterval &s) const
Returns true if the multi-interval contains all the intervals in the given multi-interval.
GF_API bool IsEmpty() const
Returns true if the multi-interval is empty.
Definition: multiInterval.h:66
GF_API void Remove(const GfMultiInterval &s)
Remove the given multi-interval from this multi-interval.
GF_API void Add(const GfMultiInterval &s)
Add the given multi-interval to the multi-interval.
GF_API GfInterval GetBounds() const
Returns an interval bounding the entire multi-interval.
GF_API void Remove(const GfInterval &i)
Remove the given interval from this multi-interval.
GF_API size_t GetSize() const
Returns the number of intervals in the set.
Definition: multiInterval.h:69
static GfMultiInterval GetFullInterval()
Returns the full interval (-inf, inf).
GF_API GfMultiInterval(const GfInterval &i)
Constructs an multi-interval with the single given interval.
GF_API size_t Hash() const
Hash value.
GF_API bool Contains(const GfInterval &i) const
Returns true if the multi-interval contains the given interval.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].