OpenVDB: Coord.h Source File

OpenVDB 7.1.0

Coord.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 #ifndef OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED
5 #define OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED
6
7 #include <functional>// for std::hash
8 #include <algorithm> // for std::min(), std::max()
9 #include <array> // for std::array
10 #include <iostream>
11 #include <limits>
12 #include <openvdb/Platform.h>
13 #include "Math.h"
14 #include "Vec3.h"
15
16 namespace tbb { class split; } // forward declaration
17
18
19 namespace openvdb {
20 OPENVDB_USE_VERSION_NAMESPACE
21 namespace OPENVDB_VERSION_NAME {
22 namespace math {
23
25 class Coord
26 {
27 public:
28 using Int32 = int32_t;
29 using Index32 = uint32_t;
30 using Vec3i = Vec3<Int32>;
31 using Vec3I = Vec3<Index32>;
32
33 using ValueType = Int32;
34 using Limits = std::numeric_limits<ValueType>;
35
36 Coord(): mVec{{0, 0, 0}} {}
37 explicit Coord(Int32 xyz): mVec{{xyz, xyz, xyz}} {}
38 Coord(Int32 x, Int32 y, Int32 z): mVec{{x, y, z}} {}
39 explicit Coord(const Vec3i& v): mVec{{v[0], v[1], v[2]}} {}
40 explicit Coord(const Vec3I& v): mVec{{Int32(v[0]), Int32(v[1]), Int32(v[2])}} {}
41 explicit Coord(const Int32* v): mVec{{v[0], v[1], v[2]}} {}
42
44 static Coord min() { return Coord(Limits::min()); }
45
47 static Coord max() { return Coord(Limits::max()); }
48
51 template<typename T> static Coord round(const Vec3<T>& xyz)
52 {
53 return Coord(Int32(Round(xyz[0])), Int32(Round(xyz[1])), Int32(Round(xyz[2])));
54 }
57 template<typename T> static Coord floor(const Vec3<T>& xyz)
58 {
59 return Coord(Int32(Floor(xyz[0])), Int32(Floor(xyz[1])), Int32(Floor(xyz[2])));
60 }
61
64 template<typename T> static Coord ceil(const Vec3<T>& xyz)
65 {
66 return Coord(Int32(Ceil(xyz[0])), Int32(Ceil(xyz[1])), Int32(Ceil(xyz[2])));
67 }
68
70 Coord& reset(Int32 x, Int32 y, Int32 z)
71 {
72 mVec[0] = x;
73 mVec[1] = y;
74 mVec[2] = z;
75 return *this;
76 }
78 Coord& reset(Int32 xyz) { return this->reset(xyz, xyz, xyz); }
79
80 Coord& setX(Int32 x) { mVec[0] = x; return *this; }
81 Coord& setY(Int32 y) { mVec[1] = y; return *this; }
82 Coord& setZ(Int32 z) { mVec[2] = z; return *this; }
83
84 Coord& offset(Int32 dx, Int32 dy, Int32 dz)
85 {
86 mVec[0] += dx;
87 mVec[1] += dy;
88 mVec[2] += dz;
89 return *this;
90 }
91 Coord& offset(Int32 n) { return this->offset(n, n, n); }
92 Coord offsetBy(Int32 dx, Int32 dy, Int32 dz) const
93 {
94 return Coord(mVec[0] + dx, mVec[1] + dy, mVec[2] + dz);
95 }
96 Coord offsetBy(Int32 n) const { return offsetBy(n, n, n); }
97
98 Coord& operator+=(const Coord& rhs)
99 {
100 mVec[0] += rhs[0];
101 mVec[1] += rhs[1];
102 mVec[2] += rhs[2];
103 return *this;
104 }
105 Coord& operator-=(const Coord& rhs)
106 {
107 mVec[0] -= rhs[0];
108 mVec[1] -= rhs[1];
109 mVec[2] -= rhs[2];
110 return *this;
111 }
112 Coord operator+(const Coord& rhs) const
113 {
114 return Coord(mVec[0] + rhs[0], mVec[1] + rhs[1], mVec[2] + rhs[2]);
115 }
116 Coord operator-(const Coord& rhs) const
117 {
118 return Coord(mVec[0] - rhs[0], mVec[1] - rhs[1], mVec[2] - rhs[2]);
119 }
120 Coord operator-() const { return Coord(-mVec[0], -mVec[1], -mVec[2]); }
121
122 Coord operator>> (size_t n) const { return Coord(mVec[0]>>n, mVec[1]>>n, mVec[2]>>n); }
123 Coord operator<< (size_t n) const { return Coord(mVec[0]<<n, mVec[1]<<n, mVec[2]<<n); }
124 Coord& operator<<=(size_t n) { mVec[0]<<=n; mVec[1]<<=n; mVec[2]<<=n; return *this; }
125 Coord& operator>>=(size_t n) { mVec[0]>>=n; mVec[1]>>=n; mVec[2]>>=n; return *this; }
126 Coord operator& (Int32 n) const { return Coord(mVec[0] & n, mVec[1] & n, mVec[2] & n); }
127 Coord operator| (Int32 n) const { return Coord(mVec[0] | n, mVec[1] | n, mVec[2] | n); }
128 Coord& operator&= (Int32 n) { mVec[0]&=n; mVec[1]&=n; mVec[2]&=n; return *this; }
129 Coord& operator|= (Int32 n) { mVec[0]|=n; mVec[1]|=n; mVec[2]|=n; return *this; }
130
131 Int32 x() const { return mVec[0]; }
132 Int32 y() const { return mVec[1]; }
133 Int32 z() const { return mVec[2]; }
134 Int32 operator[](size_t i) const { assert(i < 3); return mVec[i]; }
135 Int32& x() { return mVec[0]; }
136 Int32& y() { return mVec[1]; }
137 Int32& z() { return mVec[2]; }
138 Int32& operator[](size_t i) { assert(i < 3); return mVec[i]; }
139
140 const Int32* data() const { return mVec.data(); }
141 Int32* data() { return mVec.data(); }
142 const Int32* asPointer() const { return mVec.data(); }
143 Int32* asPointer() { return mVec.data(); }
144 Vec3d asVec3d() const { return Vec3d(double(mVec[0]), double(mVec[1]), double(mVec[2])); }
145 Vec3s asVec3s() const { return Vec3s(float(mVec[0]), float(mVec[1]), float(mVec[2])); }
146 Vec3i asVec3i() const { return Vec3i(mVec.data()); }
147 Vec3I asVec3I() const { return Vec3I(Index32(mVec[0]), Index32(mVec[1]), Index32(mVec[2])); }
148 void asXYZ(Int32& x, Int32& y, Int32& z) const { x = mVec[0]; y = mVec[1]; z = mVec[2]; }
149
150 bool operator==(const Coord& rhs) const
151 {
152 return (mVec[0] == rhs.mVec[0] && mVec[1] == rhs.mVec[1] && mVec[2] == rhs.mVec[2]);
153 }
154 bool operator!=(const Coord& rhs) const { return !(*this == rhs); }
155
157 bool operator<(const Coord& rhs) const
158 {
159 return this->x() < rhs.x() ? true : this->x() > rhs.x() ? false
160 : this->y() < rhs.y() ? true : this->y() > rhs.y() ? false
161 : this->z() < rhs.z() ? true : false;
162 }
164 bool operator<=(const Coord& rhs) const
165 {
166 return this->x() < rhs.x() ? true : this->x() > rhs.x() ? false
167 : this->y() < rhs.y() ? true : this->y() > rhs.y() ? false
168 : this->z() <=rhs.z() ? true : false;
169 }
171 bool operator>(const Coord& rhs) const { return !(*this <= rhs); }
173 bool operator>=(const Coord& rhs) const { return !(*this < rhs); }
174
176 void minComponent(const Coord& other)
177 {
178 mVec[0] = std::min(mVec[0], other.mVec[0]);
179 mVec[1] = std::min(mVec[1], other.mVec[1]);
180 mVec[2] = std::min(mVec[2], other.mVec[2]);
181 }
182
184 void maxComponent(const Coord& other)
185 {
186 mVec[0] = std::max(mVec[0], other.mVec[0]);
187 mVec[1] = std::max(mVec[1], other.mVec[1]);
188 mVec[2] = std::max(mVec[2], other.mVec[2]);
189 }
190
192 static inline Coord minComponent(const Coord& lhs, const Coord& rhs)
193 {
194 return Coord(std::min(lhs.x(), rhs.x()),
195 std::min(lhs.y(), rhs.y()),
196 std::min(lhs.z(), rhs.z()));
197 }
198
200 static inline Coord maxComponent(const Coord& lhs, const Coord& rhs)
201 {
202 return Coord(std::max(lhs.x(), rhs.x()),
203 std::max(lhs.y(), rhs.y()),
204 std::max(lhs.z(), rhs.z()));
205 }
206
209 static inline bool lessThan(const Coord& a, const Coord& b)
210 {
211 return (a[0] < b[0] || a[1] < b[1] || a[2] < b[2]);
212 }
213
215 size_t minIndex() const { return MinIndex(mVec); }
216
218 size_t maxIndex() const { return MaxIndex(mVec); }
219
220 void read(std::istream& is) { is.read(reinterpret_cast<char*>(mVec.data()), sizeof(mVec)); }
221 void write(std::ostream& os) const
222 {
223 os.write(reinterpret_cast<const char*>(mVec.data()), sizeof(mVec));
224 }
225
230 template<int Log2N = 20>
231 size_t hash() const
232 {
233 return ((1<<Log2N)-1) & (mVec[0]*73856093 ^ mVec[1]*19349663 ^ mVec[2]*83492791);
234 }
235
236 private:
237 std::array<Int32, 3> mVec;
238 }; // class Coord
239
240
242
243
248 class CoordBBox
249 {
250 public:
251 using Index64 = uint64_t;
252 using ValueType = Coord::ValueType;
253
257 template<bool ZYXOrder>
258 class Iterator
259 {
260 public:
262 Iterator(const CoordBBox& b): mPos(b.min()), mMin(b.min()), mMax(b.max()) {}
266 Iterator& operator++() { ZYXOrder ? next<2,1,0>() : next<0,1,2>(); return *this; }
268 operator bool() const { return ZYXOrder ? (mPos[0] <= mMax[0]) : (mPos[2] <= mMax[2]); }
270 const Coord& operator*() const { return mPos; }
272 bool operator==(const Iterator& other) const
273 {
274 return ((mPos == other.mPos) && (mMin == other.mMin) && (mMax == other.mMax));
275 }
277 bool operator!=(const Iterator& other) const { return !(*this == other); }
278 private:
279 template<size_t a, size_t b, size_t c>
280 void next()
281 {
282 if (mPos[a] < mMax[a]) { ++mPos[a]; } // this is the most common case
283 else if (mPos[b] < mMax[b]) { mPos[a] = mMin[a]; ++mPos[b]; }
284 else if (mPos[c] <= mMax[c]) { mPos[a] = mMin[a]; mPos[b] = mMin[b]; ++mPos[c]; }
285 }
286 Coord mPos, mMin, mMax;
287 friend class CoordBBox; // for CoordBBox::end()
288 };// CoordBBox::Iterator
289
290 using ZYXIterator = Iterator</*ZYX=*/true>;
291 using XYZIterator = Iterator</*ZYX=*/false>;
292
294 CoordBBox(): mMin(Coord::max()), mMax(Coord::min()) {}
296 CoordBBox(const Coord& min, const Coord& max): mMin(min), mMax(max) {}
298 CoordBBox(ValueType xMin, ValueType yMin, ValueType zMin,
299 ValueType xMax, ValueType yMax, ValueType zMax)
300 : mMin(xMin, yMin, zMin), mMax(xMax, yMax, zMax)
301 {
302 }
305 CoordBBox(CoordBBox& other, const tbb::split&): mMin(other.mMin), mMax(other.mMax)
306 {
307 assert(this->is_divisible());
308 const size_t n = this->maxExtent();
309 mMax[n] = (mMin[n] + mMax[n]) >> 1;
310 other.mMin[n] = mMax[n] + 1;
311 }
312
313 static CoordBBox createCube(const Coord& min, ValueType dim)
314 {
315 return CoordBBox(min, min.offsetBy(dim - 1));
316 }
317
319 static CoordBBox inf() { return CoordBBox(Coord::min(), Coord::max()); }
320
321 const Coord& min() const { return mMin; }
322 const Coord& max() const { return mMax; }
323
324 Coord& min() { return mMin; }
325 Coord& max() { return mMax; }
326
327 void reset() { mMin = Coord::max(); mMax = Coord::min(); }
328 void reset(const Coord& min, const Coord& max) { mMin = min; mMax = max; }
329 void resetToCube(const Coord& min, ValueType dim) { mMin = min; mMax = min.offsetBy(dim - 1); }
330
333 Coord getStart() const { return mMin; }
336 Coord getEnd() const { return mMax.offsetBy(1); }
337
339 ZYXIterator begin() const { return ZYXIterator{*this}; }
341 ZYXIterator beginZYX() const { return ZYXIterator{*this}; }
343 XYZIterator beginXYZ() const { return XYZIterator{*this}; }
344
346 ZYXIterator end() const { ZYXIterator it{*this}; it.mPos[0] = mMax[0] + 1; return it; }
348 ZYXIterator endZYX() const { return end(); }
350 XYZIterator endXYZ() const { XYZIterator it{*this}; it.mPos[2] = mMax[2] + 1; return it; }
351
352 bool operator==(const CoordBBox& rhs) const { return mMin == rhs.mMin && mMax == rhs.mMax; }
353 bool operator!=(const CoordBBox& rhs) const { return !(*this == rhs); }
354
356 bool empty() const
357 {
358 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
359 #pragma GCC diagnostic push
360 #pragma GCC diagnostic ignored "-Wstrict-overflow"
361 #endif
362 return (mMin[0] > mMax[0] || mMin[1] > mMax[1] || mMin[2] > mMax[2]);
363 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
364 #pragma GCC diagnostic pop
365 #endif
366 }
369 operator bool() const { return !this->empty(); }
372 bool hasVolume() const { return !this->empty(); }
373
375 Vec3d getCenter() const { return 0.5 * Vec3d((mMin + mMax).asPointer()); }
376
380 Coord dim() const { return empty() ? Coord(0) : (mMax.offsetBy(1) - mMin); }
382 Coord extents() const { return this->dim(); }
385 Index64 volume() const
386 {
387 const Coord d = this->dim();
388 return Index64(d[0]) * Index64(d[1]) * Index64(d[2]);
389 }
391 bool is_divisible() const { return mMin[0]<mMax[0] && mMin[1]<mMax[1] && mMin[2]<mMax[2]; }
392
394 size_t minExtent() const { return this->dim().minIndex(); }
395
397 size_t maxExtent() const { return this->dim().maxIndex(); }
398
400 bool isInside(const Coord& xyz) const
401 {
402 return !(Coord::lessThan(xyz,mMin) || Coord::lessThan(mMax,xyz));
403 }
404
406 bool isInside(const CoordBBox& b) const
407 {
408 return !(Coord::lessThan(b.mMin,mMin) || Coord::lessThan(mMax,b.mMax));
409 }
410
412 bool hasOverlap(const CoordBBox& b) const
413 {
414 return !(Coord::lessThan(mMax,b.mMin) || Coord::lessThan(b.mMax,mMin));
415 }
416
418 void expand(ValueType padding)
419 {
420 mMin.offset(-padding);
421 mMax.offset( padding);
422 }
423
425 CoordBBox expandBy(ValueType padding) const
426 {
427 return CoordBBox(mMin.offsetBy(-padding),mMax.offsetBy(padding));
428 }
429
431 void expand(const Coord& xyz)
432 {
433 mMin.minComponent(xyz);
434 mMax.maxComponent(xyz);
435 }
436
438 void expand(const CoordBBox& bbox)
439 {
440 mMin.minComponent(bbox.min());
441 mMax.maxComponent(bbox.max());
442 }
444 void intersect(const CoordBBox& bbox)
445 {
446 mMin.maxComponent(bbox.min());
447 mMax.minComponent(bbox.max());
448 }
451 void expand(const Coord& min, Coord::ValueType dim)
452 {
453 mMin.minComponent(min);
454 mMax.maxComponent(min.offsetBy(dim-1));
455 }
458 void translate(const Coord& t) { mMin += t; mMax += t; }
459
461 void moveMin(const Coord& min) { mMax += min - mMin; mMin = min; }
462
464 void moveMax(const Coord& max) { mMin += max - mMax; mMax = max; }
465
470 void getCornerPoints(Coord *p) const
471 {
472 assert(p != nullptr);
473 p->reset(mMin.x(), mMin.y(), mMin.z()); ++p;
474 p->reset(mMin.x(), mMin.y(), mMax.z()); ++p;
475 p->reset(mMin.x(), mMax.y(), mMin.z()); ++p;
476 p->reset(mMin.x(), mMax.y(), mMax.z()); ++p;
477 p->reset(mMax.x(), mMin.y(), mMin.z()); ++p;
478 p->reset(mMax.x(), mMin.y(), mMax.z()); ++p;
479 p->reset(mMax.x(), mMax.y(), mMin.z()); ++p;
480 p->reset(mMax.x(), mMax.y(), mMax.z());
481 }
482
484 CoordBBox operator>> (size_t n) const { return CoordBBox(mMin>>n, mMax>>n); }
486 CoordBBox operator<< (size_t n) const { return CoordBBox(mMin<<n, mMax<<n); }
487 CoordBBox& operator<<=(size_t n) { mMin <<= n; mMax <<= n; return *this; }
488 CoordBBox& operator>>=(size_t n) { mMin >>= n; mMax >>= n; return *this; }
489 CoordBBox operator& (Coord::Int32 n) const { return CoordBBox(mMin & n, mMax & n); }
490 CoordBBox operator| (Coord::Int32 n) const { return CoordBBox(mMin | n, mMax | n); }
491 CoordBBox& operator&= (Coord::Int32 n) { mMin &= n; mMax &= n; return *this; }
492 CoordBBox& operator|= (Coord::Int32 n) { mMin |= n; mMax |= n; return *this; }
494
496 void read(std::istream& is) { mMin.read(is); mMax.read(is); }
498 void write(std::ostream& os) const { mMin.write(os); mMax.write(os); }
499
500 private:
501 Coord mMin, mMax;
502 }; // class CoordBBox
503
504
506
507
508 inline std::ostream& operator<<(std::ostream& os, const Coord& xyz)
509 {
510 os << xyz.asVec3i(); return os;
511 }
512
513
514 inline Coord
515 Abs(const Coord& xyz)
516 {
517 return Coord(Abs(xyz[0]), Abs(xyz[1]), Abs(xyz[2]));
518 }
519
520
522 template<typename T>
524 inline Vec3<typename promote<T, typename Coord::ValueType>::type>
525 operator+(const Vec3<T>& v0, const Coord& v1)
526 {
527 Vec3<typename promote<T, typename Coord::ValueType>::type> result(v0);
528 result[0] += v1[0];
529 result[1] += v1[1];
530 result[2] += v1[2];
531 return result;
532 }
533
534 template<typename T>
535 inline Vec3<typename promote<T, typename Coord::ValueType>::type>
536 operator+(const Coord& v1, const Vec3<T>& v0)
537 {
538 Vec3<typename promote<T, typename Coord::ValueType>::type> result(v0);
539 result[0] += v1[0];
540 result[1] += v1[1];
541 result[2] += v1[2];
542 return result;
543 }
545
546
548 template <typename T>
550 inline Vec3<typename promote<T, Coord::ValueType>::type>
551 operator-(const Vec3<T>& v0, const Coord& v1)
552 {
553 Vec3<typename promote<T, Coord::ValueType>::type> result(v0);
554 result[0] -= v1[0];
555 result[1] -= v1[1];
556 result[2] -= v1[2];
557 return result;
558 }
559
560 template <typename T>
561 inline Vec3<typename promote<T, Coord::ValueType>::type>
562 operator-(const Coord& v1, const Vec3<T>& v0)
563 {
564 Vec3<typename promote<T, Coord::ValueType>::type> result(v0);
565 result[0] -= v1[0];
566 result[1] -= v1[1];
567 result[2] -= v1[2];
568 return -result;
569 }
571
572 inline std::ostream&
573 operator<<(std::ostream& os, const CoordBBox& b)
574 {
575 os << b.min() << " -> " << b.max();
576 return os;
577 }
578
579 } // namespace math
580 } // namespace OPENVDB_VERSION_NAME
581 } // namespace openvdb
582
584
585 // template specialization of std::hash with Coord, which
586 // allows for Coord to be used as the key in std::unordered_map
587 namespace std {// injected in namespace std
588
589 template<>
590 struct hash<openvdb::math::Coord>
591 {
592 using Coord = openvdb::math::Coord;
593 using argument_type = Coord;
594 using result_type = std::size_t;
595 std::size_t operator()(const Coord& ijk) const noexcept { return ijk.Coord::hash<>(); }
596 };// std::hash<openvdb::math::Coord>
597
598 }// namespace std
599
600 #endif // OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED
openvdb::v7_1::math::Vec3
Definition: Mat.h:170
openvdb::v7_1::math::CoordBBox::reset
void reset(const Coord &min, const Coord &max)
Definition: Coord.h:328
openvdb::v7_1::math::CoordBBox::min
Coord & min()
Definition: Coord.h:324
openvdb::v7_1::math::Coord::data
const Int32 * data() const
Definition: Coord.h:140
openvdb::v7_1::math::CoordBBox::max
Coord & max()
Definition: Coord.h:325
std::hash< openvdb::math::Coord >::argument_type
Coord argument_type
Definition: Coord.h:593
openvdb::v7_1::math::CoordBBox::expandBy
CoordBBox expandBy(ValueType padding) const
Return a new instance that is expanded by the specified padding.
Definition: Coord.h:425
openvdb::v7_1::math::CoordBBox::CoordBBox
CoordBBox(CoordBBox &other, const tbb::split &)
Splitting constructor for use in TBB ranges.
Definition: Coord.h:305
openvdb::v7_1::math::Coord::Int32
int32_t Int32
Definition: Coord.h:28
openvdb::v7_1::math::Coord::hash
size_t hash() const
Return a hash value for this coordinate.
Definition: Coord.h:231
openvdb::v7_1::math::Coord::setY
Coord & setY(Int32 y)
Definition: Coord.h:81
openvdb::v7_1::math::Coord::read
void read(std::istream &is)
Definition: Coord.h:220
openvdb::v7_1::math::CoordBBox::getStart
Coord getStart() const
Return the minimum coordinate.
Definition: Coord.h:333
openvdb::v7_1::math::CoordBBox::extents
Coord extents() const
Definition: Coord.h:382
openvdb::v7_1::math::Coord::floor
static Coord floor(const Vec3< T > &xyz)
Return the largest integer coordinates that are not greater than xyz (node centered conversion).
Definition: Coord.h:57
openvdb::v7_1::math::Coord::lessThan
static bool lessThan(const Coord &a, const Coord &b)
Definition: Coord.h:209
openvdb::v7_1::math::CoordBBox::getCornerPoints
void getCornerPoints(Coord *p) const
Populates an array with the eight corner points of this bounding box.
Definition: Coord.h:470
std::hash< openvdb::math::Coord >::Coord
openvdb::math::Coord Coord
Definition: Coord.h:592
openvdb::v7_1::math::Coord::operator>>=
Coord & operator>>=(size_t n)
Definition: Coord.h:125
openvdb::v7_1::math::Coord::ValueType
Int32 ValueType
Definition: Coord.h:33
openvdb::v7_1::math::Coord::operator!=
bool operator!=(const Coord &rhs) const
Definition: Coord.h:154
openvdb::v7_1::math::CoordBBox::operator>>=
CoordBBox & operator>>=(size_t n)
Definition: Coord.h:488
openvdb::v7_1::math::Coord::operator<
bool operator<(const Coord &rhs) const
Lexicographic less than.
Definition: Coord.h:157
openvdb::v7_1::math::Coord::operator-
Coord operator-(const Coord &rhs) const
Definition: Coord.h:116
openvdb::v7_1::math::Coord::asVec3i
Vec3i asVec3i() const
Definition: Coord.h:146
openvdb::v7_1::math::CoordBBox::reset
void reset()
Definition: Coord.h:327
openvdb::v7_1::math::Coord::operator<<=
Coord & operator<<=(size_t n)
Definition: Coord.h:124
openvdb::v7_1::math::Coord::operator<=
bool operator<=(const Coord &rhs) const
Lexicographic less than or equal to.
Definition: Coord.h:164
openvdb::v7_1::math::Coord::maxComponent
void maxComponent(const Coord &other)
Perform a component-wise maximum with the other Coord.
Definition: Coord.h:184
openvdb::v7_1::math::CoordBBox::createCube
static CoordBBox createCube(const Coord &min, ValueType dim)
Definition: Coord.h:313
openvdb::v7_1::math::operator+
Vec3< typename promote< T, typename Coord::ValueType >::type > operator+(const Coord &v1, const Vec3< T > &v0)
Definition: Coord.h:536
openvdb::v7_1::math::CoordBBox::expand
void expand(const Coord &xyz)
Expand this bounding box to enclose point (x, y, z).
Definition: Coord.h:431
tbb
Definition: Coord.h:16
openvdb::v7_1::math::Coord::setZ
Coord & setZ(Int32 z)
Definition: Coord.h:82
openvdb::v7_1::math::Floor
int Floor(float x)
Return the floor of x.
Definition: Math.h:815
openvdb::v7_1::math::Coord::round
static Coord round(const Vec3< T > &xyz)
Return xyz rounded to the closest integer coordinates (cell centered conversion).
Definition: Coord.h:51
openvdb::v7_1::math::Coord::operator-
Coord operator-() const
Definition: Coord.h:120
openvdb::v7_1::tools::composite::min
const std::enable_if<!VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:102
openvdb::v7_1::math::CoordBBox::empty
bool empty() const
Return true if this bounding box is empty (i.e., encloses no coordinates).
Definition: Coord.h:356
openvdb::v7_1::math::Coord::x
Int32 & x()
Definition: Coord.h:135
openvdb::v7_1::math::Coord::minIndex
size_t minIndex() const
Return the index (0, 1 or 2) with the smallest value.
Definition: Coord.h:215
openvdb::v7_1::math::Coord::operator>
bool operator>(const Coord &rhs) const
Lexicographic greater than.
Definition: Coord.h:171
openvdb::v7_1::math::Coord::y
Int32 y() const
Definition: Coord.h:132
openvdb::v7_1::math::Ceil
int Ceil(float x)
Return the ceiling of x.
Definition: Math.h:823
openvdb::v7_1::math::CoordBBox::translate
void translate(const Coord &t)
Translate this bounding box by (tx, ty, tz).
Definition: Coord.h:458
openvdb::v7_1::math::Vec3i
Vec3< int32_t > Vec3i
Definition: Vec3.h:659
openvdb::v7_1::math::CoordBBox::operator!=
bool operator!=(const CoordBBox &rhs) const
Definition: Coord.h:353
openvdb::v7_1::math::operator-
Vec3< typename promote< T, Coord::ValueType >::type > operator-(const Coord &v1, const Vec3< T > &v0)
Definition: Coord.h:562
openvdb::v7_1::math::Coord::Coord
Coord(const Vec3i &v)
Definition: Coord.h:39
openvdb::v7_1::math::Coord::offsetBy
Coord offsetBy(Int32 n) const
Definition: Coord.h:96
openvdb::v7_1::math::MinIndex
size_t MinIndex(const Vec3T &v)
Return the index [0,1,2] of the smallest value in a 3D vector.
Definition: Math.h:903
openvdb::v7_1::math::Abs
Coord Abs(const Coord &xyz)
Definition: Coord.h:515
openvdb::v7_1::math::Coord::data
Int32 * data()
Definition: Coord.h:141
openvdb::v7_1::Index64
uint64_t Index64
Definition: Types.h:30
openvdb::v7_1::math::Coord::x
Int32 x() const
Definition: Coord.h:131
openvdb::v7_1::math::Coord::offsetBy
Coord offsetBy(Int32 dx, Int32 dy, Int32 dz) const
Definition: Coord.h:92
Platform.h
openvdb::v7_1::math::CoordBBox::getEnd
Coord getEnd() const
Return the maximum coordinate plus one.
Definition: Coord.h:336
openvdb::v7_1::math::CoordBBox::moveMin
void moveMin(const Coord &min)
Move this bounding box to the specified min.
Definition: Coord.h:461
openvdb::v7_1::Vec3I
math::Vec3< Index32 > Vec3I
Definition: Types.h:50
openvdb::v7_1::math::Coord::Limits
std::numeric_limits< ValueType > Limits
Definition: Coord.h:34
openvdb::v7_1::math::CoordBBox::Iterator::operator==
bool operator==(const Iterator &other) const
Return true if this iterator and the given iterator point to the same coordinate.
Definition: Coord.h:272
openvdb::v7_1::math::CoordBBox::Iterator::operator!=
bool operator!=(const Iterator &other) const
Return true if this iterator and the given iterator point to different coordinates.
Definition: Coord.h:277
openvdb::v7_1::math::CoordBBox
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:249
openvdb::v7_1::math::CoordBBox::maxExtent
size_t maxExtent() const
Return the index (0, 1 or 2) of the longest axis.
Definition: Coord.h:397
openvdb::v7_1::math::Coord::Coord
Coord()
Definition: Coord.h:36
Vec3.h
openvdb::v7_1::Index32
uint32_t Index32
Definition: Types.h:29
openvdb::v7_1::math::CoordBBox::Iterator::operator*
const Coord & operator*() const
Return a const reference to the coordinate currently pointed to.
Definition: Coord.h:270
openvdb::v7_1::math::CoordBBox::CoordBBox
CoordBBox(ValueType xMin, ValueType yMin, ValueType zMin, ValueType xMax, ValueType yMax, ValueType zMax)
Construct from individual components of the min and max bounds.
Definition: Coord.h:298
openvdb::v7_1::math::CoordBBox::beginZYX
ZYXIterator beginZYX() const
Return a ZYX-order iterator that points to the minimum coordinate.
Definition: Coord.h:341
openvdb::v7_1::math::CoordBBox::resetToCube
void resetToCube(const Coord &min, ValueType dim)
Definition: Coord.h:329
openvdb::v7_1::math::Coord::asVec3I
Vec3I asVec3I() const
Definition: Coord.h:147
openvdb::v7_1::math::CoordBBox::end
ZYXIterator end() const
Return a ZYX-order iterator that points past the maximum coordinate.
Definition: Coord.h:346
Math.h
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
openvdb::v7_1::math::CoordBBox::CoordBBox
CoordBBox()
The default constructor produces an empty bounding box.
Definition: Coord.h:294
openvdb::v7_1::math::CoordBBox::CoordBBox
CoordBBox(const Coord &min, const Coord &max)
Construct a bounding box with the given min and max bounds.
Definition: Coord.h:296
openvdb::v7_1::Int32
int32_t Int32
Definition: Types.h:33
openvdb::v7_1::math::Coord::asPointer
const Int32 * asPointer() const
Definition: Coord.h:142
std::hash< openvdb::math::Coord >::result_type
std::size_t result_type
Definition: Coord.h:594
openvdb::v7_1::math::CoordBBox::isInside
bool isInside(const CoordBBox &b) const
Return true if the given bounding box is inside this bounding box.
Definition: Coord.h:406
openvdb::v7_1::math::Coord::asVec3d
Vec3d asVec3d() const
Definition: Coord.h:144
openvdb::v7_1::math::CoordBBox::expand
void expand(const CoordBBox &bbox)
Union this bounding box with the given bounding box.
Definition: Coord.h:438
openvdb::v7_1::math::CoordBBox::moveMax
void moveMax(const Coord &max)
Move this bounding box to the specified max.
Definition: Coord.h:464
openvdb::v7_1::math::Round
float Round(float x)
Return x rounded to the nearest integer.
Definition: Math.h:786
openvdb::v7_1::math::Coord::reset
Coord & reset(Int32 x, Int32 y, Int32 z)
Reset all three coordinates with the specified arguments.
Definition: Coord.h:70
openvdb::v7_1::math::Vec3s
Vec3< float > Vec3s
Definition: Vec3.h:661
openvdb::v7_1::math::CoordBBox::volume
Index64 volume() const
Return the integer volume of coordinates spanned by this bounding box.
Definition: Coord.h:385
openvdb::v7_1::math::Coord::max
static Coord max()
Return the largest possible coordinate.
Definition: Coord.h:47
openvdb::v7_1::math::CoordBBox::write
void write(std::ostream &os) const
Serialize this bounding box to the given stream.
Definition: Coord.h:498
openvdb::v7_1::math::CoordBBox::endXYZ
XYZIterator endXYZ() const
Return an XYZ-order iterator that points past the maximum coordinate.
Definition: Coord.h:350
openvdb::v7_1::math::Coord
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:26
openvdb::v7_1::math::Coord::z
Int32 z() const
Definition: Coord.h:133
openvdb::v7_1::math::Vec3d
Vec3< double > Vec3d
Definition: Vec3.h:662
openvdb::v7_1::math::Coord::reset
Coord & reset(Int32 xyz)
Reset all three coordinates with the same specified argument.
Definition: Coord.h:78
openvdb::v7_1::math::CoordBBox::is_divisible
bool is_divisible() const
Return true if this bounding box can be subdivided [mainly for use by TBB].
Definition: Coord.h:391
openvdb::v7_1::math::Coord::operator+
Coord operator+(const Coord &rhs) const
Definition: Coord.h:112
std::hash< openvdb::math::Coord >::operator()
std::size_t operator()(const Coord &ijk) const noexcept
Definition: Coord.h:595
openvdb::v7_1::math::Coord::ceil
static Coord ceil(const Vec3< T > &xyz)
Return the largest integer coordinates that are not greater than xyz+1 (node centered conversion).
Definition: Coord.h:64
openvdb::v7_1::math::Coord::Coord
Coord(Int32 x, Int32 y, Int32 z)
Definition: Coord.h:38
openvdb::v7_1::math::CoordBBox::beginXYZ
XYZIterator beginXYZ() const
Return an XYZ-order iterator that points to the minimum coordinate.
Definition: Coord.h:343
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:146
openvdb::v7_1::math::MaxIndex
size_t MaxIndex(const Vec3T &v)
Return the index [0,1,2] of the largest value in a 3D vector.
Definition: Math.h:921
openvdb::v7_1::math::Coord::min
static Coord min()
Return the smallest possible coordinate.
Definition: Coord.h:44
openvdb::v7_1::math::CoordBBox::operator==
bool operator==(const CoordBBox &rhs) const
Definition: Coord.h:352
openvdb::v7_1::math::CoordBBox::Index64
uint64_t Index64
Definition: Coord.h:251
openvdb::v7_1::math::operator<<
std::ostream & operator<<(std::ostream &os, const CoordBBox &b)
Definition: Coord.h:573
openvdb::v7_1::math::Coord::operator-=
Coord & operator-=(const Coord &rhs)
Definition: Coord.h:105
openvdb::v7_1::math::Coord::y
Int32 & y()
Definition: Coord.h:136
openvdb::v7_1::math::CoordBBox::hasVolume
bool hasVolume() const
Return true if this bounding box is nonempty (i.e., encloses at least one coordinate).
Definition: Coord.h:372
openvdb::v7_1::math::Coord::offset
Coord & offset(Int32 n)
Definition: Coord.h:91
openvdb::v7_1::math::CoordBBox::Iterator::operator++
Iterator & operator++()
Increment the iterator to point to the next coordinate.
Definition: Coord.h:266
openvdb::v7_1::math::CoordBBox::operator<<=
CoordBBox & operator<<=(size_t n)
Definition: Coord.h:487
openvdb::v7_1::math::Coord::setX
Coord & setX(Int32 x)
Definition: Coord.h:80
openvdb::v7_1::math::Coord::operator[]
Int32 & operator[](size_t i)
Definition: Coord.h:138
openvdb::v7_1::math::Coord::maxComponent
static Coord maxComponent(const Coord &lhs, const Coord &rhs)
Return the component-wise maximum of the two Coords.
Definition: Coord.h:200
openvdb::v7_1::math::CoordBBox::dim
Coord dim() const
Return the dimensions of the coordinates spanned by this bounding box.
Definition: Coord.h:380
openvdb::v7_1::math::CoordBBox::ValueType
Coord::ValueType ValueType
Definition: Coord.h:252
openvdb::v7_1::math::CoordBBox::begin
ZYXIterator begin() const
Return a ZYX-order iterator that points to the minimum coordinate.
Definition: Coord.h:339
openvdb::v7_1::math::CoordBBox::minExtent
size_t minExtent() const
Return the index (0, 1 or 2) of the shortest axis.
Definition: Coord.h:394
openvdb::v7_1::math::Coord::write
void write(std::ostream &os) const
Definition: Coord.h:221
std
Definition: Coord.h:587
openvdb::v7_1::math::CoordBBox::max
const Coord & max() const
Definition: Coord.h:322
openvdb::v7_1::math::CoordBBox::hasOverlap
bool hasOverlap(const CoordBBox &b) const
Return true if the given bounding box overlaps with this bounding box.
Definition: Coord.h:412
openvdb::v7_1::math::CoordBBox::endZYX
ZYXIterator endZYX() const
Return a ZYX-order iterator that points past the maximum coordinate.
Definition: Coord.h:348
openvdb::v7_1::math::CoordBBox::min
const Coord & min() const
Definition: Coord.h:321
openvdb::v7_1::math::Coord::operator[]
Int32 operator[](size_t i) const
Definition: Coord.h:134
openvdb::v7_1::math::Coord::z
Int32 & z()
Definition: Coord.h:137
openvdb::v7_1::math::CoordBBox::getCenter
Vec3d getCenter() const
Return the floating-point position of the center of this bounding box.
Definition: Coord.h:375
openvdb::v7_1::math::Coord::Coord
Coord(const Int32 *v)
Definition: Coord.h:41
openvdb::v7_1::math::CoordBBox::Iterator::Iterator
Iterator(const CoordBBox &b)
C-tor from a bounding box.
Definition: Coord.h:262
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:94
openvdb::v7_1::math::CoordBBox::expand
void expand(ValueType padding)
Pad this bounding box with the specified padding.
Definition: Coord.h:418
openvdb::v7_1::math::Coord::operator==
bool operator==(const Coord &rhs) const
Definition: Coord.h:150
openvdb::v7_1::math::Coord::offset
Coord & offset(Int32 dx, Int32 dy, Int32 dz)
Definition: Coord.h:84
openvdb::v7_1::math::Coord::Coord
Coord(const Vec3I &v)
Definition: Coord.h:40
openvdb::v7_1::math::Coord::operator+=
Coord & operator+=(const Coord &rhs)
Definition: Coord.h:98
openvdb::v7_1::math::CoordBBox::expand
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:451
openvdb::v7_1::math::Coord::maxIndex
size_t maxIndex() const
Return the index (0, 1 or 2) with the largest value.
Definition: Coord.h:218
openvdb::v7_1::math::Coord::asVec3s
Vec3s asVec3s() const
Definition: Coord.h:145
openvdb::v7_1::math::Coord::Index32
uint32_t Index32
Definition: Coord.h:29
openvdb
Definition: Exceptions.h:13
openvdb::v7_1::math::Coord::operator>=
bool operator>=(const Coord &rhs) const
Lexicographic greater than or equal to.
Definition: Coord.h:173
openvdb::v7_1::math::Coord::asXYZ
void asXYZ(Int32 &x, Int32 &y, Int32 &z) const
Definition: Coord.h:148
openvdb::v7_1::math::Coord::minComponent
void minComponent(const Coord &other)
Perform a component-wise minimum with the other Coord.
Definition: Coord.h:176
openvdb::v7_1::math::CoordBBox::inf
static CoordBBox inf()
Return an "infinite" bounding box, as defined by the Coord value range.
Definition: Coord.h:319
openvdb::v7_1::math::Coord::Coord
Coord(Int32 xyz)
Definition: Coord.h:37
openvdb::v7_1::math::CoordBBox::read
void read(std::istream &is)
Unserialize this bounding box from the given stream.
Definition: Coord.h:496
openvdb::v7_1::math::CoordBBox::Iterator
Iterator over the Coord domain covered by a CoordBBox.
Definition: Coord.h:259
openvdb::v7_1::math::Coord::asPointer
Int32 * asPointer()
Definition: Coord.h:143
openvdb::v7_1::math::Coord::minComponent
static Coord minComponent(const Coord &lhs, const Coord &rhs)
Return the component-wise minimum of the two Coords.
Definition: Coord.h:192
openvdb::v7_1::math::CoordBBox::intersect
void intersect(const CoordBBox &bbox)
Intersect this bounding box with the given bounding box.
Definition: Coord.h:444
openvdb::v7_1::tools::composite::max
const std::enable_if<!VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:106
openvdb::v7_1::math::CoordBBox::isInside
bool isInside(const Coord &xyz) const
Return true if point (x, y, z) is inside this bounding box.
Definition: Coord.h:400