HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Coord.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2012-2017 DreamWorks Animation LLC
4 //
5 // All rights reserved. This software is distributed under the
6 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
7 //
8 // Redistributions of source code must retain the above copyright
9 // and license notice and the following restrictions and disclaimer.
10 //
11 // * Neither the name of DreamWorks Animation nor the names of
12 // its contributors may be used to endorse or promote products derived
13 // from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
27 // LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
28 //
29 ///////////////////////////////////////////////////////////////////////////
30 
31 #ifndef OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED
32 #define OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED
33 
34 #include <array> // for std::array
35 #include <openvdb/Platform.h>
36 #include "Math.h"
37 #include "Vec3.h"
38 
39 namespace tbb { class split; } // forward declaration
40 
41 
42 namespace openvdb {
44 namespace OPENVDB_VERSION_NAME {
45 namespace math {
46 
47 /// @brief Signed (x, y, z) 32-bit integer coordinates
48 class Coord
49 {
50 public:
51  typedef int32_t Int32;
52  typedef uint32_t Index32;
53  typedef Vec3<Int32> Vec3i;
55 
56  typedef Int32 ValueType;
57  typedef std::numeric_limits<ValueType> Limits;
58 
59  Coord(): mVec{{0, 0, 0}} {}
60  explicit Coord(Int32 xyz): mVec{{xyz, xyz, xyz}} {}
61  Coord(Int32 x, Int32 y, Int32 z): mVec{{x, y, z}} {}
62  explicit Coord(const Vec3i& v): mVec{{v[0], v[1], v[2]}} {}
63  explicit Coord(const Vec3I& v): mVec{{Int32(v[0]), Int32(v[1]), Int32(v[2])}} {}
64  explicit Coord(const Int32* v): mVec{{v[0], v[1], v[2]}} {}
65 
66  /// @brief Return the smallest possible coordinate
67  static Coord min() { return Coord(Limits::min()); }
68 
69  /// @brief Return the largest possible coordinate
70  static Coord max() { return Coord(Limits::max()); }
71 
72  /// @brief Return @a xyz rounded to the closest integer coordinates
73  /// (cell centered conversion).
74  template<typename T> static Coord round(const Vec3<T>& xyz)
75  {
76  return Coord(Int32(Round(xyz[0])), Int32(Round(xyz[1])), Int32(Round(xyz[2])));
77  }
78  /// @brief Return the largest integer coordinates that are not greater
79  /// than @a xyz (node centered conversion).
80  template<typename T> static Coord floor(const Vec3<T>& xyz)
81  {
82  return Coord(Int32(Floor(xyz[0])), Int32(Floor(xyz[1])), Int32(Floor(xyz[2])));
83  }
84 
85  /// @brief Return the largest integer coordinates that are not greater
86  /// than @a xyz+1 (node centered conversion).
87  template<typename T> static Coord ceil(const Vec3<T>& xyz)
88  {
89  return Coord(Int32(Ceil(xyz[0])), Int32(Ceil(xyz[1])), Int32(Ceil(xyz[2])));
90  }
91 
92  /// @brief Reset all three coordinates with the specified arguments
93  Coord& reset(Int32 x, Int32 y, Int32 z)
94  {
95  mVec[0] = x;
96  mVec[1] = y;
97  mVec[2] = z;
98  return *this;
99  }
100  /// @brief Reset all three coordinates with the same specified argument
101  Coord& reset(Int32 xyz) { return this->reset(xyz, xyz, xyz); }
102 
103  Coord& setX(Int32 x) { mVec[0] = x; return *this; }
104  Coord& setY(Int32 y) { mVec[1] = y; return *this; }
105  Coord& setZ(Int32 z) { mVec[2] = z; return *this; }
106 
107  Coord& offset(Int32 dx, Int32 dy, Int32 dz)
108  {
109  mVec[0] += dx;
110  mVec[1] += dy;
111  mVec[2] += dz;
112  return *this;
113  }
114  Coord& offset(Int32 n) { return this->offset(n, n, n); }
115  Coord offsetBy(Int32 dx, Int32 dy, Int32 dz) const
116  {
117  return Coord(mVec[0] + dx, mVec[1] + dy, mVec[2] + dz);
118  }
119  Coord offsetBy(Int32 n) const { return offsetBy(n, n, n); }
120 
121  Coord& operator+=(const Coord& rhs)
122  {
123  mVec[0] += rhs[0];
124  mVec[1] += rhs[1];
125  mVec[2] += rhs[2];
126  return *this;
127  }
128  Coord& operator-=(const Coord& rhs)
129  {
130  mVec[0] -= rhs[0];
131  mVec[1] -= rhs[1];
132  mVec[2] -= rhs[2];
133  return *this;
134  }
135  Coord operator+(const Coord& rhs) const
136  {
137  return Coord(mVec[0] + rhs[0], mVec[1] + rhs[1], mVec[2] + rhs[2]);
138  }
139  Coord operator-(const Coord& rhs) const
140  {
141  return Coord(mVec[0] - rhs[0], mVec[1] - rhs[1], mVec[2] - rhs[2]);
142  }
143  Coord operator-() const { return Coord(-mVec[0], -mVec[1], -mVec[2]); }
144 
145  Coord operator>> (size_t n) const { return Coord(mVec[0]>>n, mVec[1]>>n, mVec[2]>>n); }
146  Coord operator<< (size_t n) const { return Coord(mVec[0]<<n, mVec[1]<<n, mVec[2]<<n); }
147  Coord& operator<<=(size_t n) { mVec[0]<<=n; mVec[1]<<=n; mVec[2]<<=n; return *this; }
148  Coord& operator>>=(size_t n) { mVec[0]>>=n; mVec[1]>>=n; mVec[2]>>=n; return *this; }
149  Coord operator& (Int32 n) const { return Coord(mVec[0] & n, mVec[1] & n, mVec[2] & n); }
150  Coord operator| (Int32 n) const { return Coord(mVec[0] | n, mVec[1] | n, mVec[2] | n); }
151  Coord& operator&= (Int32 n) { mVec[0]&=n; mVec[1]&=n; mVec[2]&=n; return *this; }
152  Coord& operator|= (Int32 n) { mVec[0]|=n; mVec[1]|=n; mVec[2]|=n; return *this; }
153 
154  Int32 x() const { return mVec[0]; }
155  Int32 y() const { return mVec[1]; }
156  Int32 z() const { return mVec[2]; }
157  Int32 operator[](size_t i) const { assert(i < 3); return mVec[i]; }
158  Int32& x() { return mVec[0]; }
159  Int32& y() { return mVec[1]; }
160  Int32& z() { return mVec[2]; }
161  Int32& operator[](size_t i) { assert(i < 3); return mVec[i]; }
162 
163  const Int32* data() const { return mVec.data(); }
164  Int32* data() { return mVec.data(); }
165  const Int32* asPointer() const { return mVec.data(); }
166  Int32* asPointer() { return mVec.data(); }
167  Vec3d asVec3d() const { return Vec3d(double(mVec[0]), double(mVec[1]), double(mVec[2])); }
168  Vec3s asVec3s() const { return Vec3s(float(mVec[0]), float(mVec[1]), float(mVec[2])); }
169  Vec3i asVec3i() const { return Vec3i(mVec.data()); }
170  Vec3I asVec3I() const { return Vec3I(Index32(mVec[0]), Index32(mVec[1]), Index32(mVec[2])); }
171  void asXYZ(Int32& x, Int32& y, Int32& z) const { x = mVec[0]; y = mVec[1]; z = mVec[2]; }
172 
173  bool operator==(const Coord& rhs) const
174  {
175  return (mVec[0] == rhs.mVec[0] && mVec[1] == rhs.mVec[1] && mVec[2] == rhs.mVec[2]);
176  }
177  bool operator!=(const Coord& rhs) const { return !(*this == rhs); }
178 
179  /// Lexicographic less than
180  bool operator<(const Coord& rhs) const
181  {
182  return this->x() < rhs.x() ? true : this->x() > rhs.x() ? false
183  : this->y() < rhs.y() ? true : this->y() > rhs.y() ? false
184  : this->z() < rhs.z() ? true : false;
185  }
186  /// Lexicographic less than or equal to
187  bool operator<=(const Coord& rhs) const
188  {
189  return this->x() < rhs.x() ? true : this->x() > rhs.x() ? false
190  : this->y() < rhs.y() ? true : this->y() > rhs.y() ? false
191  : this->z() <=rhs.z() ? true : false;
192  }
193  /// Lexicographic greater than
194  bool operator>(const Coord& rhs) const { return !(*this <= rhs); }
195  /// Lexicographic greater than or equal to
196  bool operator>=(const Coord& rhs) const { return !(*this < rhs); }
197 
198  /// Perform a component-wise minimum with the other Coord.
199  void minComponent(const Coord& other)
200  {
201  mVec[0] = std::min(mVec[0], other.mVec[0]);
202  mVec[1] = std::min(mVec[1], other.mVec[1]);
203  mVec[2] = std::min(mVec[2], other.mVec[2]);
204  }
205 
206  /// Perform a component-wise maximum with the other Coord.
207  void maxComponent(const Coord& other)
208  {
209  mVec[0] = std::max(mVec[0], other.mVec[0]);
210  mVec[1] = std::max(mVec[1], other.mVec[1]);
211  mVec[2] = std::max(mVec[2], other.mVec[2]);
212  }
213 
214  /// Return the component-wise minimum of the two Coords.
215  static inline Coord minComponent(const Coord& lhs, const Coord& rhs)
216  {
217  return Coord(std::min(lhs.x(), rhs.x()),
218  std::min(lhs.y(), rhs.y()),
219  std::min(lhs.z(), rhs.z()));
220  }
221 
222  /// Return the component-wise maximum of the two Coords.
223  static inline Coord maxComponent(const Coord& lhs, const Coord& rhs)
224  {
225  return Coord(std::max(lhs.x(), rhs.x()),
226  std::max(lhs.y(), rhs.y()),
227  std::max(lhs.z(), rhs.z()));
228  }
229 
230  /// Return true if any of the components of @a a are smaller than the
231  /// corresponding components of @a b.
232  static inline bool lessThan(const Coord& a, const Coord& b)
233  {
234  return (a[0] < b[0] || a[1] < b[1] || a[2] < b[2]);
235  }
236 
237  /// @brief Return the index (0, 1 or 2) with the smallest value.
238  size_t minIndex() const { return MinIndex(mVec); }
239 
240  /// @brief Return the index (0, 1 or 2) with the largest value.
241  size_t maxIndex() const { return MaxIndex(mVec); }
242 
243  void read(std::istream& is) { is.read(reinterpret_cast<char*>(mVec.data()), sizeof(mVec)); }
244  void write(std::ostream& os) const
245  {
246  os.write(reinterpret_cast<const char*>(mVec.data()), sizeof(mVec));
247  }
248 
249 private:
250  std::array<Int32, 3> mVec;
251 }; // class Coord
252 
253 inline Coord
254 Abs(const Coord& xyz)
255 {
256  return Coord(Abs(xyz[0]), Abs(xyz[1]), Abs(xyz[2]));
257 }
258 
259 ////////////////////////////////////////
260 
261 
262 /// @brief Axis-aligned bounding box of signed integer coordinates
263 /// @note The range of the integer coordinates, [min, max], is inclusive.
264 /// Thus, a bounding box with min = max is not empty but rather encloses
265 /// a single coordinate.
267 {
268 public:
269  typedef uint64_t Index64;
271 
272  /// @brief Iterator over Coord domain covered by a CoordBBox
273  ///
274  /// @note If ZYX is true Z is the fastest moving coordinate, else
275  /// it is the X coordinate, i.e. XYZ traversal
276  template<bool ZYX>
277  class Iterator {
278  public:
279  /// @brief C-tor from a bounding box
280  Iterator(const CoordBBox &b) : mPos(b.min()), mMin(b.min()), mMax(b.max()) {}
281  /// @brief Increments iterator to point to the next coordinate
282  /// @note Stops a the last + 1 coordinate of the bounding box
283  /// as defined by the template parameter.
285  ZYX ? this->next<2,1,0>() : this->next<0,1,2>();//resolved and inlined
286  return *this;
287  }
288  /// @brief Return true if the iterator still points to a valid coordinate
289  operator bool() const {
290  return ZYX ? mPos[0] <= mMax[0] : mPos[2] <= mMax[2];
291  }
292  /// @brief Return a const reference to the coordinate currently pointed to
293  const Coord& operator*() const { return mPos; }
294  private:
295  template<size_t a, size_t b, size_t c>
296  inline void next() {
297  if ( mPos[a] < mMax[a] ) {// this is the most common case
298  ++mPos[a];
299  } else if ( mPos[b] < mMax[b] ) {
300  mPos[a] = mMin[a];
301  ++mPos[b];
302  } else if ( mPos[c] <= mMax[c] ) {
303  mPos[a] = mMin[a];
304  mPos[b] = mMin[b];
305  ++mPos[c];
306  }
307  }
308  Coord mPos, mMin, mMax;
309  };// CoordBBox::Iterator
310 
311  /// @brief The default constructor produces an empty bounding box.
312  CoordBBox(): mMin(Coord::max()), mMax(Coord::min()) {}
313  /// @brief Construct a bounding box with the given @a min and @a max bounds.
314  CoordBBox(const Coord& min, const Coord& max): mMin(min), mMax(max) {}
315  /// @brief Construct from individual components of the min and max bounds.
316  CoordBBox(ValueType x_min, ValueType y_min, ValueType z_min,
317  ValueType x_max, ValueType y_max, ValueType z_max)
318  : mMin(x_min, y_min, z_min), mMax(x_max, y_max, z_max)
319  {
320  }
321  /// @brief Splitting constructor for use in TBB ranges
322  /// @note The other bounding box is assumed to be divisible.
323  CoordBBox(CoordBBox& other, const tbb::split&): mMin(other.mMin), mMax(other.mMax)
324  {
325  assert(this->is_divisible());
326  const size_t n = this->maxExtent();
327  mMax[n] = (mMin[n] + mMax[n]) >> 1;
328  other.mMin[n] = mMax[n] + 1;
329  }
330 
332  {
333  return CoordBBox(min, min.offsetBy(dim - 1));
334  }
335 
336  /// Return an "infinite" bounding box, as defined by the Coord value range.
337  static CoordBBox inf() { return CoordBBox(Coord::min(), Coord::max()); }
338 
339  const Coord& min() const { return mMin; }
340  const Coord& max() const { return mMax; }
341 
342  Coord& min() { return mMin; }
343  Coord& max() { return mMax; }
344 
345  void reset() { mMin = Coord::max(); mMax = Coord::min(); }
346  void reset(const Coord& min, const Coord& max) { mMin = min; mMax = max; }
347  void resetToCube(const Coord& min, ValueType dim) { mMin = min; mMax = min.offsetBy(dim - 1); }
348 
349  /// @note The start coordinate is inclusive.
350  Coord getStart() const { return mMin; }
351  /// @note The end coordinate is exclusive.
352  Coord getEnd() const { return mMax.offsetBy(1); }
353 
354  bool operator==(const CoordBBox& rhs) const { return mMin == rhs.mMin && mMax == rhs.mMax; }
355  bool operator!=(const CoordBBox& rhs) const { return !(*this == rhs); }
356 
357  bool empty() const { return (mMin[0] > mMax[0] || mMin[1] > mMax[1] || mMin[2] > mMax[2]); }
358  //@{
359  /// Return @c true if this bounding box is nonempty
360  operator bool() const { return !this->empty(); }
361  bool hasVolume() const { return !this->empty(); }
362  //@}
363 
364  /// Return the floating-point position of the center of this bounding box.
365  Vec3d getCenter() const { return 0.5 * Vec3d((mMin + mMax).asPointer()); }
366 
367  /// @brief Return the dimensions of the coordinates spanned by this bounding box.
368  /// @note Since coordinates are inclusive, a bounding box with min = max
369  /// has dimensions of (1, 1, 1).
370  Coord dim() const { return mMax.offsetBy(1) - mMin; }
371  /// @todo deprecate - use dim instead
372  Coord extents() const { return this->dim(); }
373  /// @brief Return the integer volume of coordinates spanned by this bounding box.
374  /// @note Since coordinates are inclusive, a bounding box with min = max has volume one.
375  Index64 volume() const
376  {
377  const Coord d = this->dim();
378  return Index64(d[0]) * Index64(d[1]) * Index64(d[2]);
379  }
380  /// Return @c true if this bounding box can be subdivided [mainly for use by TBB].
381  bool is_divisible() const { return mMin[0]<mMax[0] && mMin[1]<mMax[1] && mMin[2]<mMax[2]; }
382 
383  /// @brief Return the index (0, 1 or 2) of the shortest axis.
384  size_t minExtent() const { return this->dim().minIndex(); }
385 
386  /// @brief Return the index (0, 1 or 2) of the longest axis.
387  size_t maxExtent() const { return this->dim().maxIndex(); }
388 
389  /// Return @c true if point (x, y, z) is inside this bounding box.
390  bool isInside(const Coord& xyz) const
391  {
392  return !(Coord::lessThan(xyz,mMin) || Coord::lessThan(mMax,xyz));
393  }
394 
395  /// Return @c true if the given bounding box is inside this bounding box.
396  bool isInside(const CoordBBox& b) const
397  {
398  return !(Coord::lessThan(b.mMin,mMin) || Coord::lessThan(mMax,b.mMax));
399  }
400 
401  /// Return @c true if the given bounding box overlaps with this bounding box.
402  bool hasOverlap(const CoordBBox& b) const
403  {
404  return !(Coord::lessThan(mMax,b.mMin) || Coord::lessThan(b.mMax,mMin));
405  }
406 
407  /// Pad this bounding box with the specified padding.
408  void expand(ValueType padding)
409  {
410  mMin.offset(-padding);
411  mMax.offset( padding);
412  }
413 
414  /// Return a new instance that is expanded by the specified padding.
415  CoordBBox expandBy(ValueType padding) const
416  {
417  return CoordBBox(mMin.offsetBy(-padding),mMax.offsetBy(padding));
418  }
419 
420  /// Expand this bounding box to enclose point (x, y, z).
421  void expand(const Coord& xyz)
422  {
423  mMin.minComponent(xyz);
424  mMax.maxComponent(xyz);
425  }
426 
427  /// Union this bounding box with the given bounding box.
428  void expand(const CoordBBox& bbox)
429  {
430  mMin.minComponent(bbox.min());
431  mMax.maxComponent(bbox.max());
432  }
433  /// Intersect this bounding box with the given bounding box.
434  void intersect(const CoordBBox& bbox)
435  {
436  mMin.maxComponent(bbox.min());
437  mMax.minComponent(bbox.max());
438  }
439  /// @brief Union this bounding box with the cubical bounding box
440  /// of the given size and with the given minimum coordinates.
442  {
443  mMin.minComponent(min);
444  mMax.maxComponent(min.offsetBy(dim-1));
445  }
446  /// Translate this bounding box by @f$(t_x, t_y, t_z)@f$.
447  void translate(const Coord& t) { mMin += t; mMax += t; }
448 
449  /// @brief Populates an array with the eight corner points of this bounding box.
450  /// @details The ordering of the corner points is lexicographic.
451  /// @warning It is assumed that the pointer can be incremented at
452  /// least seven times, i.e. has storage for eight Coord elements!
453  void getCornerPoints(Coord *p) const
454  {
455  assert(p != nullptr);
456  p->reset(mMin.x(), mMin.y(), mMin.z()); ++p;
457  p->reset(mMin.x(), mMin.y(), mMax.z()); ++p;
458  p->reset(mMin.x(), mMax.y(), mMin.z()); ++p;
459  p->reset(mMin.x(), mMax.y(), mMax.z()); ++p;
460  p->reset(mMax.x(), mMin.y(), mMin.z()); ++p;
461  p->reset(mMax.x(), mMin.y(), mMax.z()); ++p;
462  p->reset(mMax.x(), mMax.y(), mMin.z()); ++p;
463  p->reset(mMax.x(), mMax.y(), mMax.z());
464  }
465 
466  //@{
467  /// @brief Bit-wise operations performed on both the min and max members
468  CoordBBox operator>> (size_t n) const { return CoordBBox(mMin>>n, mMax>>n); }
469  CoordBBox operator<< (size_t n) const { return CoordBBox(mMin<<n, mMax<<n); }
470  CoordBBox& operator<<=(size_t n) { mMin <<= n; mMax <<= n; return *this; }
471  CoordBBox& operator>>=(size_t n) { mMin >>= n; mMax >>= n; return *this; }
472  CoordBBox operator& (Coord::Int32 n) const { return CoordBBox(mMin & n, mMax & n); }
473  CoordBBox operator| (Coord::Int32 n) const { return CoordBBox(mMin | n, mMax | n); }
474  CoordBBox& operator&= (Coord::Int32 n) { mMin &= n; mMax &= n; return *this; }
475  CoordBBox& operator|= (Coord::Int32 n) { mMin |= n; mMax |= n; return *this; }
476  //@}
477 
478  /// Unserialize this bounding box from the given stream.
479  void read(std::istream& is) { mMin.read(is); mMax.read(is); }
480  /// Serialize this bounding box to the given stream.
481  void write(std::ostream& os) const { mMin.write(os); mMax.write(os); }
482 
483 private:
484  Coord mMin, mMax;
485 }; // class CoordBBox
486 
487 
488 ////////////////////////////////////////
489 
490 
491 inline std::ostream& operator<<(std::ostream& os, const Coord& xyz)
492 {
493  os << xyz.asVec3i(); return os;
494 }
495 
496 
497 //@{
498 /// Allow a Coord to be added to or subtracted from a Vec3.
499 template<typename T>
501 operator+(const Vec3<T>& v0, const Coord& v1)
502 {
504  result[0] += v1[0];
505  result[1] += v1[1];
506  result[2] += v1[2];
507  return result;
508 }
509 
510 template<typename T>
512 operator+(const Coord& v1, const Vec3<T>& v0)
513 {
515  result[0] += v1[0];
516  result[1] += v1[1];
517  result[2] += v1[2];
518  return result;
519 }
520 //@}
521 
522 
523 //@{
524 /// Allow a Coord to be subtracted from a Vec3.
525 template <typename T>
527 operator-(const Vec3<T>& v0, const Coord& v1)
528 {
530  result[0] -= v1[0];
531  result[1] -= v1[1];
532  result[2] -= v1[2];
533  return result;
534 }
535 
536 template <typename T>
538 operator-(const Coord& v1, const Vec3<T>& v0)
539 {
541  result[0] -= v1[0];
542  result[1] -= v1[1];
543  result[2] -= v1[2];
544  return -result;
545 }
546 //@}
547 
548 inline std::ostream&
549 operator<<(std::ostream& os, const CoordBBox& b)
550 {
551  os << b.min() << " -> " << b.max();
552  return os;
553 }
554 
555 } // namespace math
556 } // namespace OPENVDB_VERSION_NAME
557 } // namespace openvdb
558 
559 #endif // OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED
560 
561 // Copyright (c) 2012-2017 DreamWorks Animation LLC
562 // All rights reserved. This software is distributed under the
563 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
Vec2< T > minComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise minimum of the two vectors.
Definition: Vec2.h:553
void expand(const CoordBBox &bbox)
Union this bounding box with the given bounding box.
Definition: Coord.h:428
CoordBBox & operator<<=(size_t n)
Bit-wise operations performed on both the min and max members.
Definition: Coord.h:470
const Coord & operator*() const
Return a const reference to the coordinate currently pointed to.
Definition: Coord.h:293
bool operator<=(const UT_Vector2T< T > &v1, const UT_Vector2T< T > &v2)
Definition: UT_Vector2.h:376
int Ceil(float x)
Return the ceiling of x.
Definition: Math.h:822
Vec3d getCenter() const
Return the floating-point position of the center of this bounding box.
Definition: Coord.h:365
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:128
void expand(const Coord &xyz)
Expand this bounding box to enclose point (x, y, z).
Definition: Coord.h:421
void translate(const Coord &t)
Translate this bounding box by .
Definition: Coord.h:447
static CoordBBox createCube(const Coord &min, ValueType dim)
Definition: Coord.h:331
size_t MaxIndex(const Vec3T &v)
Return the index [0,1,2] of the largest value in a 3D vector.
Definition: Math.h:911
const GLdouble * v
Definition: glcorearb.h:836
Coord dim() const
Return the dimensions of the coordinates spanned by this bounding box.
Definition: Coord.h:370
bool hasVolume() const
Return true if this bounding box is nonempty.
Definition: Coord.h:361
Vec3< typename promote< T, Coord::ValueType >::type > operator-(const Vec3< T > &v0, const Coord &v1)
Allow a Coord to be subtracted from a Vec3.
Definition: Coord.h:527
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:847
void intersect(const CoordBBox &bbox)
Intersect this bounding box with the given bounding box.
Definition: Coord.h:434
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
void getCornerPoints(Coord *p) const
Populates an array with the eight corner points of this bounding box.
Definition: Coord.h:453
CoordBBox operator|(Coord::Int32 n) const
Bit-wise operations performed on both the min and max members.
Definition: Coord.h:473
size_t minExtent() const
Return the index (0, 1 or 2) of the shortest axis.
Definition: Coord.h:384
GLint y
Definition: glcorearb.h:102
Iterator over Coord domain covered by a CoordBBox.
Definition: Coord.h:277
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:48
void read(T &in, bool &v)
Definition: ImfXdr.h:611
png_uint_32 i
Definition: png.h:2877
void reset(const Coord &min, const Coord &max)
Definition: Coord.h:346
void resetToCube(const Coord &min, ValueType dim)
Definition: Coord.h:347
CoordBBox expandBy(ValueType padding) const
Return a new instance that is expanded by the specified padding.
Definition: Coord.h:415
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:132
CoordBBox()
The default constructor produces an empty bounding box.
Definition: Coord.h:312
void expand(const Coord &min, Coord::ValueType dim)
Union this bounding box with the cubical bounding box of the given size and with the given minimum co...
Definition: Coord.h:441
HALF_EXPORT std::istream & operator>>(std::istream &is, half &h)
static CoordBBox inf()
Return an "infinite" bounding box, as defined by the Coord value range.
Definition: Coord.h:337
GLdouble n
Definition: glcorearb.h:2007
size_t MinIndex(const Vec3T &v)
Return the index [0,1,2] of the smallest value in a 3D vector.
Definition: Math.h:890
bool operator==(const CoordBBox &rhs) const
Definition: Coord.h:354
bool hasOverlap(const CoordBBox &b) const
Return true if the given bounding box overlaps with this bounding box.
Definition: Coord.h:402
CoordBBox operator&(Coord::Int32 n) const
Bit-wise operations performed on both the min and max members.
Definition: Coord.h:472
Coord Abs(const Coord &xyz)
Definition: Coord.h:254
#define OPENVDB_VERSION_NAME
Definition: version.h:43
CoordBBox & operator&=(Coord::Int32 n)
Bit-wise operations performed on both the min and max members.
Definition: Coord.h:474
Index64 volume() const
Return the integer volume of coordinates spanned by this bounding box.
Definition: Coord.h:375
float Round(float x)
Return x rounded to the nearest integer.
Definition: Math.h:785
CoordBBox(const Coord &min, const Coord &max)
Construct a bounding box with the given min and max bounds.
Definition: Coord.h:314
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
void read(std::istream &is)
Unserialize this bounding box from the given stream.
Definition: Coord.h:479
GLintptr offset
Definition: glcorearb.h:664
bool operator>=(const UT_Vector2T< T > &v1, const UT_Vector2T< T > &v2)
Definition: UT_Vector2.h:386
void write(std::ostream &os) const
Serialize this bounding box to the given stream.
Definition: Coord.h:481
Iterator(const CoordBBox &b)
C-tor from a bounding box.
Definition: Coord.h:280
CoordBBox(ValueType x_min, ValueType y_min, ValueType z_min, ValueType x_max, ValueType y_max, ValueType z_max)
Construct from individual components of the min and max bounds.
Definition: Coord.h:316
std::numeric_limits< ValueType > Limits
Definition: Coord.h:57
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:266
CoordBBox operator<<(size_t n) const
Bit-wise operations performed on both the min and max members.
Definition: Coord.h:469
bool is_divisible() const
Return true if this bounding box can be subdivided [mainly for use by TBB].
Definition: Coord.h:381
GLboolean * data
Definition: glcorearb.h:130
bool isInside(const Coord &xyz) const
Return true if point (x, y, z) is inside this bounding box.
Definition: Coord.h:390
size_t maxExtent() const
Return the index (0, 1 or 2) of the longest axis.
Definition: Coord.h:387
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
bool operator>(const Tuple< SIZE, T0 > &t0, const Tuple< SIZE, T1 > &t1)
Definition: Tuple.h:186
void expand(ValueType padding)
Pad this bounding box with the specified padding.
Definition: Coord.h:408
int floor(T x)
Definition: ImathFun.h:150
Iterator & operator++()
Increments iterator to point to the next coordinate.
Definition: Coord.h:284
GLfloat v0
Definition: glcorearb.h:815
CoordBBox & operator>>=(size_t n)
Bit-wise operations performed on both the min and max members.
Definition: Coord.h:471
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec3.h:510
CoordBBox operator>>(size_t n) const
Bit-wise operations performed on both the min and max members.
Definition: Coord.h:468
bool operator!=(const CoordBBox &rhs) const
Definition: Coord.h:355
GLint GLenum GLint x
Definition: glcorearb.h:408
GLfloat GLfloat v1
Definition: glcorearb.h:816
Vec2< T > maxComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise maximum of the two vectors.
Definition: Vec2.h:562
Vec3< typename promote< T, typename Coord::ValueType >::type > operator+(const Vec3< T > &v0, const Coord &v1)
Allow a Coord to be added to or subtracted from a Vec3.
Definition: Coord.h:501
int Floor(float x)
Return the floor of x.
Definition: Math.h:814
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
int ceil(T x)
Definition: ImathFun.h:158
bool isInside(const CoordBBox &b) const
Return true if the given bounding box is inside this bounding box.
Definition: Coord.h:396
void write(T &out, bool v)
Definition: ImfXdr.h:332
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:502
CoordBBox & operator|=(Coord::Int32 n)
Bit-wise operations performed on both the min and max members.
Definition: Coord.h:475
CoordBBox(CoordBBox &other, const tbb::split &)
Splitting constructor for use in TBB ranges.
Definition: Coord.h:323
std::ostream & operator<<(std::ostream &os, const BBox< Vec3T > &b)
Definition: BBox.h:448
bool operator<(const Tuple< SIZE, T0 > &t0, const Tuple< SIZE, T1 > &t1)
Definition: Tuple.h:174