OpenVDB: Coord.h Source File

OpenVDB 6.1.0

Coord.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2019 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 //
30
31 #ifndef OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED
32 #define OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED
33
34 #include <functional>// for std::hash
35 #include <algorithm> // for std::min(), std::max()
36 #include <array> // for std::array
37 #include <iostream>
38 #include <limits>
39 #include <openvdb/Platform.h>
40 #include "Math.h"
41 #include "Vec3.h"
42
43 namespace tbb { class split; } // forward declaration
44
45
46 namespace openvdb {
47 OPENVDB_USE_VERSION_NAMESPACE
48 namespace OPENVDB_VERSION_NAME {
49 namespace math {
50
52 class Coord
53 {
54 public:
55 using Int32 = int32_t;
56 using Index32 = uint32_t;
57 using Vec3i = Vec3<Int32>;
58 using Vec3I = Vec3<Index32>;
59
60 using ValueType = Int32;
61 using Limits = std::numeric_limits<ValueType>;
62
63 Coord(): mVec{{0, 0, 0}} {}
64 explicit Coord(Int32 xyz): mVec{{xyz, xyz, xyz}} {}
65 Coord(Int32 x, Int32 y, Int32 z): mVec{{x, y, z}} {}
66 explicit Coord(const Vec3i& v): mVec{{v[0], v[1], v[2]}} {}
67 explicit Coord(const Vec3I& v): mVec{{Int32(v[0]), Int32(v[1]), Int32(v[2])}} {}
68 explicit Coord(const Int32* v): mVec{{v[0], v[1], v[2]}} {}
69
71 static Coord min() { return Coord(Limits::min()); }
72
74 static Coord max() { return Coord(Limits::max()); }
75
78 template<typename T> static Coord round(const Vec3<T>& xyz)
79 {
80 return Coord(Int32(Round(xyz[0])), Int32(Round(xyz[1])), Int32(Round(xyz[2])));
81 }
84 template<typename T> static Coord floor(const Vec3<T>& xyz)
85 {
86 return Coord(Int32(Floor(xyz[0])), Int32(Floor(xyz[1])), Int32(Floor(xyz[2])));
87 }
88
91 template<typename T> static Coord ceil(const Vec3<T>& xyz)
92 {
93 return Coord(Int32(Ceil(xyz[0])), Int32(Ceil(xyz[1])), Int32(Ceil(xyz[2])));
94 }
95
97 Coord& reset(Int32 x, Int32 y, Int32 z)
98 {
99 mVec[0] = x;
100 mVec[1] = y;
101 mVec[2] = z;
102 return *this;
103 }
105 Coord& reset(Int32 xyz) { return this->reset(xyz, xyz, xyz); }
106
107 Coord& setX(Int32 x) { mVec[0] = x; return *this; }
108 Coord& setY(Int32 y) { mVec[1] = y; return *this; }
109 Coord& setZ(Int32 z) { mVec[2] = z; return *this; }
110
111 Coord& offset(Int32 dx, Int32 dy, Int32 dz)
112 {
113 mVec[0] += dx;
114 mVec[1] += dy;
115 mVec[2] += dz;
116 return *this;
117 }
118 Coord& offset(Int32 n) { return this->offset(n, n, n); }
119 Coord offsetBy(Int32 dx, Int32 dy, Int32 dz) const
120 {
121 return Coord(mVec[0] + dx, mVec[1] + dy, mVec[2] + dz);
122 }
123 Coord offsetBy(Int32 n) const { return offsetBy(n, n, n); }
124
125 Coord& operator+=(const Coord& rhs)
126 {
127 mVec[0] += rhs[0];
128 mVec[1] += rhs[1];
129 mVec[2] += rhs[2];
130 return *this;
131 }
132 Coord& operator-=(const Coord& rhs)
133 {
134 mVec[0] -= rhs[0];
135 mVec[1] -= rhs[1];
136 mVec[2] -= rhs[2];
137 return *this;
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 Coord& rhs) const
144 {
145 return Coord(mVec[0] - rhs[0], mVec[1] - rhs[1], mVec[2] - rhs[2]);
146 }
147 Coord operator-() const { return Coord(-mVec[0], -mVec[1], -mVec[2]); }
148
149 Coord operator>> (size_t n) const { return Coord(mVec[0]>>n, mVec[1]>>n, mVec[2]>>n); }
150 Coord operator<< (size_t n) const { return Coord(mVec[0]<<n, mVec[1]<<n, mVec[2]<<n); }
151 Coord& operator<<=(size_t n) { mVec[0]<<=n; mVec[1]<<=n; mVec[2]<<=n; return *this; }
152 Coord& operator>>=(size_t n) { mVec[0]>>=n; mVec[1]>>=n; mVec[2]>>=n; return *this; }
153 Coord operator& (Int32 n) const { return Coord(mVec[0] & n, mVec[1] & n, mVec[2] & n); }
154 Coord operator| (Int32 n) const { return Coord(mVec[0] | n, mVec[1] | n, mVec[2] | n); }
155 Coord& operator&= (Int32 n) { mVec[0]&=n; mVec[1]&=n; mVec[2]&=n; return *this; }
156 Coord& operator|= (Int32 n) { mVec[0]|=n; mVec[1]|=n; mVec[2]|=n; return *this; }
157
158 Int32 x() const { return mVec[0]; }
159 Int32 y() const { return mVec[1]; }
160 Int32 z() const { return mVec[2]; }
161 Int32 operator[](size_t i) const { assert(i < 3); return mVec[i]; }
162 Int32& x() { return mVec[0]; }
163 Int32& y() { return mVec[1]; }
164 Int32& z() { return mVec[2]; }
165 Int32& operator[](size_t i) { assert(i < 3); return mVec[i]; }
166
167 const Int32* data() const { return mVec.data(); }
168 Int32* data() { return mVec.data(); }
169 const Int32* asPointer() const { return mVec.data(); }
170 Int32* asPointer() { return mVec.data(); }
171 Vec3d asVec3d() const { return Vec3d(double(mVec[0]), double(mVec[1]), double(mVec[2])); }
172 Vec3s asVec3s() const { return Vec3s(float(mVec[0]), float(mVec[1]), float(mVec[2])); }
173 Vec3i asVec3i() const { return Vec3i(mVec.data()); }
174 Vec3I asVec3I() const { return Vec3I(Index32(mVec[0]), Index32(mVec[1]), Index32(mVec[2])); }
175 void asXYZ(Int32& x, Int32& y, Int32& z) const { x = mVec[0]; y = mVec[1]; z = mVec[2]; }
176
177 bool operator==(const Coord& rhs) const
178 {
179 return (mVec[0] == rhs.mVec[0] && mVec[1] == rhs.mVec[1] && mVec[2] == rhs.mVec[2]);
180 }
181 bool operator!=(const Coord& rhs) const { return !(*this == rhs); }
182
184 bool operator<(const Coord& rhs) const
185 {
186 return this->x() < rhs.x() ? true : this->x() > rhs.x() ? false
187 : this->y() < rhs.y() ? true : this->y() > rhs.y() ? false
188 : this->z() < rhs.z() ? true : false;
189 }
191 bool operator<=(const Coord& rhs) const
192 {
193 return this->x() < rhs.x() ? true : this->x() > rhs.x() ? false
194 : this->y() < rhs.y() ? true : this->y() > rhs.y() ? false
195 : this->z() <=rhs.z() ? true : false;
196 }
198 bool operator>(const Coord& rhs) const { return !(*this <= rhs); }
200 bool operator>=(const Coord& rhs) const { return !(*this < rhs); }
201
203 void minComponent(const Coord& other)
204 {
205 mVec[0] = std::min(mVec[0], other.mVec[0]);
206 mVec[1] = std::min(mVec[1], other.mVec[1]);
207 mVec[2] = std::min(mVec[2], other.mVec[2]);
208 }
209
211 void maxComponent(const Coord& other)
212 {
213 mVec[0] = std::max(mVec[0], other.mVec[0]);
214 mVec[1] = std::max(mVec[1], other.mVec[1]);
215 mVec[2] = std::max(mVec[2], other.mVec[2]);
216 }
217
219 static inline Coord minComponent(const Coord& lhs, const Coord& rhs)
220 {
221 return Coord(std::min(lhs.x(), rhs.x()),
222 std::min(lhs.y(), rhs.y()),
223 std::min(lhs.z(), rhs.z()));
224 }
225
227 static inline Coord maxComponent(const Coord& lhs, const Coord& rhs)
228 {
229 return Coord(std::max(lhs.x(), rhs.x()),
230 std::max(lhs.y(), rhs.y()),
231 std::max(lhs.z(), rhs.z()));
232 }
233
236 static inline bool lessThan(const Coord& a, const Coord& b)
237 {
238 return (a[0] < b[0] || a[1] < b[1] || a[2] < b[2]);
239 }
240
242 size_t minIndex() const { return MinIndex(mVec); }
243
245 size_t maxIndex() const { return MaxIndex(mVec); }
246
247 void read(std::istream& is) { is.read(reinterpret_cast<char*>(mVec.data()), sizeof(mVec)); }
248 void write(std::ostream& os) const
249 {
250 os.write(reinterpret_cast<const char*>(mVec.data()), sizeof(mVec));
251 }
252
256 template <int Log2N = 20>
257 inline size_t hash() const { return ( (1<<Log2N)-1 ) & (mVec[0]*73856093 ^ mVec[1]*19349663 ^ mVec[2]*83492791); }
258
259 private:
260 std::array<Int32, 3> mVec;
261 }; // class Coord
262
263
265
266
271 class CoordBBox
272 {
273 public:
274 using Index64 = uint64_t;
275 using ValueType = Coord::ValueType;
276
280 template<bool ZYXOrder>
281 class Iterator
282 {
283 public:
285 Iterator(const CoordBBox& b): mPos(b.min()), mMin(b.min()), mMax(b.max()) {}
289 Iterator& operator++() { ZYXOrder ? next<2,1,0>() : next<0,1,2>(); return *this; }
291 operator bool() const { return ZYXOrder ? (mPos[0] <= mMax[0]) : (mPos[2] <= mMax[2]); }
293 const Coord& operator*() const { return mPos; }
295 bool operator==(const Iterator& other) const
296 {
297 return ((mPos == other.mPos) && (mMin == other.mMin) && (mMax == other.mMax));
298 }
300 bool operator!=(const Iterator& other) const { return !(*this == other); }
301 private:
302 template<size_t a, size_t b, size_t c>
303 void next()
304 {
305 if (mPos[a] < mMax[a]) { ++mPos[a]; } // this is the most common case
306 else if (mPos[b] < mMax[b]) { mPos[a] = mMin[a]; ++mPos[b]; }
307 else if (mPos[c] <= mMax[c]) { mPos[a] = mMin[a]; mPos[b] = mMin[b]; ++mPos[c]; }
308 }
309 Coord mPos, mMin, mMax;
310 friend class CoordBBox; // for CoordBBox::end()
311 };// CoordBBox::Iterator
312
313 using ZYXIterator = Iterator</*ZYX=*/true>;
314 using XYZIterator = Iterator</*ZYX=*/false>;
315
317 CoordBBox(): mMin(Coord::max()), mMax(Coord::min()) {}
319 CoordBBox(const Coord& min, const Coord& max): mMin(min), mMax(max) {}
321 CoordBBox(ValueType xMin, ValueType yMin, ValueType zMin,
322 ValueType xMax, ValueType yMax, ValueType zMax)
323 : mMin(xMin, yMin, zMin), mMax(xMax, yMax, zMax)
324 {
325 }
328 CoordBBox(CoordBBox& other, const tbb::split&): mMin(other.mMin), mMax(other.mMax)
329 {
330 assert(this->is_divisible());
331 const size_t n = this->maxExtent();
332 mMax[n] = (mMin[n] + mMax[n]) >> 1;
333 other.mMin[n] = mMax[n] + 1;
334 }
335
336 static CoordBBox createCube(const Coord& min, ValueType dim)
337 {
338 return CoordBBox(min, min.offsetBy(dim - 1));
339 }
340
342 static CoordBBox inf() { return CoordBBox(Coord::min(), Coord::max()); }
343
344 const Coord& min() const { return mMin; }
345 const Coord& max() const { return mMax; }
346
347 Coord& min() { return mMin; }
348 Coord& max() { return mMax; }
349
350 void reset() { mMin = Coord::max(); mMax = Coord::min(); }
351 void reset(const Coord& min, const Coord& max) { mMin = min; mMax = max; }
352 void resetToCube(const Coord& min, ValueType dim) { mMin = min; mMax = min.offsetBy(dim - 1); }
353
356 Coord getStart() const { return mMin; }
359 Coord getEnd() const { return mMax.offsetBy(1); }
360
362 ZYXIterator begin() const { return ZYXIterator{*this}; }
364 ZYXIterator beginZYX() const { return ZYXIterator{*this}; }
366 XYZIterator beginXYZ() const { return XYZIterator{*this}; }
367
369 ZYXIterator end() const { ZYXIterator it{*this}; it.mPos[0] = mMax[0] + 1; return it; }
371 ZYXIterator endZYX() const { return end(); }
373 XYZIterator endXYZ() const { XYZIterator it{*this}; it.mPos[2] = mMax[2] + 1; return it; }
374
375 bool operator==(const CoordBBox& rhs) const { return mMin == rhs.mMin && mMax == rhs.mMax; }
376 bool operator!=(const CoordBBox& rhs) const { return !(*this == rhs); }
377
379 bool empty() const
380 {
381 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
382 #pragma GCC diagnostic push
383 #pragma GCC diagnostic ignored "-Wstrict-overflow"
384 #endif
385 return (mMin[0] > mMax[0] || mMin[1] > mMax[1] || mMin[2] > mMax[2]);
386 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
387 #pragma GCC diagnostic pop
388 #endif
389 }
391 operator bool() const { return !this->empty(); }
393 bool hasVolume() const { return !this->empty(); }
394
396 Vec3d getCenter() const { return 0.5 * Vec3d((mMin + mMax).asPointer()); }
397
401 Coord dim() const { return mMax.offsetBy(1) - mMin; }
403 Coord extents() const { return this->dim(); }
406 Index64 volume() const
407 {
408 const Coord d = this->dim();
409 return Index64(d[0]) * Index64(d[1]) * Index64(d[2]);
410 }
412 bool is_divisible() const { return mMin[0]<mMax[0] && mMin[1]<mMax[1] && mMin[2]<mMax[2]; }
413
415 size_t minExtent() const { return this->dim().minIndex(); }
416
418 size_t maxExtent() const { return this->dim().maxIndex(); }
419
421 bool isInside(const Coord& xyz) const
422 {
423 return !(Coord::lessThan(xyz,mMin) || Coord::lessThan(mMax,xyz));
424 }
425
427 bool isInside(const CoordBBox& b) const
428 {
429 return !(Coord::lessThan(b.mMin,mMin) || Coord::lessThan(mMax,b.mMax));
430 }
431
433 bool hasOverlap(const CoordBBox& b) const
434 {
435 return !(Coord::lessThan(mMax,b.mMin) || Coord::lessThan(b.mMax,mMin));
436 }
437
439 void expand(ValueType padding)
440 {
441 mMin.offset(-padding);
442 mMax.offset( padding);
443 }
444
446 CoordBBox expandBy(ValueType padding) const
447 {
448 return CoordBBox(mMin.offsetBy(-padding),mMax.offsetBy(padding));
449 }
450
452 void expand(const Coord& xyz)
453 {
454 mMin.minComponent(xyz);
455 mMax.maxComponent(xyz);
456 }
457
459 void expand(const CoordBBox& bbox)
460 {
461 mMin.minComponent(bbox.min());
462 mMax.maxComponent(bbox.max());
463 }
465 void intersect(const CoordBBox& bbox)
466 {
467 mMin.maxComponent(bbox.min());
468 mMax.minComponent(bbox.max());
469 }
472 void expand(const Coord& min, Coord::ValueType dim)
473 {
474 mMin.minComponent(min);
475 mMax.maxComponent(min.offsetBy(dim-1));
476 }
479 void translate(const Coord& t) { mMin += t; mMax += t; }
480
482 void moveMin(const Coord& min) { mMax += min - mMin; mMin = min; }
483
485 void moveMax(const Coord& max) { mMin += max - mMax; mMax = max; }
486
491 void getCornerPoints(Coord *p) const
492 {
493 assert(p != nullptr);
494 p->reset(mMin.x(), mMin.y(), mMin.z()); ++p;
495 p->reset(mMin.x(), mMin.y(), mMax.z()); ++p;
496 p->reset(mMin.x(), mMax.y(), mMin.z()); ++p;
497 p->reset(mMin.x(), mMax.y(), mMax.z()); ++p;
498 p->reset(mMax.x(), mMin.y(), mMin.z()); ++p;
499 p->reset(mMax.x(), mMin.y(), mMax.z()); ++p;
500 p->reset(mMax.x(), mMax.y(), mMin.z()); ++p;
501 p->reset(mMax.x(), mMax.y(), mMax.z());
502 }
503
505 CoordBBox operator>> (size_t n) const { return CoordBBox(mMin>>n, mMax>>n); }
507 CoordBBox operator<< (size_t n) const { return CoordBBox(mMin<<n, mMax<<n); }
508 CoordBBox& operator<<=(size_t n) { mMin <<= n; mMax <<= n; return *this; }
509 CoordBBox& operator>>=(size_t n) { mMin >>= n; mMax >>= n; return *this; }
510 CoordBBox operator& (Coord::Int32 n) const { return CoordBBox(mMin & n, mMax & n); }
511 CoordBBox operator| (Coord::Int32 n) const { return CoordBBox(mMin | n, mMax | n); }
512 CoordBBox& operator&= (Coord::Int32 n) { mMin &= n; mMax &= n; return *this; }
513 CoordBBox& operator|= (Coord::Int32 n) { mMin |= n; mMax |= n; return *this; }
515
517 void read(std::istream& is) { mMin.read(is); mMax.read(is); }
519 void write(std::ostream& os) const { mMin.write(os); mMax.write(os); }
520
521 private:
522 Coord mMin, mMax;
523 }; // class CoordBBox
524
525
527
528
529 inline std::ostream& operator<<(std::ostream& os, const Coord& xyz)
530 {
531 os << xyz.asVec3i(); return os;
532 }
533
534
535 inline Coord
536 Abs(const Coord& xyz)
537 {
538 return Coord(Abs(xyz[0]), Abs(xyz[1]), Abs(xyz[2]));
539 }
540
541
543 template<typename T>
545 inline Vec3<typename promote<T, typename Coord::ValueType>::type>
546 operator+(const Vec3<T>& v0, const Coord& v1)
547 {
548 Vec3<typename promote<T, typename Coord::ValueType>::type> result(v0);
549 result[0] += v1[0];
550 result[1] += v1[1];
551 result[2] += v1[2];
552 return result;
553 }
554
555 template<typename T>
556 inline Vec3<typename promote<T, typename Coord::ValueType>::type>
557 operator+(const Coord& v1, const Vec3<T>& v0)
558 {
559 Vec3<typename promote<T, typename Coord::ValueType>::type> result(v0);
560 result[0] += v1[0];
561 result[1] += v1[1];
562 result[2] += v1[2];
563 return result;
564 }
566
567
569 template <typename T>
571 inline Vec3<typename promote<T, Coord::ValueType>::type>
572 operator-(const Vec3<T>& v0, const Coord& v1)
573 {
574 Vec3<typename promote<T, Coord::ValueType>::type> result(v0);
575 result[0] -= v1[0];
576 result[1] -= v1[1];
577 result[2] -= v1[2];
578 return result;
579 }
580
581 template <typename T>
582 inline Vec3<typename promote<T, Coord::ValueType>::type>
583 operator-(const Coord& v1, const Vec3<T>& v0)
584 {
585 Vec3<typename promote<T, Coord::ValueType>::type> result(v0);
586 result[0] -= v1[0];
587 result[1] -= v1[1];
588 result[2] -= v1[2];
589 return -result;
590 }
592
593 inline std::ostream&
594 operator<<(std::ostream& os, const CoordBBox& b)
595 {
596 os << b.min() << " -> " << b.max();
597 return os;
598 }
599
600 } // namespace math
601 } // namespace OPENVDB_VERSION_NAME
602 } // namespace openvdb
603
605
606 // template specialization of std::hash with Coord, which
607 // allows for Coord to be used as the key in std::unordered_map
608 namespace std {// injected in namespace std
609
610 template<>
611 struct hash<openvdb::math::Coord>
612 {
613 using Coord = openvdb::math::Coord;
614 using argument_type = Coord;
615 using result_type = std::size_t;
616 std::size_t operator()(const Coord& ijk) const noexcept { return ijk.Coord::hash<>(); }
617 };// std::hash<openvdb::math::Coord>
618
619 }// namespace std
620
621 #endif // OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED
622
623 // Copyright (c) 2012-2019 DreamWorks Animation LLC
624 // All rights reserved. This software is distributed under the
625 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
openvdb::v6_1::math::Abs
Coord Abs(const Coord &xyz)
Definition: Coord.h:536
openvdb::v6_1::math::CoordBBox::CoordBBox
CoordBBox(CoordBBox &other, const tbb::split &)
Splitting constructor for use in TBB ranges.
Definition: Coord.h:328
openvdb::v6_1::math::CoordBBox::beginXYZ
XYZIterator beginXYZ() const
Return an XYZ-order iterator that points to the minimum coordinate.
Definition: Coord.h:366
openvdb::v6_1::math::Coord::hash
size_t hash() const
Return a hash value for this coordinate.
Definition: Coord.h:257
openvdb::v6_1::math::Coord::setY
Coord & setY(Int32 y)
Definition: Coord.h:108
openvdb::v6_1::math::Coord::setZ
Coord & setZ(Int32 z)
Definition: Coord.h:109
openvdb::v6_1::math::Coord::read
void read(std::istream &is)
Definition: Coord.h:247
openvdb::v6_1::math::Coord::asVec3s
Vec3s asVec3s() const
Definition: Coord.h:172
openvdb::v6_1::math::Coord::Index32
uint32_t Index32
Definition: Coord.h:56
openvdb::v6_1::math::CoordBBox::operator==
bool operator==(const CoordBBox &rhs) const
Definition: Coord.h:375
openvdb::v6_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:427
openvdb::v6_1::math::Coord::operator-=
Coord & operator-=(const Coord &rhs)
Definition: Coord.h:132
Vec3.h
openvdb::v6_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:321
openvdb::v6_1::math::CoordBBox::Iterator::Iterator
Iterator(const CoordBBox &b)
C-tor from a bounding box.
Definition: Coord.h:285
openvdb::v6_1::math::CoordBBox::expand
void expand(const CoordBBox &bbox)
Union this bounding box with the given bounding box.
Definition: Coord.h:459
openvdb::v6_1::math::CoordBBox::reset
void reset(const Coord &min, const Coord &max)
Definition: Coord.h:351
openvdb::v6_1::math::CoordBBox::getStart
Coord getStart() const
Return the minimum coordinate.
Definition: Coord.h:356
openvdb::v6_1::math::CoordBBox::min
Coord & min()
Definition: Coord.h:347
openvdb::v6_1::math::Coord::setX
Coord & setX(Int32 x)
Definition: Coord.h:107
Math.h
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
openvdb::v6_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:84
openvdb::v6_1::math::CoordBBox::reset
void reset()
Definition: Coord.h:350
openvdb::v6_1::math::CoordBBox::expand
void expand(const Coord &xyz)
Expand this bounding box to enclose point (x, y, z).
Definition: Coord.h:452
openvdb::v6_1::math::Coord::data
Int32 * data()
Definition: Coord.h:168
openvdb::v6_1::math::CoordBBox::getCenter
Vec3d getCenter() const
Return the floating-point position of the center of this bounding box.
Definition: Coord.h:396
openvdb::v6_1::math::Coord::operator!=
bool operator!=(const Coord &rhs) const
Definition: Coord.h:181
openvdb::v6_1::math::Coord::z
Int32 z() const
Definition: Coord.h:160
openvdb::v6_1::math::Coord::operator+
Coord operator+(const Coord &rhs) const
Definition: Coord.h:139
openvdb::v6_1::Vec3I
math::Vec3< Index32 > Vec3I
Definition: Types.h:80
openvdb::v6_1::math::Coord::asVec3i
Vec3i asVec3i() const
Definition: Coord.h:173
openvdb::v6_1::math::Coord::operator[]
Int32 operator[](size_t i) const
Definition: Coord.h:161
openvdb::v6_1::math::Coord::Coord
Coord(Int32 x, Int32 y, Int32 z)
Definition: Coord.h:65
openvdb::v6_1::math::Coord::Coord
Coord(const Int32 *v)
Definition: Coord.h:68
openvdb::v6_1::math::CoordBBox::operator>>=
CoordBBox & operator>>=(size_t n)
Bit-wise operations performed on both the min and max members.
Definition: Coord.h:509
std
Definition: Coord.h:608
openvdb::v6_1::math::Vec3i
Vec3< int32_t > Vec3i
Definition: Vec3.h:686
openvdb::v6_1::math::Coord::y
Int32 & y()
Definition: Coord.h:163
openvdb::v6_1::math::CoordBBox::minExtent
size_t minExtent() const
Return the index (0, 1 or 2) of the shortest axis.
Definition: Coord.h:415
openvdb::v6_1::math::Coord::minIndex
size_t minIndex() const
Return the index (0, 1 or 2) with the smallest value.
Definition: Coord.h:242
openvdb::v6_1::math::Coord::asVec3I
Vec3I asVec3I() const
Definition: Coord.h:174
std::hash< openvdb::math::Coord >::argument_type
Coord argument_type
Definition: Coord.h:614
openvdb::v6_1::math::Coord::operator==
bool operator==(const Coord &rhs) const
Definition: Coord.h:177
openvdb::v6_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:91
openvdb::v6_1::math::Coord::operator[]
Int32 & operator[](size_t i)
Definition: Coord.h:165
openvdb::v6_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:227
openvdb::v6_1::math::Coord::Coord
Coord(const Vec3i &v)
Definition: Coord.h:66
openvdb::v6_1::math::Coord::asPointer
const Int32 * asPointer() const
Definition: Coord.h:169
openvdb::v6_1::math::Coord::operator>=
bool operator>=(const Coord &rhs) const
Lexicographic greater than or equal to.
Definition: Coord.h:200
openvdb::v6_1::math::Coord::x
Int32 x() const
Definition: Coord.h:158
openvdb::v6_1::math::CoordBBox::operator<<=
CoordBBox & operator<<=(size_t n)
Bit-wise operations performed on both the min and max members.
Definition: Coord.h:508
openvdb::v6_1::math::operator-
Vec3< typename promote< T, Coord::ValueType >::type > operator-(const Coord &v1, const Vec3< T > &v0)
Allow a Coord to be subtracted from a Vec3.
Definition: Coord.h:583
openvdb::v6_1::math::CoordBBox::beginZYX
ZYXIterator beginZYX() const
Return a ZYX-order iterator that points to the minimum coordinate.
Definition: Coord.h:364
openvdb::v6_1::math::CoordBBox::max
const Coord & max() const
Definition: Coord.h:345
openvdb::v6_1::math::CoordBBox::end
ZYXIterator end() const
Return a ZYX-order iterator that points past the maximum coordinate.
Definition: Coord.h:369
openvdb::v6_1::math::CoordBBox::maxExtent
size_t maxExtent() const
Return the index (0, 1 or 2) of the longest axis.
Definition: Coord.h:418
std::hash< openvdb::math::Coord >::operator()
std::size_t operator()(const Coord &ijk) const noexcept
Definition: Coord.h:616
openvdb::v6_1::math::Coord::z
Int32 & z()
Definition: Coord.h:164
openvdb::v6_1::math::Vec3d
Vec3< double > Vec3d
Definition: Vec3.h:689
openvdb::v6_1::math::Coord::Coord
Coord()
Definition: Coord.h:63
openvdb::v6_1::math::CoordBBox::getEnd
Coord getEnd() const
Return the maximum coordinate plus one.
Definition: Coord.h:359
openvdb::v6_1::math::Coord::x
Int32 & x()
Definition: Coord.h:162
openvdb::v6_1::tools::composite::max
const std::enable_if<!VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:133
openvdb::v6_1::math::Coord::data
const Int32 * data() const
Definition: Coord.h:167
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:125
openvdb::v6_1::math::CoordBBox::extents
Coord extents() const
Definition: Coord.h:403
openvdb::v6_1::math::CoordBBox::CoordBBox
CoordBBox()
The default constructor produces an empty bounding box.
Definition: Coord.h:317
openvdb::v6_1::math::CoordBBox::expand
void expand(ValueType padding)
Pad this bounding box with the specified padding.
Definition: Coord.h:439
openvdb::v6_1::math::Coord::offset
Coord & offset(Int32 dx, Int32 dy, Int32 dz)
Definition: Coord.h:111
std::hash< openvdb::math::Coord >::result_type
std::size_t result_type
Definition: Coord.h:615
openvdb::v6_1::math::Coord::offsetBy
Coord offsetBy(Int32 n) const
Definition: Coord.h:123
openvdb::v6_1::math::Coord::operator+=
Coord & operator+=(const Coord &rhs)
Definition: Coord.h:125
openvdb::v6_1::Index64
uint64_t Index64
Definition: Types.h:60
openvdb::v6_1::math::CoordBBox::expandBy
CoordBBox expandBy(ValueType padding) const
Return a new instance that is expanded by the specified padding.
Definition: Coord.h:446
openvdb::v6_1::math::CoordBBox::write
void write(std::ostream &os) const
Serialize this bounding box to the given stream.
Definition: Coord.h:519
openvdb::v6_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:412
openvdb::v6_1::math::CoordBBox::resetToCube
void resetToCube(const Coord &min, ValueType dim)
Definition: Coord.h:352
openvdb::v6_1::math::operator+
Vec3< typename promote< T, typename Coord::ValueType >::type > operator+(const Coord &v1, const Vec3< T > &v0)
Allow a Coord to be added to or subtracted from a Vec3.
Definition: Coord.h:557
openvdb::v6_1::math::Coord::asVec3d
Vec3d asVec3d() const
Definition: Coord.h:171
openvdb::v6_1::math::CoordBBox::inf
static CoordBBox inf()
Return an "infinite" bounding box, as defined by the Coord value range.
Definition: Coord.h:342
openvdb::v6_1::math::Coord::operator-
Coord operator-(const Coord &rhs) const
Definition: Coord.h:143
openvdb::v6_1::math::Coord::Coord
Coord(Int32 xyz)
Definition: Coord.h:64
openvdb::v6_1::math::operator *
Mat3< typename promote< T0, T1 >::type > operator *(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Multiply m0 by m1 and return the resulting matrix.
Definition: Mat3.h:645
openvdb
Definition: Exceptions.h:40
openvdb::v6_1::math::CoordBBox::volume
Index64 volume() const
Return the integer volume of coordinates spanned by this bounding box.
Definition: Coord.h:406
openvdb::v6_1::math::CoordBBox::getCornerPoints
void getCornerPoints(Coord *p) const
Populates an array with the eight corner points of this bounding box.
Definition: Coord.h:491
openvdb::v6_1::math::Coord::maxComponent
void maxComponent(const Coord &other)
Perform a component-wise maximum with the other Coord.
Definition: Coord.h:211
openvdb::v6_1::math::Coord::ValueType
Int32 ValueType
Definition: Coord.h:60
openvdb::v6_1::math::CoordBBox::createCube
static CoordBBox createCube(const Coord &min, ValueType dim)
Definition: Coord.h:336
openvdb::v6_1::math::CoordBBox
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:271
openvdb::v6_1::math::CoordBBox::intersect
void intersect(const CoordBBox &bbox)
Intersect this bounding box with the given bounding box.
Definition: Coord.h:465
openvdb::v6_1::math::Vec3
Definition: Mat.h:197
openvdb::v6_1::math::Coord::reset
Coord & reset(Int32 xyz)
Reset all three coordinates with the same specified argument.
Definition: Coord.h:105
openvdb::v6_1::math::CoordBBox::empty
bool empty() const
Return true if this bounding box is empty (i.e., encloses no coordinates).
Definition: Coord.h:379
openvdb::v6_1::math::CoordBBox::dim
Coord dim() const
Return the dimensions of the coordinates spanned by this bounding box.
Definition: Coord.h:401
openvdb::v6_1::math::CoordBBox::ValueType
Coord::ValueType ValueType
Definition: Coord.h:275
openvdb::v6_1::math::CoordBBox::begin
ZYXIterator begin() const
Return a ZYX-order iterator that points to the minimum coordinate.
Definition: Coord.h:362
openvdb::v6_1::math::Vec3s
Vec3< float > Vec3s
Definition: Vec3.h:688
openvdb::v6_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:295
openvdb::v6_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:78
openvdb::v6_1::math::Coord::operator-
Coord operator-() const
Definition: Coord.h:147
openvdb::v6_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:300
openvdb::v6_1::math::CoordBBox::Index64
uint64_t Index64
Definition: Coord.h:274
openvdb::v6_1::math::CoordBBox::endZYX
ZYXIterator endZYX() const
Return a ZYX-order iterator that points past the maximum coordinate.
Definition: Coord.h:371
openvdb::v6_1::math::CoordBBox::min
const Coord & min() const
Definition: Coord.h:344
openvdb::v6_1::math::Coord::min
static Coord min()
Return the smallest possible coordinate.
Definition: Coord.h:71
openvdb::v6_1::math::Coord::y
Int32 y() const
Definition: Coord.h:159
openvdb::v6_1::math::Coord::offset
Coord & offset(Int32 n)
Definition: Coord.h:118
openvdb::v6_1::tools::composite::min
const std::enable_if<!VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:129
openvdb::v6_1::math::Coord::operator<
bool operator<(const Coord &rhs) const
Lexicographic less than.
Definition: Coord.h:184
openvdb::v6_1::math::Coord
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:52
openvdb::v6_1::math::Ceil
int Ceil(float x)
Return the ceiling of x.
Definition: Math.h:810
openvdb::v6_1::math::Coord::reset
Coord & reset(Int32 x, Int32 y, Int32 z)
Reset all three coordinates with the specified arguments.
Definition: Coord.h:97
openvdb::v6_1::math::Coord::Limits
std::numeric_limits< ValueType > Limits
Definition: Coord.h:61
openvdb::v6_1::math::Floor
int Floor(float x)
Return the floor of x.
Definition: Math.h:802
openvdb::v6_1::math::Coord::max
static Coord max()
Return the largest possible coordinate.
Definition: Coord.h:74
std::hash< openvdb::math::Coord >::Coord
openvdb::math::Coord Coord
Definition: Coord.h:613
openvdb::v6_1::math::Coord::operator<=
bool operator<=(const Coord &rhs) const
Lexicographic less than or equal to.
Definition: Coord.h:191
openvdb::v6_1::math::CoordBBox::operator!=
bool operator!=(const CoordBBox &rhs) const
Definition: Coord.h:376
tbb
Definition: Coord.h:43
openvdb::v6_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:890
openvdb::v6_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:393
openvdb::v6_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:219
openvdb::v6_1::math::CoordBBox::translate
void translate(const Coord &t)
Translate this bounding box by (tx, ty, tz).
Definition: Coord.h:479
openvdb::v6_1::math::Coord::operator>
bool operator>(const Coord &rhs) const
Lexicographic greater than.
Definition: Coord.h:198
openvdb::v6_1::math::Coord::operator<<=
Coord & operator<<=(size_t n)
Definition: Coord.h:151
openvdb::v6_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:433
openvdb::v6_1::math::Coord::Coord
Coord(const Vec3I &v)
Definition: Coord.h:67
openvdb::v6_1::math::CoordBBox::Iterator
Iterator over the Coord domain covered by a CoordBBox.
Definition: Coord.h:281
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:177
openvdb::v6_1::math::Coord::Int32
int32_t Int32
Definition: Coord.h:55
openvdb::v6_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:472
openvdb::v6_1::math::Coord::maxIndex
size_t maxIndex() const
Return the index (0, 1 or 2) with the largest value.
Definition: Coord.h:245
openvdb::v6_1::math::operator<<
std::ostream & operator<<(std::ostream &os, const CoordBBox &b)
Definition: Coord.h:594
openvdb::v6_1::Int32
int32_t Int32
Definition: Types.h:63
openvdb::v6_1::math::Coord::minComponent
void minComponent(const Coord &other)
Perform a component-wise minimum with the other Coord.
Definition: Coord.h:203
openvdb::v6_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:911
openvdb::v6_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:421
openvdb::v6_1::math::Coord::lessThan
static bool lessThan(const Coord &a, const Coord &b)
Definition: Coord.h:236
openvdb::v6_1::math::Coord::asXYZ
void asXYZ(Int32 &x, Int32 &y, Int32 &z) const
Definition: Coord.h:175
openvdb::v6_1::math::Coord::write
void write(std::ostream &os) const
Definition: Coord.h:248
openvdb::v6_1::math::CoordBBox::moveMax
void moveMax(const Coord &max)
Move this bounding box to the specified max.
Definition: Coord.h:485
openvdb::v6_1::math::Round
float Round(float x)
Return x rounded to the nearest integer.
Definition: Math.h:773
openvdb::v6_1::math::Coord::operator>>=
Coord & operator>>=(size_t n)
Definition: Coord.h:152
openvdb::v6_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:319
openvdb::v6_1::math::CoordBBox::read
void read(std::istream &is)
Unserialize this bounding box from the given stream.
Definition: Coord.h:517
openvdb::v6_1::math::Coord::offsetBy
Coord offsetBy(Int32 dx, Int32 dy, Int32 dz) const
Definition: Coord.h:119
openvdb::v6_1::math::CoordBBox::endXYZ
XYZIterator endXYZ() const
Return an XYZ-order iterator that points past the maximum coordinate.
Definition: Coord.h:373
openvdb::v6_1::math::Coord::asPointer
Int32 * asPointer()
Definition: Coord.h:170
openvdb::v6_1::math::CoordBBox::moveMin
void moveMin(const Coord &min)
Move this bounding box to the specified min.
Definition: Coord.h:482
Platform.h
openvdb::v6_1::math::CoordBBox::Iterator::operator++
Iterator & operator++()
Increment the iterator to point to the next coordinate.
Definition: Coord.h:289
openvdb::v6_1::Index32
uint32_t Index32
Definition: Types.h:59
openvdb::v6_1::math::CoordBBox::max
Coord & max()
Definition: Coord.h:348