4 #ifndef OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED
5 #define OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED
16 #include <tbb/blocked_range.h>
33 using Limits = std::numeric_limits<ValueType>;
95 Coord offsetBy(
Int32 n)
const {
return offsetBy(n, n, n); }
133 Int32 operator[](
size_t i)
const { assert(i < 3);
return mVec[i]; }
137 Int32& operator[](
size_t i) { assert(i < 3);
return mVec[i]; }
141 const Int32* asPointer()
const {
return mVec.data(); }
142 Int32* asPointer() {
return mVec.data(); }
151 return (
mVec[0] == rhs.mVec[0] &&
mVec[1] == rhs.mVec[1] &&
mVec[2] == rhs.mVec[2]);
158 return this->
x() < rhs.x() ?
true : this->
x() > rhs.x() ?
false
159 : this->
y() < rhs.y() ?
true : this->
y() > rhs.y() ?
false
160 : this->
z() < rhs.z() ?
true :
false;
165 return this->
x() < rhs.x() ?
true : this->
x() > rhs.x() ?
false
166 : this->
y() < rhs.y() ?
true : this->
y() > rhs.y() ?
false
167 : this->
z() <=rhs.z() ?
true :
false;
170 bool operator>(
const Coord& rhs)
const {
return !(*
this <= rhs); }
208 static inline bool lessThan(
const Coord&
a,
const Coord&
b)
210 return (a[0] < b[0] || a[1] < b[1] || a[2] < b[2]);
219 void read(std::istream& is) { is.read(reinterpret_cast<char*>(
mVec.data()),
sizeof(
mVec)); }
220 void write(std::ostream& os)
const
222 os.write(reinterpret_cast<const char*>(
mVec.data()),
sizeof(
mVec));
231 template<
int Log2N = 20>
234 const uint32_t* vec =
reinterpret_cast<const uint32_t*
>(
mVec.data());
235 return ((1<<Log2N)-1) & (vec[0]*73856093 ^ vec[1]*19349669 ^ vec[2]*83492791);
239 std::array<Int32, 3>
mVec;
259 template<
bool ZYXOrder>
270 operator bool()
const {
return ZYXOrder ? (mPos[0] <= mMax[0]) : (mPos[2] <= mMax[2]); }
276 return ((mPos == other.mPos) && (mMin == other.mMin) && (mMax == other.mMax));
281 template<
size_t a,
size_t b,
size_t c>
284 if (mPos[a] < mMax[a]) { ++mPos[
a]; }
285 else if (mPos[b] < mMax[b]) { mPos[
a] = mMin[
a]; ++mPos[
b]; }
286 else if (mPos[
c] <= mMax[
c]) { mPos[
a] = mMin[
a]; mPos[
b] = mMin[
b]; ++mPos[
c]; }
288 Coord mPos, mMin, mMax;
302 : mMin(xMin, yMin, zMin), mMax(xMax, yMax, zMax)
311 mMax[
n] = (mMin[
n] + mMax[
n]) >> 1;
312 other.mMin[
n] = mMax[
n] + 1;
317 return CoordBBox(min, min.offsetBy(dim - 1));
360 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
361 #pragma GCC diagnostic push
362 #pragma GCC diagnostic ignored "-Wstrict-overflow"
364 return (mMin[0] > mMax[0] || mMin[1] > mMax[1] || mMin[2] > mMax[2]);
365 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
366 #pragma GCC diagnostic pop
371 operator bool()
const {
return !this->
empty(); }
393 bool is_divisible()
const {
return mMin[0]<mMax[0] && mMin[1]<mMax[1] && mMin[2]<mMax[2]; }
404 return !(Coord::lessThan(xyz,mMin) || Coord::lessThan(mMax,xyz));
410 return !(Coord::lessThan(b.mMin,mMin) || Coord::lessThan(mMax,b.mMax));
416 return !(Coord::lessThan(mMax,b.mMin) || Coord::lessThan(b.mMax,mMin));
422 mMin.offset(-padding);
423 mMax.offset( padding);
429 return CoordBBox(mMin.offsetBy(-padding),mMax.offsetBy(padding));
435 mMin.minComponent(xyz);
436 mMax.maxComponent(xyz);
442 mMin.minComponent(bbox.
min());
443 mMax.maxComponent(bbox.
max());
448 mMin.maxComponent(bbox.
min());
449 mMax.minComponent(bbox.
max());
455 mMin.minComponent(min);
456 mMax.maxComponent(min.offsetBy(dim-1));
474 assert(p !=
nullptr);
475 p->reset(mMin.x(), mMin.y(), mMin.z()); ++p;
476 p->reset(mMin.x(), mMin.y(), mMax.z()); ++p;
477 p->reset(mMin.x(), mMax.y(), mMin.z()); ++p;
478 p->reset(mMin.x(), mMax.y(), mMax.z()); ++p;
479 p->reset(mMax.x(), mMin.y(), mMin.z()); ++p;
480 p->reset(mMax.x(), mMin.y(), mMax.z()); ++p;
481 p->reset(mMax.x(), mMax.y(), mMin.z()); ++p;
482 p->reset(mMax.x(), mMax.y(), mMax.z());
498 void read(std::istream& is) { mMin.read(is); mMax.read(is); }
500 void write(std::ostream& os)
const { mMin.write(os); mMax.write(os); }
512 os << xyz.asVec3i();
return os;
551 template <
typename T>
562 template <
typename T>
577 os << b.
min() <<
" -> " << b.
max();
592 struct hash<openvdb::math::Coord>
597 std::size_t
operator()(
const Coord& ijk)
const noexcept {
return ijk.Coord::hash<>(); }
602 #endif // OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED
Vec2< T > minComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise minimum of the two vectors.
void expand(const CoordBBox &bbox)
Union this bounding box with the given bounding box.
CoordBBox & operator<<=(size_t n)
Bit-wise operations performed on both the min and max members.
int Ceil(float x)
Return the ceiling of x.
bool operator==(const Iterator &other) const
Return true if this iterator and the given iterator point to the same coordinate. ...
Coord getEnd() const
Return the maximum coordinate plus one.
OIIO_FORCEINLINE const vint4 & operator>>=(vint4 &a, const unsigned int bits)
Vec3d getCenter() const
Return the floating-point position of the center of this bounding box.
void expand(const Coord &xyz)
Expand this bounding box to enclose point (x, y, z).
IMATH_HOSTDEVICE constexpr int floor(T x) IMATH_NOEXCEPT
void translate(const Coord &t)
Translate this bounding box by (tx, ty, tz).
static CoordBBox createCube(const Coord &min, ValueType dim)
size_t MaxIndex(const Vec3T &v)
Return the index [0,1,2] of the largest value in a 3D vector.
openvdb::math::Coord Coord
Coord dim() const
Return the dimensions of the coordinates spanned by this bounding box.
bool hasVolume() const
Return true if this bounding box is nonempty (i.e., encloses at least one coordinate).
Vec3< typename promote< T, Coord::ValueType >::type > operator-(const Vec3< T > &v0, const Coord &v1)
Allow a Coord to be subtracted from a Vec3.
GLdouble GLdouble GLdouble z
void intersect(const CoordBBox &bbox)
Intersect this bounding box with the given bounding box.
GLboolean GLboolean GLboolean GLboolean a
void getCornerPoints(Coord *p) const
Populates an array with the eight corner points of this bounding box.
#define OPENVDB_USE_VERSION_NAMESPACE
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
CoordBBox operator|(Coord::Int32 n) const
Bit-wise operations performed on both the min and max members.
size_t minExtent() const
Return the index (0, 1 or 2) of the shortest axis.
Iterator over the Coord domain covered by a CoordBBox.
**But if you need a result
bool empty() const
Return true if this bounding box is empty (i.e., encloses no coordinates).
Signed (x, y, z) 32-bit integer coordinates.
void read(T &in, bool &v)
std::numeric_limits< ValueType > Limits
OIIO_FORCEINLINE vbool4 operator>=(const vint4 &a, const vint4 &b)
void moveMax(const Coord &max)
Move this bounding box to the specified max.
Coord::ValueType ValueType
const Coord & min() const
void reset(const Coord &min, const Coord &max)
void resetToCube(const Coord &min, ValueType dim)
CoordBBox expandBy(ValueType padding) const
Return a new instance that is expanded by the specified padding.
CoordBBox()
The default constructor produces an empty bounding box.
bool operator!=(const Iterator &other) const
Return true if this iterator and the given iterator point to different coordinates.
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...
static CoordBBox inf()
Return an "infinite" bounding box, as defined by the Coord value range.
ZYXIterator begin() const
Return a ZYX-order iterator that points to the minimum coordinate.
OIIO_FORCEINLINE vbool4 operator<=(const vint4 &a, const vint4 &b)
size_t MinIndex(const Vec3T &v)
Return the index [0,1,2] of the smallest value in a 3D vector.
bool operator==(const CoordBBox &rhs) const
bool hasOverlap(const CoordBBox &b) const
Return true if the given bounding box overlaps with this bounding box.
CoordBBox operator&(Coord::Int32 n) const
Bit-wise operations performed on both the min and max members.
Coord Abs(const Coord &xyz)
OIIO_FORCEINLINE const vint4 & operator+=(vint4 &a, const vint4 &b)
CoordBBox & operator&=(Coord::Int32 n)
Bit-wise operations performed on both the min and max members.
Index64 volume() const
Return the integer volume of coordinates spanned by this bounding box.
float Round(float x)
Return x rounded to the nearest integer.
CoordBBox(const Coord &min, const Coord &max)
Construct a bounding box with the given min and max bounds.
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
void read(std::istream &is)
Unserialize this bounding box from the given stream.
Iterator(const CoordBBox &b)
C-tor from a bounding box.
void write(std::ostream &os) const
Serialize this bounding box to the given stream.
const Coord & max() const
Axis-aligned bounding box of signed integer coordinates.
CoordBBox operator<<(size_t n) const
Bit-wise operations performed on both the min and max members.
bool is_divisible() const
Return true if this bounding box can be subdivided [mainly for use by TBB].
bool isInside(const Coord &xyz) const
Return true if point (x, y, z) is inside this bounding box.
size_t maxExtent() const
Return the index (0, 1 or 2) of the longest axis.
OIIO_FORCEINLINE vint4 operator>>(const vint4 &a, const unsigned int bits)
vfloat4 round(const vfloat4 &a)
GLboolean GLboolean GLboolean b
bool operator>(const Tuple< SIZE, T0 > &t0, const Tuple< SIZE, T1 > &t1)
Coord getStart() const
Return the minimum coordinate.
void expand(ValueType padding)
Pad this bounding box with the specified padding.
Iterator & operator++()
Increment the iterator to point to the next coordinate.
std::size_t operator()(const Coord &ijk) const noexcept
CoordBBox & operator>>=(size_t n)
Bit-wise operations performed on both the min and max members.
ZYXIterator end() const
Return a ZYX-order iterator that points past the maximum coordinate.
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
OrtDmlDeviceFilter & operator&=(OrtDmlDeviceFilter &a, OrtDmlDeviceFilter b)
IMATH_HOSTDEVICE constexpr int ceil(T x) IMATH_NOEXCEPT
CoordBBox operator>>(size_t n) const
Bit-wise operations performed on both the min and max members.
XYZIterator beginXYZ() const
Return an XYZ-order iterator that points to the minimum coordinate.
OIIO_FORCEINLINE const vint4 & operator<<=(vint4 &a, const unsigned int bits)
XYZIterator endXYZ() const
Return an XYZ-order iterator that points past the maximum coordinate.
void moveMin(const Coord &min)
Move this bounding box to the specified min.
ZYXIterator beginZYX() const
Return a ZYX-order iterator that points to the minimum coordinate.
<< 7)-1u)) DEFINE_ISCACHED(2,((1u<< 12)-1u)) inlineint32_tcnanovdb_readaccessor_computeDirty(constcnanovdb_readaccessor *RESTRICTacc, constcnanovdb_coord *RESTRICTijk){return(ijk->mVec[0]^acc->mKey.mVec[0])|(ijk-> mVec[1] acc mKey mVec(ijk->mVec[2]^acc->mKey.mVec[2])
bool operator!=(const CoordBBox &rhs) const
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
Vec2< T > maxComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise maximum of the two vectors.
OIIO_FORCEINLINE const vint4 & operator-=(vint4 &a, const vint4 &b)
Vec3< typename promote< T, typename Coord::ValueType >::type > operator+(const Vec3< T > &v0, const Coord &v1)
Allow a Coord to be added to or subtracted from a Vec3.
int Floor(float x)
Return the floor of x.
CoordBBox(ValueType xMin, ValueType yMin, ValueType zMin, ValueType xMax, ValueType yMax, ValueType zMax)
Construct from individual components of the min and max bounds.
void OIIO_UTIL_API split(string_view str, std::vector< string_view > &result, string_view sep=string_view(), int maxsplit=-1)
bool isInside(const CoordBBox &b) const
Return true if the given bounding box is inside this bounding box.
void write(T &out, bool v)
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
ZYXIterator endZYX() const
Return a ZYX-order iterator that points past the maximum coordinate.
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
CoordBBox & operator|=(Coord::Int32 n)
Bit-wise operations performed on both the min and max members.
OrtDmlDeviceFilter & operator|=(OrtDmlDeviceFilter &a, OrtDmlDeviceFilter b)
CoordBBox(CoordBBox &other, const tbb::split &)
Splitting constructor for use in TBB ranges.
const Coord & operator*() const
Return a const reference to the coordinate currently pointed to.
std::ostream & operator<<(std::ostream &os, const BBox< Vec3T > &b)
bool operator<(const Tuple< SIZE, T0 > &t0, const Tuple< SIZE, T1 > &t1)