Go to the documentation of this file.
31 #ifndef OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED
32 #define OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED
43 namespace tbb {
class split; }
61 using Limits = std::numeric_limits<ValueType>;
66 explicit Coord(
const Vec3i& v): mVec{{v[0], v[1], v[2]}} {}
68 explicit Coord(
const Int32* v): mVec{{v[0], v[1], v[2]}} {}
121 return Coord(mVec[0] + dx, mVec[1] + dy, mVec[2] + dz);
141 return Coord(mVec[0] + rhs[0], mVec[1] + rhs[1], mVec[2] + rhs[2]);
145 return Coord(mVec[0] - rhs[0], mVec[1] - rhs[1], mVec[2] - rhs[2]);
149 Coord operator>> (
size_t n)
const {
return Coord(mVec[0]>>n, mVec[1]>>n, mVec[2]>>n); }
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; }
179 return (mVec[0] == rhs.mVec[0] && mVec[1] == rhs.mVec[1] && mVec[2] == rhs.mVec[2]);
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;
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;
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]);
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]);
238 return (a[0] < b[0] || a[1] < b[1] || a[2] < b[2]);
247 void read(std::istream& is) { is.read(reinterpret_cast<char*>(mVec.data()),
sizeof(mVec)); }
250 os.write(reinterpret_cast<const char*>(mVec.data()),
sizeof(mVec));
257 template<
int Log2N = 20>
260 return ((1<<Log2N)-1) & (mVec[0]*73856093 ^ mVec[1]*19349663 ^ mVec[2]*83492791);
264 std::array<Int32, 3> mVec;
284 template<
bool ZYXOrder>
295 operator bool()
const {
return ZYXOrder ? (mPos[0] <= mMax[0]) : (mPos[2] <= mMax[2]); }
301 return ((mPos == other.mPos) && (mMin == other.mMin) && (mMax == other.mMax));
306 template<
size_t a,
size_t b,
size_t c>
309 if (mPos[a] < mMax[a]) { ++mPos[a]; }
310 else if (mPos[b] < mMax[b]) { mPos[a] = mMin[a]; ++mPos[b]; }
311 else if (mPos[c] <= mMax[c]) { mPos[a] = mMin[a]; mPos[b] = mMin[b]; ++mPos[c]; }
313 Coord mPos, mMin, mMax;
327 : mMin(xMin, yMin, zMin), mMax(xMax, yMax, zMax)
334 assert(this->is_divisible());
335 const size_t n = this->maxExtent();
336 mMax[n] = (mMin[n] + mMax[n]) >> 1;
337 other.mMin[n] = mMax[n] + 1;
385 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
386 #pragma GCC diagnostic push
387 #pragma GCC diagnostic ignored "-Wstrict-overflow"
389 return (mMin[0] > mMax[0] || mMin[1] > mMax[1] || mMin[2] > mMax[2]);
390 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
391 #pragma GCC diagnostic pop
396 operator bool()
const {
return !this->empty(); }
407 Coord dim()
const {
return empty() ?
Coord(0) : (mMax.offsetBy(1) - mMin); }
414 const Coord d = this->dim();
418 bool is_divisible()
const {
return mMin[0]<mMax[0] && mMin[1]<mMax[1] && mMin[2]<mMax[2]; }
421 size_t minExtent()
const {
return this->dim().minIndex(); }
424 size_t maxExtent()
const {
return this->dim().maxIndex(); }
447 mMin.offset(-padding);
448 mMax.offset( padding);
454 return CoordBBox(mMin.offsetBy(-padding),mMax.offsetBy(padding));
460 mMin.minComponent(xyz);
461 mMax.maxComponent(xyz);
467 mMin.minComponent(bbox.
min());
468 mMax.maxComponent(bbox.
max());
473 mMin.maxComponent(bbox.
min());
474 mMax.minComponent(bbox.
max());
480 mMin.minComponent(
min);
481 mMax.maxComponent(
min.offsetBy(dim-1));
499 assert(p !=
nullptr);
500 p->
reset(mMin.x(), mMin.y(), mMin.z()); ++p;
501 p->
reset(mMin.x(), mMin.y(), mMax.z()); ++p;
502 p->
reset(mMin.x(), mMax.y(), mMin.z()); ++p;
503 p->
reset(mMin.x(), mMax.y(), mMax.z()); ++p;
504 p->
reset(mMax.x(), mMin.y(), mMin.z()); ++p;
505 p->
reset(mMax.x(), mMin.y(), mMax.z()); ++p;
506 p->
reset(mMax.x(), mMax.y(), mMin.z()); ++p;
507 p->
reset(mMax.x(), mMax.y(), mMax.z());
523 void read(std::istream& is) { mMin.read(is); mMax.read(is); }
525 void write(std::ostream& os)
const { mMin.write(os); mMax.write(os); }
537 os << xyz.
asVec3i();
return os;
575 template <
typename T>
587 template <
typename T>
602 os << b.
min() <<
" -> " << b.
max();
622 std::size_t
operator()(
const Coord& ijk)
const noexcept {
return ijk.Coord::hash<>(); }
627 #endif // OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED
XYZIterator endXYZ() const
Return an XYZ-order iterator that points past the maximum coordinate.
Definition: Coord.h:377
Coord argument_type
Definition: Coord.h:620
Vec3d getCenter() const
Return the floating-point position of the center of this bounding box.
Definition: Coord.h:402
Int32 & y()
Definition: Coord.h:163
Iterator(const CoordBBox &b)
C-tor from a bounding box.
Definition: Coord.h:289
Coord(const Vec3i &v)
Definition: Coord.h:66
void write(std::ostream &os) const
Definition: Coord.h:248
bool isInside(const CoordBBox &b) const
Return true if the given bounding box is inside this bounding box.
Definition: Coord.h:433
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:52
Coord & setX(Int32 x)
Definition: Coord.h:107
void moveMax(const Coord &max)
Move this bounding box to the specified max.
Definition: Coord.h:491
Int32 & z()
Definition: Coord.h:164
float Round(float x)
Return x rounded to the nearest integer.
Definition: Math.h:793
Coord(Int32 x, Int32 y, Int32 z)
Definition: Coord.h:65
int Ceil(float x)
Return the ceiling of x.
Definition: Math.h:830
void expand(const Coord &xyz)
Expand this bounding box to enclose point (x, y, z).
Definition: Coord.h:458
Coord(const Int32 *v)
Definition: Coord.h:68
Coord getStart() const
Return the minimum coordinate.
Definition: Coord.h:360
openvdb::math::Coord Coord
Definition: Coord.h:619
bool operator>(const Coord &rhs) const
Lexicographic greater than.
Definition: Coord.h:198
Vec3< typename promote< T, typename Coord::ValueType >::type > operator+(const Coord &v1, const Vec3< T > &v0)
Definition: Coord.h:563
ZYXIterator end() const
Return a ZYX-order iterator that points past the maximum coordinate.
Definition: Coord.h:373
void reset()
Definition: Coord.h:354
const Int32 * data() const
Definition: Coord.h:167
Vec3s asVec3s() const
Definition: Coord.h:172
Coord & offset(Int32 dx, Int32 dy, Int32 dz)
Definition: Coord.h:111
CoordBBox()
The default constructor produces an empty bounding box.
Definition: Coord.h:321
CoordBBox(const Coord &min, const Coord &max)
Construct a bounding box with the given min and max bounds.
Definition: Coord.h:323
void minComponent(const Coord &other)
Perform a component-wise minimum with the other Coord.
Definition: Coord.h:203
Coord & reset(Int32 x, Int32 y, Int32 z)
Reset all three coordinates with the specified arguments.
Definition: Coord.h:97
const Int32 * asPointer() const
Definition: Coord.h:169
size_t MaxIndex(const Vec3T &v)
Return the index [0,1,2] of the largest value in a 3D vector.
Definition: Math.h:931
bool hasVolume() const
Return true if this bounding box is nonempty (i.e., encloses at least one coordinate).
Definition: Coord.h:399
const Coord & operator*() const
Return a const reference to the coordinate currently pointed to.
Definition: Coord.h:297
ZYXIterator beginZYX() const
Return a ZYX-order iterator that points to the minimum coordinate.
Definition: Coord.h:368
Coord & operator+=(const Coord &rhs)
Definition: Coord.h:125
std::numeric_limits< ValueType > Limits
Definition: Coord.h:61
size_t hash() const
Return a hash value for this coordinate.
Definition: Coord.h:258
Vec3< int32_t > Vec3i
Definition: Vec3.h:686
bool hasOverlap(const CoordBBox &b) const
Return true if the given bounding box overlaps with this bounding box.
Definition: Coord.h:439
int32_t Int32
Definition: Types.h:63
size_t maxIndex() const
Return the index (0, 1 or 2) with the largest value.
Definition: Coord.h:245
static Coord max()
Return the largest possible coordinate.
Definition: Coord.h:74
uint32_t Index32
Definition: Coord.h:56
Coord & operator>>=(size_t n)
Definition: Coord.h:152
bool operator!=(const Coord &rhs) const
Definition: Coord.h:181
void asXYZ(Int32 &x, Int32 &y, Int32 &z) const
Definition: Coord.h:175
Vec3d asVec3d() const
Definition: Coord.h:171
Coord & setZ(Int32 z)
Definition: Coord.h:109
Int32 z() const
Definition: Coord.h:160
Coord operator-(const Coord &rhs) const
Definition: Coord.h:143
Vec3i asVec3i() const
Definition: Coord.h:173
bool empty() const
Return true if this bounding box is empty (i.e., encloses no coordinates).
Definition: Coord.h:383
static bool lessThan(const Coord &a, const Coord &b)
Definition: Coord.h:236
Int32 * asPointer()
Definition: Coord.h:170
Int32 & x()
Definition: Coord.h:162
void reset(const Coord &min, const Coord &max)
Definition: Coord.h:355
Coord & min()
Definition: Coord.h:351
Coord extents() const
Definition: Coord.h:409
static Coord maxComponent(const Coord &lhs, const Coord &rhs)
Return the component-wise maximum of the two Coords.
Definition: Coord.h:227
size_t MinIndex(const Vec3T &v)
Return the index [0,1,2] of the smallest value in a 3D vector.
Definition: Math.h:910
math::Vec3< Index32 > Vec3I
Definition: Types.h:80
void expand(const CoordBBox &bbox)
Union this bounding box with the given bounding box.
Definition: Coord.h:465
size_t minExtent() const
Return the index (0, 1 or 2) of the shortest axis.
Definition: Coord.h:421
Int32 & operator[](size_t i)
Definition: Coord.h:165
static Coord min()
Return the smallest possible coordinate.
Definition: Coord.h:71
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Int32 ValueType
Definition: Coord.h:60
Vec3< typename promote< T, Coord::ValueType >::type > operator-(const Coord &v1, const Vec3< T > &v0)
Definition: Coord.h:589
static CoordBBox inf()
Return an "infinite" bounding box, as defined by the Coord value range.
Definition: Coord.h:346
Coord & operator-=(const Coord &rhs)
Definition: Coord.h:132
std::size_t result_type
Definition: Coord.h:621
Coord::ValueType ValueType
Definition: Coord.h:279
Coord dim() const
Return the dimensions of the coordinates spanned by this bounding box.
Definition: Coord.h:407
ZYXIterator begin() const
Return a ZYX-order iterator that points to the minimum coordinate.
Definition: Coord.h:366
bool operator!=(const CoordBBox &rhs) const
Definition: Coord.h:380
Int32 operator[](size_t i) const
Definition: Coord.h:161
static Coord minComponent(const Coord &lhs, const Coord &rhs)
Return the component-wise minimum of the two Coords.
Definition: Coord.h:219
CoordBBox(CoordBBox &other, const tbb::split &)
Splitting constructor for use in TBB ranges.
Definition: Coord.h:332
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:275
bool operator==(const Coord &rhs) const
Definition: Coord.h:177
Coord()
Definition: Coord.h:63
const Coord & min() const
Definition: Coord.h:348
void resetToCube(const Coord &min, ValueType dim)
Definition: Coord.h:356
bool isInside(const Coord &xyz) const
Return true if point (x, y, z) is inside this bounding box.
Definition: Coord.h:427
Coord getEnd() const
Return the maximum coordinate plus one.
Definition: Coord.h:363
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:325
bool operator<(const Coord &rhs) const
Lexicographic less than.
Definition: Coord.h:184
void expand(ValueType padding)
Pad this bounding box with the specified padding.
Definition: Coord.h:445
Coord offsetBy(Int32 n) const
Definition: Coord.h:123
Index64 volume() const
Return the integer volume of coordinates spanned by this bounding box.
Definition: Coord.h:412
bool operator!=(const Iterator &other) const
Return true if this iterator and the given iterator point to different coordinates.
Definition: Coord.h:304
Vec3< double > Vec3d
Definition: Vec3.h:689
ZYXIterator endZYX() const
Return a ZYX-order iterator that points past the maximum coordinate.
Definition: Coord.h:375
std::size_t operator()(const Coord &ijk) const noexcept
Definition: Coord.h:622
size_t maxExtent() const
Return the index (0, 1 or 2) of the longest axis.
Definition: Coord.h:424
Int32 y() const
Definition: Coord.h:159
uint32_t Index32
Definition: Types.h:59
Coord offsetBy(Int32 dx, Int32 dy, Int32 dz) const
Definition: Coord.h:119
static Coord round(const Vec3< T > &xyz)
Return xyz rounded to the closest integer coordinates (cell centered conversion).
Definition: Coord.h:78
Vec3< float > Vec3s
Definition: Vec3.h:688
std::ostream & operator<<(std::ostream &os, const CoordBBox &b)
Definition: Coord.h:600
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:180
Coord(Int32 xyz)
Definition: Coord.h:64
void translate(const Coord &t)
Translate this bounding box by (tx, ty, tz).
Definition: Coord.h:485
static CoordBBox createCube(const Coord &min, ValueType dim)
Definition: Coord.h:340
Int32 x() const
Definition: Coord.h:158
uint64_t Index64
Definition: Types.h:60
const Coord & max() const
Definition: Coord.h:349
bool is_divisible() const
Return true if this bounding box can be subdivided [mainly for use by TBB].
Definition: Coord.h:418
void write(std::ostream &os) const
Serialize this bounding box to the given stream.
Definition: Coord.h:525
uint64_t Index64
Definition: Coord.h:278
int32_t Int32
Definition: Coord.h:55
Coord & setY(Int32 y)
Definition: Coord.h:108
CoordBBox & operator>>=(size_t n)
Definition: Coord.h:515
bool operator>=(const Coord &rhs) const
Lexicographic greater than or equal to.
Definition: Coord.h:200
bool operator<=(const Coord &rhs) const
Lexicographic less than or equal to.
Definition: Coord.h:191
XYZIterator beginXYZ() const
Return an XYZ-order iterator that points to the minimum coordinate.
Definition: Coord.h:370
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:478
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:128
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
bool operator==(const CoordBBox &rhs) const
Definition: Coord.h:379
void maxComponent(const Coord &other)
Perform a component-wise maximum with the other Coord.
Definition: Coord.h:211
Vec3I asVec3I() const
Definition: Coord.h:174
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
Coord & reset(Int32 xyz)
Reset all three coordinates with the same specified argument.
Definition: Coord.h:105
CoordBBox & operator<<=(size_t n)
Definition: Coord.h:514
Iterator & operator++()
Increment the iterator to point to the next coordinate.
Definition: Coord.h:293
Coord & offset(Int32 n)
Definition: Coord.h:118
void moveMin(const Coord &min)
Move this bounding box to the specified min.
Definition: Coord.h:488
Coord Abs(const Coord &xyz)
Definition: Coord.h:542
void read(std::istream &is)
Definition: Coord.h:247
void getCornerPoints(Coord *p) const
Populates an array with the eight corner points of this bounding box.
Definition: Coord.h:497
Iterator over the Coord domain covered by a CoordBBox.
Definition: Coord.h:285
Coord & max()
Definition: Coord.h:352
bool operator==(const Iterator &other) const
Return true if this iterator and the given iterator point to the same coordinate.
Definition: Coord.h:299
Definition: Exceptions.h:40
int Floor(float x)
Return the floor of x.
Definition: Math.h:822
void intersect(const CoordBBox &bbox)
Intersect this bounding box with the given bounding box.
Definition: Coord.h:471
Coord & operator<<=(size_t n)
Definition: Coord.h:151
Coord operator+(const Coord &rhs) const
Definition: Coord.h:139
Coord operator-() const
Definition: Coord.h:147
CoordBBox expandBy(ValueType padding) const
Return a new instance that is expanded by the specified padding.
Definition: Coord.h:452
size_t minIndex() const
Return the index (0, 1 or 2) with the smallest value.
Definition: Coord.h:242
void read(std::istream &is)
Unserialize this bounding box from the given stream.
Definition: Coord.h:523
Coord(const Vec3I &v)
Definition: Coord.h:67
Int32 * data()
Definition: Coord.h:168