4 #ifndef OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED
5 #define OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED
17 #include <tbb/blocked_range.h>
34 using Limits = std::numeric_limits<ValueType>;
96 Coord offsetBy(
Int32 n)
const {
return offsetBy(n, n, n); }
142 const Int32* asPointer()
const {
return mVec.data(); }
143 Int32* asPointer() {
return mVec.data(); }
152 return (
mVec[0] == rhs.mVec[0] &&
mVec[1] == rhs.mVec[1] &&
mVec[2] == rhs.mVec[2]);
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;
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;
171 bool operator>(
const Coord& rhs)
const {
return !(*
this <= rhs); }
209 static inline bool lessThan(
const Coord&
a,
const Coord&
b)
211 return (a[0] < b[0] || a[1] < b[1] || a[2] < b[2]);
220 void read(std::istream& is) { is.read(reinterpret_cast<char*>(
mVec.data()),
sizeof(
mVec)); }
221 void write(std::ostream& os)
const
223 os.write(reinterpret_cast<const char*>(
mVec.data()),
sizeof(
mVec));
232 template<
int Log2N = 20>
235 const uint32_t* vec =
reinterpret_cast<const uint32_t*
>(
mVec.data());
236 return ((1<<Log2N)-1) & (vec[0]*73856093 ^ vec[1]*19349669 ^ vec[2]*83492791);
240 std::array<Int32, 3>
mVec;
260 template<
bool ZYXOrder>
271 operator bool()
const {
return ZYXOrder ? (mPos[0] <= mMax[0]) : (mPos[2] <= mMax[2]); }
277 return ((mPos == other.mPos) && (mMin == other.mMin) && (mMax == other.mMax));
282 template<
size_t a,
size_t b,
size_t c>
285 if (mPos[a] < mMax[a]) { ++mPos[
a]; }
286 else if (mPos[b] < mMax[b]) { mPos[
a] = mMin[
a]; ++mPos[
b]; }
287 else if (mPos[
c] <= mMax[
c]) { mPos[
a] = mMin[
a]; mPos[
b] = mMin[
b]; ++mPos[
c]; }
289 Coord mPos, mMin, mMax;
303 : mMin(xMin, yMin, zMin), mMax(xMax, yMax, zMax)
312 mMax[
n] = (mMin[
n] + mMax[
n]) >> 1;
313 other.mMin[
n] = mMax[
n] + 1;
318 return CoordBBox(min, min.offsetBy(dim - 1));
361 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
362 #pragma GCC diagnostic push
363 #pragma GCC diagnostic ignored "-Wstrict-overflow"
365 return (mMin[0] > mMax[0] || mMin[1] > mMax[1] || mMin[2] > mMax[2]);
366 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
367 #pragma GCC diagnostic pop
394 bool is_divisible()
const {
return mMin[0]<mMax[0] && mMin[1]<mMax[1] && mMin[2]<mMax[2]; }
405 return !(Coord::lessThan(xyz,mMin) || Coord::lessThan(mMax,xyz));
411 return !(Coord::lessThan(b.mMin,mMin) || Coord::lessThan(mMax,b.mMax));
417 return !(Coord::lessThan(mMax,b.mMin) || Coord::lessThan(b.mMax,mMin));
423 mMin.offset(-padding);
424 mMax.offset( padding);
430 return CoordBBox(mMin.offsetBy(-padding),mMax.offsetBy(padding));
436 mMin.minComponent(xyz);
437 mMax.maxComponent(xyz);
443 mMin.minComponent(bbox.
min());
444 mMax.maxComponent(bbox.
max());
449 mMin.maxComponent(bbox.
min());
450 mMax.minComponent(bbox.
max());
456 mMin.minComponent(min);
457 mMax.maxComponent(min.offsetBy(dim-1));
476 p->reset(mMin.x(), mMin.y(), mMin.z()); ++p;
477 p->reset(mMin.x(), mMin.y(), mMax.z()); ++p;
478 p->reset(mMin.x(), mMax.y(), mMin.z()); ++p;
479 p->reset(mMin.x(), mMax.y(), mMax.z()); ++p;
480 p->reset(mMax.x(), mMin.y(), mMin.z()); ++p;
481 p->reset(mMax.x(), mMin.y(), mMax.z()); ++p;
482 p->reset(mMax.x(), mMax.y(), mMin.z()); ++p;
483 p->reset(mMax.x(), mMax.y(), mMax.z());
499 void read(std::istream& is) { mMin.read(is); mMax.read(is); }
501 void write(std::ostream& os)
const { mMin.write(os); mMax.write(os); }
513 os << xyz.asVec3i();
return os;
552 template <
typename T>
563 template <
typename T>
578 os << b.
min() <<
" -> " << b.
max();
593 struct hash<openvdb::math::Coord>
598 std::size_t
operator()(
const Coord& ijk)
const noexcept {
return ijk.Coord::hash<>(); }
603 #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.
std::enable_if< UT_EnableBitMask< T >::enable, T & >::type operator&=(T &lhs, T rhs)
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.
#define OPENVDB_ASSERT(X)
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.
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.
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::enable_if< UT_EnableBitMask< T >::enable, T & >::type operator|=(T &lhs, T rhs)
std::ostream & operator<<(std::ostream &os, const BBox< Vec3T > &b)
bool operator<(const Tuple< SIZE, T0 > &t0, const Tuple< SIZE, T1 > &t1)