HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
range1f.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_RANGE1F_H
29 #define PXR_BASE_GF_RANGE1F_H
30 
31 /// \file gf/range1f.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 GfRange1f> { static const bool value = true; };
51 
52 /// \class GfRange1f
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 GfRange1f
62 {
63 public:
64 
65  /// Helper typedef.
66  typedef float 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  GfRange1f(float min, float max)
85  : _min(min), _max(max)
86  {
87  }
88 
89 
90  /// Construct from GfRange1d.
91  GF_API
92  explicit GfRange1f(class GfRange1d const &other);
93 
94  /// Returns the minimum value of the range.
95  float GetMin() const { return _min; }
96 
97  /// Returns the maximum value of the range.
98  float GetMax() const { return _max; }
99 
100  /// Returns the size of the range.
101  float 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  float 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(float min) { _min = min; }
113 
114  /// Sets the maximum value of the range.
115  void SetMax(float 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(float point) { UnionWith(point); }
125 
126  /// Modifies the range if necessary to surround the given range.
127  /// \deprecated Use UnionWith() instead.
128  void ExtendBy(const GfRange1f &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(float 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 GfRange1f &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(float 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 GfRange1f &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 GfRange1f &range) const {
162  return (range._max < _min || range._min > _max);
163  }
164 
165  /// Returns the smallest \c GfRange1f which contains both \p a and \p b.
166  static GfRange1f GetUnion(const GfRange1f &a, const GfRange1f &b) {
167  GfRange1f 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 GfRange1f &UnionWith(const GfRange1f &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 GfRange1f &UnionWith(float b) {
182  _FindMin(_min,b);
183  _FindMax(_max,b);
184  return *this;
185  }
186 
187  /// Returns the smallest \c GfRange1f which contains both \p a and \p b
188  /// \deprecated Use GetUnion() instead.
189  static GfRange1f Union(const GfRange1f &a, const GfRange1f &b) {
190  return GetUnion(a, b);
191  }
192 
193  /// Extend \p this to include \p b.
194  /// \deprecated Use UnionWith() instead.
195  const GfRange1f &Union(const GfRange1f &b) {
196  return UnionWith(b);
197  }
198 
199  /// Extend \p this to include \p b.
200  /// \deprecated Use UnionWith() instead.
201  const GfRange1f &Union(float b) {
202  return UnionWith(b);
203  }
204 
205  /// Returns a \c GfRange1f that describes the intersection of \p a and \p b.
206  static GfRange1f GetIntersection(const GfRange1f &a, const GfRange1f &b) {
207  GfRange1f res = a;
208  _FindMax(res._min,b._min);
209  _FindMin(res._max,b._max);
210  return res;
211  }
212 
213  /// Returns a \c GfRange1f that describes the intersection of \p a and \p b.
214  /// \deprecated Use GetIntersection() instead.
215  static GfRange1f Intersection(const GfRange1f &a, const GfRange1f &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  GfRange1f &operator *=(double m) {
250  if (m > 0) {
251  _min *= m;
252  _max *= m;
253  } else {
254  float tmp = _min;
255  _min = _max * m;
256  _max = tmp * m;
257  }
258  return *this;
259  }
260 
261  /// unary division.
262  GfRange1f &operator /=(double m) {
263  return *this *= (1.0 / m);
264  }
265 
266  /// binary sum.
267  GfRange1f operator +(const GfRange1f &b) const {
268  return GfRange1f(_min + b._min, _max + b._max);
269  }
270 
271 
272  /// binary difference.
273  GfRange1f operator -(const GfRange1f &b) const {
274  return GfRange1f(_min - b._max, _max - b._min);
275  }
276 
277  /// scalar multiply.
278  friend GfRange1f operator *(double m, const GfRange1f &r) {
279  return (m > 0 ?
280  GfRange1f(r._min*m, r._max*m) :
281  GfRange1f(r._max*m, r._min*m));
282  }
283 
284  /// scalar multiply.
285  friend GfRange1f operator *(const GfRange1f &r, double m) {
286  return (m > 0 ?
287  GfRange1f(r._min*m, r._max*m) :
288  GfRange1f(r._max*m, r._min*m));
289  }
290 
291  /// scalar divide.
292  friend GfRange1f operator /(const GfRange1f &r, double m) {
293  return r * (1.0 / m);
294  }
295 
296  /// hash.
297  friend inline size_t hash_value(const GfRange1f &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 GfRange1f &b) const {
303  return (_min == b._min && _max == b._max);
304  }
305 
306  bool operator !=(const GfRange1f &b) const {
307  return !(*this == b);
308  }
309 
310  /// Compare this range to a GfRange1d.
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 GfRange1d& other) const;
315  GF_API inline bool operator !=(const GfRange1d& other) const;
316 
317  /// Compute the squared distance from a point to the range.
318  GF_API
319  double GetDistanceSquared(float p) const;
320 
321 
322  private:
323  /// Minimum and maximum points.
324  float _min, _max;
325 
326  /// Extends minimum point if necessary to contain given point.
327  static void _FindMin(float &dest, float point) {
328  if (point < dest) dest = point;
329  }
330 
331  /// Extends maximum point if necessary to contain given point.
332  static void _FindMax(float &dest, float point) {
333  if (point > dest) dest = point;
334  }
335 };
336 
337 /// Output a GfRange1f.
338 /// \ingroup group_gf_DebuggingOutput
339 GF_API std::ostream& operator<<(std::ostream &, GfRange1f const &);
340 
342 #include "pxr/base/gf/range1d.h"
344 
345 inline bool
346 GfRange1f::operator ==(const GfRange1d& other) const {
347  return _min == float(other.GetMin()) &&
348  _max == float(other.GetMax());
349 }
350 
351 inline bool
352 GfRange1f::operator !=(const GfRange1d& other) const {
353  return !(*this == other);
354 }
355 
356 
358 
359 #endif // PXR_BASE_GF_RANGE1F_H
void SetMax(float max)
Sets the maximum value of the range.
Definition: range1f.h:115
double GetMin() const
Returns the minimum value of the range.
Definition: range1d.h:95
void ExtendBy(const GfRange1f &range)
Definition: range1f.h:128
GLenum GLint * range
Definition: glcorearb.h:1925
bool IsInside(float point) const
Definition: range1f.h:146
*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
GfRange1f(float min, float max)
This constructor initializes the minimum and maximum points.
Definition: range1f.h:84
GfRange1f & operator-=(const GfRange1f &b)
unary difference.
Definition: range1f.h:242
const GfRange1f & IntersectWith(const GfRange1f &b)
Definition: range1f.h:221
bool Contains(const GfRange1f &range) const
Definition: range1f.h:139
void ExtendBy(float point)
Definition: range1f.h:124
GfRange1f operator-(const GfRange1f &b) const
binary difference.
Definition: range1f.h:273
bool IsOutside(const GfRange1f &range) const
Definition: range1f.h:161
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
const GfRange1f & UnionWith(float b)
Extend this to include b.
Definition: range1f.h:181
static const size_t dimension
Definition: range1f.h:68
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
void SetMin(float min)
Sets the minimum value of the range.
Definition: range1f.h:112
static GfRange1f GetUnion(const GfRange1f &a, const GfRange1f &b)
Returns the smallest GfRange1f which contains both a and b.
Definition: range1f.h:166
GfRange1f & operator+=(const GfRange1f &b)
unary sum.
Definition: range1f.h:235
static GfRange1f Intersection(const GfRange1f &a, const GfRange1f &b)
Definition: range1f.h:215
static GfRange1f GetIntersection(const GfRange1f &a, const GfRange1f &b)
Returns a GfRange1f that describes the intersection of a and b.
Definition: range1f.h:206
MinMaxType ScalarType
Definition: range1f.h:69
double GetMax() const
Returns the maximum value of the range.
Definition: range1d.h:98
const GfRange1f & Union(const GfRange1f &b)
Definition: range1f.h:195
GfRange1f operator+(const GfRange1f &b) const
binary sum.
Definition: range1f.h:267
float GetSize() const
Returns the size of the range.
Definition: range1f.h:101
bool operator!=(const GfRange1f &b) const
Definition: range1f.h:306
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
bool IsEmpty() const
Returns whether the range is empty (max < min).
Definition: range1f.h:118
GfRange1f()
The default constructor creates an empty range.
Definition: range1f.h:79
float GetMin() const
Returns the minimum value of the range.
Definition: range1f.h:95
void SetEmpty()
Sets the range to an empty interval.
Definition: range1f.h:73
friend size_t hash_value(const GfRange1f &r)
hash.
Definition: range1f.h:297
float MinMaxType
Helper typedef.
Definition: range1f.h:66
GfRange1f & operator/=(double m)
unary division.
Definition: range1f.h:262
static size_t Combine(Args &&...args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:519
float GetMidpoint() const
Definition: range1f.h:106
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
const GfRange1f & UnionWith(const GfRange1f &b)
Extend this to include b.
Definition: range1f.h:174
friend GfRange1f operator/(const GfRange1f &r, double m)
scalar divide.
Definition: range1f.h:292
float GetMax() const
Returns the maximum value of the range.
Definition: range1f.h:98
GF_API double GetDistanceSquared(float p) const
Compute the squared distance from a point to the range.
const GfRange1f & Intersection(const GfRange1f &b)
Definition: range1f.h:230
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
GfRange1f & operator*=(double m)
unary multiply.
Definition: range1f.h:249
friend GfRange1f operator*(double m, const GfRange1f &r)
scalar multiply.
Definition: range1f.h:278
bool IsInside(const GfRange1f &range) const
Definition: range1f.h:154
Definition: core.h:1131
bool Contains(float point) const
Definition: range1f.h:132
GLboolean r
Definition: glcorearb.h:1222
const GfRange1f & Union(float b)
Definition: range1f.h:201
GF_API std::ostream & operator<<(std::ostream &, GfRange1f const &)
static GfRange1f Union(const GfRange1f &a, const GfRange1f &b)
Definition: range1f.h:189
bool operator==(const GfRange1f &b) const
The min and max points must match exactly for equality.
Definition: range1f.h:302
#define GF_API
Definition: api.h:40