All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
multiInterval.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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 #ifndef GF_INTERVAL_SET_H
25 #define GF_INTERVAL_SET_H
26 
29 
30 #include "pxr/pxr.h"
31 #include "pxr/base/gf/interval.h"
32 #include "pxr/base/gf/api.h"
33 
34 #include <iosfwd>
35 #include <set>
36 #include <vector>
37 
38 PXR_NAMESPACE_OPEN_SCOPE
39 
47 {
48 public:
49  typedef std::set<GfInterval> Set;
50  typedef Set::const_iterator const_iterator;
51  typedef Set::const_iterator iterator;
52 
56  GF_API GfMultiInterval() {}
58  GF_API GfMultiInterval(const GfMultiInterval &s) : _set(s._set) {}
60  GF_API explicit GfMultiInterval(const GfInterval &i);
62  GF_API explicit GfMultiInterval(const std::vector<GfInterval> &intervals);
64 
65  GF_API bool operator==(const GfMultiInterval &that) const { return _set == that._set; }
66  GF_API bool operator!=(const GfMultiInterval &that) const { return !(*this == that); }
67  GF_API bool operator<(const GfMultiInterval &that) const { return _set < that._set; }
68  GF_API bool operator>=(const GfMultiInterval &that) const { return !(*this < that); }
69  GF_API bool operator>(const GfMultiInterval &that) const { return (that < *this); }
70  GF_API bool operator<=(const GfMultiInterval &that) const { return !(that < *this); }
71 
72 
75  GF_API size_t Hash() const;
76 
77  friend inline size_t hash_value(const GfMultiInterval &mi) {
78  return mi.Hash();
79  }
80 
83 
85  GF_API bool IsEmpty() const { return _set.empty(); }
86 
88  GF_API size_t GetSize() const { return _set.size(); }
89 
92  GF_API GfInterval GetBounds() const;
93 
95  GF_API bool Contains(double d) const;
96 
98  GF_API bool Contains(const GfInterval & i) const;
99 
102  GF_API bool Contains(const GfMultiInterval & s) const;
103 
105 
108 
110  GF_API void Clear() { _set.clear(); }
111 
113  GF_API void Add( const GfInterval & i );
116  GF_API void Add( const GfMultiInterval &s );
117 
120  GF_API void ArithmeticAdd( const GfInterval &i );
121 
123  GF_API void Remove( const GfInterval & i );
125  GF_API void Remove( const GfMultiInterval &s );
126 
127  GF_API void Intersect( const GfInterval & i );
128  GF_API void Intersect( const GfMultiInterval &s );
129 
131  GF_API GfMultiInterval GetComplement() const;
132 
134 
139 
140  GF_API const_iterator begin() const { return _set.begin(); }
141  GF_API const_iterator end() const { return _set.end(); }
142 
145  GF_API const_iterator lower_bound( double x ) const;
146 
149  GF_API const_iterator upper_bound( double x ) const;
150 
153  GF_API const_iterator GetNextNonContainingInterval( double x ) const;
154 
157  GF_API const_iterator GetPriorNonContainingInterval( double x ) const;
158 
161  GF_API const_iterator GetContainingInterval( double x ) const;
162 
164 
168  }
169 
171  void swap(GfMultiInterval &other) { _set.swap(other._set); }
172 
173 private:
174  void _AssertInvariants() const;
175 
176  Set _set;
177 };
178 
181 GF_API std::ostream & operator<<(std::ostream &out, const GfMultiInterval &s);
182 
183 PXR_NAMESPACE_CLOSE_SCOPE
184 
185 #endif // GF_INTERVAL_SET_H
void swap(GfMultiInterval &other)
Swap two multi-intervals.
GF_API void Remove(const GfInterval &i)
Remove the given interval from this multi-interval.
GF_API const_iterator GetPriorNonContainingInterval(double x) const
Returns an iterator identifying the last (highest) interval whose maximum value is &lt; x...
GF_API GfMultiInterval(const GfMultiInterval &s)
Constructs an multi-interval by copying the given set.
Definition: multiInterval.h:58
GF_API GfInterval GetBounds() const
Returns an interval bounding the entire multi-interval.
GF_API void ArithmeticAdd(const GfInterval &i)
Uses the given interval to extend the multi-interval in the interval arithmetic sense.
GF_API void Add(const GfInterval &i)
Add the given interval to the multi-interval.
GF_API const_iterator upper_bound(double x) const
Returns an iterator identifying the first (lowest) interval whose minimum value is &gt; x...
GF_API bool IsEmpty() const
Returns true if the multi-interval is empty.
Definition: multiInterval.h:85
GF_API bool Contains(double d) const
Returns true if the multi-interval contains the given value.
GF_API const_iterator lower_bound(double x) const
Returns an iterator identifying the first (lowest) interval whose minimum value is &gt;= x...
GF_API size_t GetSize() const
Returns the number of intervals in the set.
Definition: multiInterval.h:88
static GfMultiInterval GetFullInterval()
Returns the full interval (-inf, inf).
GF_API size_t Hash() const
Hash value.
A basic mathematical interval class.
Definition: interval.h:50
static GfInterval GetFullInterval()
Returns the full interval (-inf, inf).
Definition: interval.h:346
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
GfMultiInterval represents a subset of the real number line as an ordered set of non-intersecting GfI...
Definition: multiInterval.h:46
GF_API void Clear()
Clear the multi-interval.
GF_API const_iterator GetNextNonContainingInterval(double x) const
Returns an iterator identifying the first (loest) interval whose minimum value is &gt; x...
GF_API GfMultiInterval GetComplement() const
Return the complement of this set.
GF_API const_iterator GetContainingInterval(double x) const
Returns an iterator identifying the interval that contains x.