31 #ifndef OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED 32 #define OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED 42 namespace tbb {
class split; }
60 using Limits = std::numeric_limits<ValueType>;
65 explicit Coord(
const Vec3i& v): mVec{{v[0], v[1], v[2]}} {}
67 explicit Coord(
const Int32* v): mVec{{v[0], v[1], v[2]}} {}
120 return Coord(mVec[0] + dx, mVec[1] + dy, mVec[2] + dz);
140 return Coord(mVec[0] + rhs[0], mVec[1] + rhs[1], mVec[2] + rhs[2]);
144 return Coord(mVec[0] - rhs[0], mVec[1] - rhs[1], mVec[2] - rhs[2]);
148 Coord operator>> (
size_t n)
const {
return Coord(mVec[0]>>n, mVec[1]>>n, mVec[2]>>n); }
152 Coord operator& (
Int32 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) { mVec[0]&=n; mVec[1]&=n; mVec[2]&=n;
return *
this; }
155 Coord& operator|= (
Int32 n) { mVec[0]|=n; mVec[1]|=n; mVec[2]|=n;
return *
this; }
178 return (mVec[0] == rhs.mVec[0] && mVec[1] == rhs.mVec[1] && mVec[2] == rhs.mVec[2]);
185 return this->x() < rhs.
x() ? true : this->x() > rhs.
x() ? false
186 : this->y() < rhs.
y() ? true : this->y() > rhs.
y() ? false
187 : this->z() < rhs.
z() ? true :
false;
192 return this->x() < rhs.
x() ? true : this->x() > rhs.
x() ? false
193 : this->y() < rhs.
y() ? true : this->y() > rhs.
y() ? false
194 : this->z() <=rhs.
z() ? true :
false;
204 mVec[0] =
std::min(mVec[0], other.mVec[0]);
205 mVec[1] =
std::min(mVec[1], other.mVec[1]);
206 mVec[2] =
std::min(mVec[2], other.mVec[2]);
212 mVec[0] =
std::max(mVec[0], other.mVec[0]);
213 mVec[1] =
std::max(mVec[1], other.mVec[1]);
214 mVec[2] =
std::max(mVec[2], other.mVec[2]);
237 return (a[0] < b[0] || a[1] < b[1] || a[2] < b[2]);
246 void read(std::istream& is) { is.read(reinterpret_cast<char*>(mVec.data()),
sizeof(mVec)); }
249 os.write(reinterpret_cast<const char*>(mVec.data()),
sizeof(mVec));
253 std::array<Int32, 3> mVec;
273 template<
bool ZYXOrder>
284 operator bool()
const {
return ZYXOrder ? (mPos[0] <= mMax[0]) : (mPos[2] <= mMax[2]); }
290 return ((mPos == other.mPos) && (mMin == other.mMin) && (mMax == other.mMax));
295 template<
size_t a,
size_t b,
size_t c>
298 if (mPos[a] < mMax[a]) { ++mPos[a]; }
299 else if (mPos[b] < mMax[b]) { mPos[a] = mMin[a]; ++mPos[b]; }
300 else if (mPos[c] <= mMax[c]) { mPos[a] = mMin[a]; mPos[b] = mMin[b]; ++mPos[c]; }
302 Coord mPos, mMin, mMax;
316 : mMin(xMin, yMin, zMin), mMax(xMax, yMax, zMax)
323 assert(this->is_divisible());
324 const size_t n = this->maxExtent();
325 mMax[n] = (mMin[n] + mMax[n]) >> 1;
326 other.mMin[n] = mMax[n] + 1;
372 bool empty()
const {
return (mMin[0] > mMax[0] || mMin[1] > mMax[1] || mMin[2] > mMax[2]); }
374 operator bool()
const {
return !this->empty(); }
391 const Coord d = this->dim();
395 bool is_divisible()
const {
return mMin[0]<mMax[0] && mMin[1]<mMax[1] && mMin[2]<mMax[2]; }
398 size_t minExtent()
const {
return this->dim().minIndex(); }
401 size_t maxExtent()
const {
return this->dim().maxIndex(); }
424 mMin.offset(-padding);
425 mMax.offset( padding);
431 return CoordBBox(mMin.offsetBy(-padding),mMax.offsetBy(padding));
437 mMin.minComponent(xyz);
438 mMax.maxComponent(xyz);
444 mMin.minComponent(bbox.
min());
445 mMax.maxComponent(bbox.
max());
450 mMin.maxComponent(bbox.
min());
451 mMax.minComponent(bbox.
max());
457 mMin.minComponent(
min);
458 mMax.maxComponent(
min.offsetBy(dim-1));
470 assert(p !=
nullptr);
471 p->
reset(mMin.x(), mMin.y(), mMin.z()); ++p;
472 p->
reset(mMin.x(), mMin.y(), mMax.z()); ++p;
473 p->
reset(mMin.x(), mMax.y(), mMin.z()); ++p;
474 p->
reset(mMin.x(), mMax.y(), mMax.z()); ++p;
475 p->
reset(mMax.x(), mMin.y(), mMin.z()); ++p;
476 p->
reset(mMax.x(), mMin.y(), mMax.z()); ++p;
477 p->
reset(mMax.x(), mMax.y(), mMin.z()); ++p;
478 p->
reset(mMax.x(), mMax.y(), mMax.z());
494 void read(std::istream& is) { mMin.read(is); mMax.read(is); }
496 void write(std::ostream& os)
const { mMin.write(os); mMax.write(os); }
508 os << xyz.
asVec3i();
return os;
546 template <
typename T>
558 template <
typename T>
573 os << b.
min() <<
" -> " << b.
max();
581 #endif // OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED Int32 * asPointer()
Definition: Coord.h:169
Coord & setY(Int32 y)
Definition: Coord.h:107
Coord & setZ(Int32 z)
Definition: Coord.h:108
void read(std::istream &is)
Definition: Coord.h:246
Vec3s asVec3s() const
Definition: Coord.h:171
Vec3< int32_t > Vec3i
Definition: Vec3.h:676
float Round(float x)
Return x rounded to the nearest integer.
Definition: Math.h:773
Coord & operator-=(const Coord &rhs)
Definition: Coord.h:131
int Ceil(float x)
Return the ceiling of x.
Definition: Math.h:810
CoordBBox & operator>>=(size_t n)
Bit-wise operations performed on both the min and max members.
Definition: Coord.h:486
uint32_t Index32
Definition: Coord.h:55
uint64_t Index64
Definition: Types.h:60
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
CoordBBox()
The default constructor produces an empty bounding box.
Definition: Coord.h:310
Int32 * data()
Definition: Coord.h:167
bool operator==(const Iterator &other) const
Return true if this iterator and the given iterator point to the same coordinate.
Definition: Coord.h:288
Coord & setX(Int32 x)
Definition: Coord.h:106
size_t maxExtent() const
Return the index (0, 1 or 2) of the longest axis.
Definition: Coord.h:401
static Coord floor(const Vec3< T > &xyz)
Return the largest integer coordinates that are not greater than xyz (node centered conversion).
Definition: Coord.h:83
bool operator!=(const Coord &rhs) const
Definition: Coord.h:180
Coord extents() const
Definition: Coord.h:386
Int32 z() const
Definition: Coord.h:159
Vec3< double > Vec3d
Definition: Vec3.h:679
Coord operator+(const Coord &rhs) const
Definition: Coord.h:138
size_t MinIndex(const Vec3T &v)
Return the index [0,1,2] of the smallest value in a 3D vector.
Definition: Math.h:890
const Coord & max() const
Definition: Coord.h:338
Vec3i asVec3i() const
Definition: Coord.h:172
bool operator!=(const Iterator &other) const
Return true if this iterator and the given iterator point to different coordinates.
Definition: Coord.h:293
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:455
Int32 operator[](size_t i) const
Definition: Coord.h:160
Coord(Int32 x, Int32 y, Int32 z)
Definition: Coord.h:64
Coord & min()
Definition: Coord.h:340
Coord(const Int32 *v)
Definition: Coord.h:67
Vec3I asVec3I() const
Definition: Coord.h:173
bool operator==(const Coord &rhs) const
Definition: Coord.h:176
Int32 & operator[](size_t i)
Definition: Coord.h:164
static Coord maxComponent(const Coord &lhs, const Coord &rhs)
Return the component-wise maximum of the two Coords.
Definition: Coord.h:226
void reset()
Definition: Coord.h:343
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:534
Int32 & y()
Definition: Coord.h:162
const Int32 * asPointer() const
Definition: Coord.h:168
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
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:51
size_t minIndex() const
Return the index (0, 1 or 2) with the smallest value.
Definition: Coord.h:241
int Floor(float x)
Return the floor of x.
Definition: Math.h:802
ZYXIterator begin() const
Return a ZYX-order iterator that points to the minimum coordinate.
Definition: Coord.h:355
int32_t Int32
Definition: Types.h:63
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:90
void getCornerPoints(Coord *p) const
Populates an array with the eight corner points of this bounding box.
Definition: Coord.h:468
Coord(const Vec3i &v)
Definition: Coord.h:65
Int32 x() const
Definition: Coord.h:157
bool operator==(const CoordBBox &rhs) const
Definition: Coord.h:368
void expand(const CoordBBox &bbox)
Union this bounding box with the given bounding box.
Definition: Coord.h:442
void write(std::ostream &os) const
Serialize this bounding box to the given stream.
Definition: Coord.h:496
Iterator & operator++()
Increment the iterator to point to the next coordinate.
Definition: Coord.h:282
bool operator>=(const Coord &rhs) const
Lexicographic greater than or equal to.
Definition: Coord.h:199
bool isInside(const Coord &xyz) const
Return true if point (x, y, z) is inside this bounding box.
Definition: Coord.h:404
Int32 & z()
Definition: Coord.h:163
Coord::ValueType ValueType
Definition: Coord.h:268
Coord()
Definition: Coord.h:62
uint32_t Index32
Definition: Types.h:59
Int32 & x()
Definition: Coord.h:161
const Int32 * data() const
Definition: Coord.h:166
void reset(const Coord &min, const Coord &max)
Definition: Coord.h:344
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
Coord & operator+=(const Coord &rhs)
Definition: Coord.h:124
bool hasOverlap(const CoordBBox &b) const
Return true if the given bounding box overlaps with this bounding box.
Definition: Coord.h:416
XYZIterator beginXYZ() const
Return an XYZ-order iterator that points to the minimum coordinate.
Definition: Coord.h:359
Coord dim() const
Return the dimensions of the coordinates spanned by this bounding box.
Definition: Coord.h:384
Coord & offset(Int32 dx, Int32 dy, Int32 dz)
Definition: Coord.h:110
void read(std::istream &is)
Unserialize this bounding box from the given stream.
Definition: Coord.h:494
Vec3d asVec3d() const
Definition: Coord.h:170
uint64_t Index64
Definition: Coord.h:267
Coord offsetBy(Int32 n) const
Definition: Coord.h:122
ZYXIterator endZYX() const
Return a ZYX-order iterator that points past the maximum coordinate.
Definition: Coord.h:364
const Coord & min() const
Definition: Coord.h:337
size_t MaxIndex(const Vec3T &v)
Return the index [0,1,2] of the largest value in a 3D vector.
Definition: Math.h:911
Definition: Exceptions.h:40
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:264
CoordBBox(CoordBBox &other, const tbb::split &)
Splitting constructor for use in TBB ranges.
Definition: Coord.h:321
Coord operator-(const Coord &rhs) const
Definition: Coord.h:142
Coord(Int32 xyz)
Definition: Coord.h:63
Coord & reset(Int32 xyz)
Reset all three coordinates with the same specified argument.
Definition: Coord.h:104
bool operator!=(const CoordBBox &rhs) const
Definition: Coord.h:369
void maxComponent(const Coord &other)
Perform a component-wise maximum with the other Coord.
Definition: Coord.h:210
Int32 ValueType
Definition: Coord.h:59
std::ostream & operator<<(std::ostream &os, const CoordBBox &b)
Definition: Coord.h:571
bool isInside(const CoordBBox &b) const
Return true if the given bounding box is inside this bounding box.
Definition: Coord.h:410
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:560
bool hasVolume() const
Return true if this bounding box is nonempty (i.e., encloses at least one coordinate).
Definition: Coord.h:376
Coord getStart() const
Return the minimum coordinate.
Definition: Coord.h:349
void expand(ValueType padding)
Pad this bounding box with the specified padding.
Definition: Coord.h:422
CoordBBox expandBy(ValueType padding) const
Return a new instance that is expanded by the specified padding.
Definition: Coord.h:429
Int32 y() const
Definition: Coord.h:158
bool is_divisible() const
Return true if this bounding box can be subdivided [mainly for use by TBB].
Definition: Coord.h:395
static Coord round(const Vec3< T > &xyz)
Return xyz rounded to the closest integer coordinates (cell centered conversion).
Definition: Coord.h:77
Coord operator-() const
Definition: Coord.h:146
Coord & offset(Int32 n)
Definition: Coord.h:117
static CoordBBox inf()
Return an "infinite" bounding box, as defined by the Coord value range.
Definition: Coord.h:335
CoordBBox & operator<<=(size_t n)
Bit-wise operations performed on both the min and max members.
Definition: Coord.h:485
Iterator(const CoordBBox &b)
C-tor from a bounding box.
Definition: Coord.h:278
static Coord min()
Return the smallest possible coordinate.
Definition: Coord.h:70
Coord Abs(const Coord &xyz)
Definition: Coord.h:513
bool operator<=(const Coord &rhs) const
Lexicographic less than or equal to.
Definition: Coord.h:190
ZYXIterator end() const
Return a ZYX-order iterator that points past the maximum coordinate.
Definition: Coord.h:362
bool operator<(const Coord &rhs) const
Lexicographic less than.
Definition: Coord.h:183
static Coord minComponent(const Coord &lhs, const Coord &rhs)
Return the component-wise minimum of the two Coords.
Definition: Coord.h:218
Coord & reset(Int32 x, Int32 y, Int32 z)
Reset all three coordinates with the specified arguments.
Definition: Coord.h:96
std::numeric_limits< ValueType > Limits
Definition: Coord.h:60
math::Vec3< Index32 > Vec3I
Definition: Types.h:80
void expand(const Coord &xyz)
Expand this bounding box to enclose point (x, y, z).
Definition: Coord.h:435
static Coord max()
Return the largest possible coordinate.
Definition: Coord.h:73
CoordBBox(const Coord &min, const Coord &max)
Construct a bounding box with the given min and max bounds.
Definition: Coord.h:312
Vec3d getCenter() const
Return the floating-point position of the center of this bounding box.
Definition: Coord.h:379
XYZIterator endXYZ() const
Return an XYZ-order iterator that points past the maximum coordinate.
Definition: Coord.h:366
Coord(const Vec3I &v)
Definition: Coord.h:66
size_t minExtent() const
Return the index (0, 1 or 2) of the shortest axis.
Definition: Coord.h:398
Index64 volume() const
Return the integer volume of coordinates spanned by this bounding box.
Definition: Coord.h:389
ZYXIterator beginZYX() const
Return a ZYX-order iterator that points to the minimum coordinate.
Definition: Coord.h:357
Iterator over the Coord domain covered by a CoordBBox.
Definition: Coord.h:274
Coord & max()
Definition: Coord.h:341
static CoordBBox createCube(const Coord &min, ValueType dim)
Definition: Coord.h:329
int32_t Int32
Definition: Coord.h:54
bool operator>(const Coord &rhs) const
Lexicographic greater than.
Definition: Coord.h:197
Coord & operator<<=(size_t n)
Definition: Coord.h:150
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
void minComponent(const Coord &other)
Perform a component-wise minimum with the other Coord.
Definition: Coord.h:202
Vec3< float > Vec3s
Definition: Vec3.h:678
void resetToCube(const Coord &min, ValueType dim)
Definition: Coord.h:345
static bool lessThan(const Coord &a, const Coord &b)
Definition: Coord.h:235
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:314
size_t maxIndex() const
Return the index (0, 1 or 2) with the largest value.
Definition: Coord.h:244
void asXYZ(Int32 &x, Int32 &y, Int32 &z) const
Definition: Coord.h:174
void write(std::ostream &os) const
Definition: Coord.h:247
void intersect(const CoordBBox &bbox)
Intersect this bounding box with the given bounding box.
Definition: Coord.h:448
Coord getEnd() const
Return the maximum coordinate plus one.
Definition: Coord.h:352
Coord & operator>>=(size_t n)
Definition: Coord.h:151
bool empty() const
Return true if this bounding box is empty (i.e., encloses no coordinates).
Definition: Coord.h:372
void translate(const Coord &t)
Definition: Coord.h:462
Coord offsetBy(Int32 dx, Int32 dy, Int32 dz) const
Definition: Coord.h:118