HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
range1d.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 ////////////////////////////////////////////////////////////////////////
25 // This file is generated by a script. Do not edit directly. Edit the
26 // range.template.h file to make changes.
27 
28 #ifndef PXR_BASE_GF_RANGE1D_H
29 #define PXR_BASE_GF_RANGE1D_H
30 
31 /// \file gf/range1d.h
32 /// \ingroup group_gf_BasicGeometry
33 
34 #include "pxr/pxr.h"
35 
36 #include "pxr/base/gf/api.h"
37 #include "pxr/base/gf/traits.h"
38 #include "pxr/base/tf/hash.h"
39 
40 #include <cfloat>
41 #include <cstddef>
42 #include <iosfwd>
43 
45 
46 class GfRange1d;
47 class GfRange1f;
48 
49 template <>
50 struct GfIsGfRange<class GfRange1d> { static const bool value = true; };
51 
52 /// \class GfRange1d
53 /// \ingroup group_gf_BasicGeometry
54 ///
55 /// Basic type: 1-dimensional floating point range.
56 ///
57 /// This class represents a 1-dimensional range (or interval) All
58 /// operations are component-wise and conform to interval mathematics. An
59 /// empty range is one where max < min.
60 /// The default empty is [FLT_MAX,-FLT_MAX]
61 class GfRange1d
62 {
63 public:
64 
65  /// Helper typedef.
66  typedef double MinMaxType;
67 
68  static const size_t dimension = 1;
70 
71  /// Sets the range to an empty interval
72  // TODO check whether this can be deprecated.
73  void inline SetEmpty() {
74  _min = FLT_MAX;
75  _max = -FLT_MAX;
76  }
77 
78  /// The default constructor creates an empty range.
80  SetEmpty();
81  }
82 
83  /// This constructor initializes the minimum and maximum points.
84  GfRange1d(double min, double max)
85  : _min(min), _max(max)
86  {
87  }
88 
89 
90  /// Implicitly convert from GfRange1f.
91  GF_API
92  GfRange1d(class GfRange1f const &other);
93 
94  /// Returns the minimum value of the range.
95  double GetMin() const { return _min; }
96 
97  /// Returns the maximum value of the range.
98  double GetMax() const { return _max; }
99 
100  /// Returns the size of the range.
101  double GetSize() const { return _max - _min; }
102 
103  /// Returns the midpoint of the range, that is, 0.5*(min+max).
104  /// Note: this returns zero in the case of default-constructed ranges,
105  /// or ranges set via SetEmpty().
106  double GetMidpoint() const {
107  return static_cast<ScalarType>(0.5) * _min
108  + static_cast<ScalarType>(0.5) * _max;
109  }
110 
111  /// Sets the minimum value of the range.
112  void SetMin(double min) { _min = min; }
113 
114  /// Sets the maximum value of the range.
115  void SetMax(double max) { _max = max; }
116 
117  /// Returns whether the range is empty (max < min).
118  bool IsEmpty() const {
119  return _min > _max;
120  }
121 
122  /// Modifies the range if necessary to surround the given value.
123  /// \deprecated Use UnionWith() instead.
124  void ExtendBy(double point) { UnionWith(point); }
125 
126  /// Modifies the range if necessary to surround the given range.
127  /// \deprecated Use UnionWith() instead.
128  void ExtendBy(const GfRange1d &range) { UnionWith(range); }
129 
130  /// Returns true if the \p point is located inside the range. As with all
131  /// operations of this type, the range is assumed to include its extrema.
132  bool Contains(double point) const {
133  return (point >= _min && point <= _max);
134  }
135 
136  /// Returns true if the \p range is located entirely inside the range. As
137  /// with all operations of this type, the ranges are assumed to include
138  /// their extrema.
139  bool Contains(const GfRange1d &range) const {
140  return Contains(range._min) && Contains(range._max);
141  }
142 
143  /// Returns true if the \p point is located inside the range. As with all
144  /// operations of this type, the range is assumed to include its extrema.
145  /// \deprecated Use Contains() instead.
146  bool IsInside(double point) const {
147  return Contains(point);
148  }
149 
150  /// Returns true if the \p range is located entirely inside the range. As
151  /// with all operations of this type, the ranges are assumed to include
152  /// their extrema.
153  /// \deprecated Use Contains() instead.
154  bool IsInside(const GfRange1d &range) const {
155  return Contains(range);
156  }
157 
158  /// Returns true if the \p range is located entirely outside the range. As
159  /// with all operations of this type, the ranges are assumed to include
160  /// their extrema.
161  bool IsOutside(const GfRange1d &range) const {
162  return (range._max < _min || range._min > _max);
163  }
164 
165  /// Returns the smallest \c GfRange1d which contains both \p a and \p b.
166  static GfRange1d GetUnion(const GfRange1d &a, const GfRange1d &b) {
167  GfRange1d res = a;
168  _FindMin(res._min,b._min);
169  _FindMax(res._max,b._max);
170  return res;
171  }
172 
173  /// Extend \p this to include \p b.
174  const GfRange1d &UnionWith(const GfRange1d &b) {
175  _FindMin(_min,b._min);
176  _FindMax(_max,b._max);
177  return *this;
178  }
179 
180  /// Extend \p this to include \p b.
181  const GfRange1d &UnionWith(double b) {
182  _FindMin(_min,b);
183  _FindMax(_max,b);
184  return *this;
185  }
186 
187  /// Returns the smallest \c GfRange1d which contains both \p a and \p b
188  /// \deprecated Use GetUnion() instead.
189  static GfRange1d Union(const GfRange1d &a, const GfRange1d &b) {
190  return GetUnion(a, b);
191  }
192 
193  /// Extend \p this to include \p b.
194  /// \deprecated Use UnionWith() instead.
195  const GfRange1d &Union(const GfRange1d &b) {
196  return UnionWith(b);
197  }
198 
199  /// Extend \p this to include \p b.
200  /// \deprecated Use UnionWith() instead.
201  const GfRange1d &Union(double b) {
202  return UnionWith(b);
203  }
204 
205  /// Returns a \c GfRange1d that describes the intersection of \p a and \p b.
206  static GfRange1d GetIntersection(const GfRange1d &a, const GfRange1d &b) {
207  GfRange1d res = a;
208  _FindMax(res._min,b._min);
209  _FindMin(res._max,b._max);
210  return res;
211  }
212 
213  /// Returns a \c GfRange1d that describes the intersection of \p a and \p b.
214  /// \deprecated Use GetIntersection() instead.
215  static GfRange1d Intersection(const GfRange1d &a, const GfRange1d &b) {
216  return GetIntersection(a, b);
217  }
218 
219  /// Modifies this range to hold its intersection with \p b and returns the
220  /// result
222  _FindMax(_min,b._min);
223  _FindMin(_max,b._max);
224  return *this;
225  }
226 
227  /// Modifies this range to hold its intersection with \p b and returns the
228  /// result.
229  /// \deprecated Use IntersectWith() instead.
231  return IntersectWith(b);
232  }
233 
234  /// unary sum.
236  _min += b._min;
237  _max += b._max;
238  return *this;
239  }
240 
241  /// unary difference.
243  _min -= b._max;
244  _max -= b._min;
245  return *this;
246  }
247 
248  /// unary multiply.
249  GfRange1d &operator *=(double m) {
250  if (m > 0) {
251  _min *= m;
252  _max *= m;
253  } else {
254  double tmp = _min;
255  _min = _max * m;
256  _max = tmp * m;
257  }
258  return *this;
259  }
260 
261  /// unary division.
262  GfRange1d &operator /=(double m) {
263  return *this *= (1.0 / m);
264  }
265 
266  /// binary sum.
267  GfRange1d operator +(const GfRange1d &b) const {
268  return GfRange1d(_min + b._min, _max + b._max);
269  }
270 
271 
272  /// binary difference.
273  GfRange1d operator -(const GfRange1d &b) const {
274  return GfRange1d(_min - b._max, _max - b._min);
275  }
276 
277  /// scalar multiply.
278  friend GfRange1d operator *(double m, const GfRange1d &r) {
279  return (m > 0 ?
280  GfRange1d(r._min*m, r._max*m) :
281  GfRange1d(r._max*m, r._min*m));
282  }
283 
284  /// scalar multiply.
285  friend GfRange1d operator *(const GfRange1d &r, double m) {
286  return (m > 0 ?
287  GfRange1d(r._min*m, r._max*m) :
288  GfRange1d(r._max*m, r._min*m));
289  }
290 
291  /// scalar divide.
292  friend GfRange1d operator /(const GfRange1d &r, double m) {
293  return r * (1.0 / m);
294  }
295 
296  /// hash.
297  friend inline size_t hash_value(const GfRange1d &r) {
298  return TfHash::Combine(r._min, r._max);
299  }
300 
301  /// The min and max points must match exactly for equality.
302  bool operator ==(const GfRange1d &b) const {
303  return (_min == b._min && _max == b._max);
304  }
305 
306  bool operator !=(const GfRange1d &b) const {
307  return !(*this == b);
308  }
309 
310  /// Compare this range to a GfRange1f.
311  ///
312  /// The values must match exactly and it does exactly what you might
313  /// expect when comparing float and double values.
314  GF_API inline bool operator ==(const GfRange1f& other) const;
315  GF_API inline bool operator !=(const GfRange1f& other) const;
316 
317  /// Compute the squared distance from a point to the range.
318  GF_API
319  double GetDistanceSquared(double p) const;
320 
321 
322  private:
323  /// Minimum and maximum points.
324  double _min, _max;
325 
326  /// Extends minimum point if necessary to contain given point.
327  static void _FindMin(double &dest, double point) {
328  if (point < dest) dest = point;
329  }
330 
331  /// Extends maximum point if necessary to contain given point.
332  static void _FindMax(double &dest, double point) {
333  if (point > dest) dest = point;
334  }
335 };
336 
337 /// Output a GfRange1d.
338 /// \ingroup group_gf_DebuggingOutput
339 GF_API std::ostream& operator<<(std::ostream &, GfRange1d const &);
340 
342 #include "pxr/base/gf/range1f.h"
344 
345 inline bool
346 GfRange1d::operator ==(const GfRange1f& other) const {
347  return _min == double(other.GetMin()) &&
348  _max == double(other.GetMax());
349 }
350 
351 inline bool
352 GfRange1d::operator !=(const GfRange1f& other) const {
353  return !(*this == other);
354 }
355 
356 
358 
359 #endif // PXR_BASE_GF_RANGE1D_H
double MinMaxType
Helper typedef.
Definition: range1d.h:66
const GfRange1d & UnionWith(const GfRange1d &b)
Extend this to include b.
Definition: range1d.h:174
double GetMin() const
Returns the minimum value of the range.
Definition: range1d.h:95
bool Contains(double point) const
Definition: range1d.h:132
GLenum GLint * range
Definition: glcorearb.h:1925
static const size_t dimension
Definition: range1d.h:68
static GfRange1d Union(const GfRange1d &a, const GfRange1d &b)
Definition: range1d.h:189
friend size_t hash_value(const GfRange1d &r)
hash.
Definition: range1d.h:297
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:623
const GfRange1d & Union(double b)
Definition: range1d.h:201
void ExtendBy(double point)
Definition: range1d.h:124
GfRange1d & operator+=(const GfRange1d &b)
unary sum.
Definition: range1d.h:235
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
bool operator==(const GfRange1d &b) const
The min and max points must match exactly for equality.
Definition: range1d.h:302
GF_API std::ostream & operator<<(std::ostream &, GfRange1d const &)
GfRange1d & operator*=(double m)
unary multiply.
Definition: range1d.h:249
GfRange1d & operator/=(double m)
unary division.
Definition: range1d.h:262
bool operator!=(const GfRange1d &b) const
Definition: range1d.h:306
const GfRange1d & IntersectWith(const GfRange1d &b)
Definition: range1d.h:221
const GfRange1d & Intersection(const GfRange1d &b)
Definition: range1d.h:230
double GetMax() const
Returns the maximum value of the range.
Definition: range1d.h:98
friend GfRange1d operator*(double m, const GfRange1d &r)
scalar multiply.
Definition: range1d.h:278
double GetMidpoint() const
Definition: range1d.h:106
GfRange1d operator+(const GfRange1d &b) const
binary sum.
Definition: range1d.h:267
bool IsEmpty() const
Returns whether the range is empty (max < min).
Definition: range1d.h:118
MinMaxType ScalarType
Definition: range1d.h:69
void SetMax(double max)
Sets the maximum value of the range.
Definition: range1d.h:115
void SetEmpty()
Sets the range to an empty interval.
Definition: range1d.h:73
bool IsInside(const GfRange1d &range) const
Definition: range1d.h:154
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GF_API double GetDistanceSquared(double p) const
Compute the squared distance from a point to the range.
float GetMin() const
Returns the minimum value of the range.
Definition: range1f.h:95
static GfRange1d GetUnion(const GfRange1d &a, const GfRange1d &b)
Returns the smallest GfRange1d which contains both a and b.
Definition: range1d.h:166
void SetMin(double min)
Sets the minimum value of the range.
Definition: range1d.h:112
bool IsInside(double point) const
Definition: range1d.h:146
GfRange1d()
The default constructor creates an empty range.
Definition: range1d.h:79
double GetSize() const
Returns the size of the range.
Definition: range1d.h:101
static size_t Combine(Args &&...args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:492
bool IsOutside(const GfRange1d &range) const
Definition: range1d.h:161
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
bool Contains(const GfRange1d &range) const
Definition: range1d.h:139
static GfRange1d GetIntersection(const GfRange1d &a, const GfRange1d &b)
Returns a GfRange1d that describes the intersection of a and b.
Definition: range1d.h:206
GfRange1d & operator-=(const GfRange1d &b)
unary difference.
Definition: range1d.h:242
float GetMax() const
Returns the maximum value of the range.
Definition: range1f.h:98
friend GfRange1d operator/(const GfRange1d &r, double m)
scalar divide.
Definition: range1d.h:292
GfRange1d(double min, double max)
This constructor initializes the minimum and maximum points.
Definition: range1d.h:84
GfRange1d operator-(const GfRange1d &b) const
binary difference.
Definition: range1d.h:273
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
Definition: core.h:1131
GLboolean r
Definition: glcorearb.h:1222
static GfRange1d Intersection(const GfRange1d &a, const GfRange1d &b)
Definition: range1d.h:215
const GfRange1d & UnionWith(double b)
Extend this to include b.
Definition: range1d.h:181
void ExtendBy(const GfRange1d &range)
Definition: range1d.h:128
#define GF_API
Definition: api.h:40
const GfRange1d & Union(const GfRange1d &b)
Definition: range1d.h:195