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>;
36 explicit Coord(
Int32 xyz): mVec{{xyz, xyz, xyz}} {}
38 explicit Coord(
const Vec3i&
v): mVec{{v[0], v[1], v[2]}} {}
40 explicit Coord(
const Int32*
v): mVec{{v[0], v[1], v[2]}} {}
93 return Coord(mVec[0] + dx, mVec[1] + dy, mVec[2] + dz);
95 Coord offsetBy(
Int32 n)
const {
return offsetBy(n, n, n); }
113 return Coord(mVec[0] + rhs[0], mVec[1] + rhs[1], mVec[2] + rhs[2]);
117 return Coord(mVec[0] - rhs[0], mVec[1] - rhs[1], mVec[2] - rhs[2]);
125 Coord operator& (
Int32 n)
const {
return Coord(mVec[0] & n, mVec[1] & n, mVec[2] & n); }
126 Coord operator| (
Int32 n)
const {
return Coord(mVec[0] | n, mVec[1] | n, mVec[2] | n); }
130 Int32 x()
const {
return mVec[0]; }
131 Int32 y()
const {
return mVec[1]; }
132 Int32 z()
const {
return mVec[2]; }
133 Int32 operator[](
size_t i)
const { assert(i < 3);
return mVec[i]; }
134 Int32&
x() {
return mVec[0]; }
135 Int32&
y() {
return mVec[1]; }
136 Int32&
z() {
return mVec[2]; }
137 Int32& operator[](
size_t i) { assert(i < 3);
return mVec[i]; }
139 const Int32*
data()
const {
return mVec.data(); }
141 const Int32* asPointer()
const {
return mVec.data(); }
142 Int32* asPointer() {
return mVec.data(); }
143 Vec3d asVec3d()
const {
return Vec3d(
double(mVec[0]),
double(mVec[1]),
double(mVec[2])); }
144 Vec3s asVec3s()
const {
return Vec3s(
float(mVec[0]),
float(mVec[1]),
float(mVec[2])); }
145 Vec3i asVec3i()
const {
return Vec3i(mVec.data()); }
147 void asXYZ(
Int32&
x,
Int32&
y,
Int32&
z)
const { x = mVec[0]; y = mVec[1]; z = mVec[2]; }
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); }
177 mVec[0] =
std::min(mVec[0], other.mVec[0]);
178 mVec[1] =
std::min(mVec[1], other.mVec[1]);
179 mVec[2] =
std::min(mVec[2], other.mVec[2]);
185 mVec[0] =
std::max(mVec[0], other.mVec[0]);
186 mVec[1] =
std::max(mVec[1], other.mVec[1]);
187 mVec[2] =
std::max(mVec[2], other.mVec[2]);
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]);
214 size_t minIndex()
const {
return MinIndex(mVec); }
217 size_t maxIndex()
const {
return MaxIndex(mVec); }
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));
229 template<
int Log2N = 20>
232 const uint32_t* vec =
reinterpret_cast<const uint32_t*
>(mVec.data());
233 return ((1<<Log2N)-1) & (vec[0]*73856093 ^ vec[1]*19349663 ^ vec[2]*83492791);
237 std::array<Int32, 3> mVec;
257 template<
bool ZYXOrder>
268 operator bool()
const {
return ZYXOrder ? (mPos[0] <= mMax[0]) : (mPos[2] <= mMax[2]); }
274 return ((mPos == other.mPos) && (mMin == other.mMin) && (mMax == other.mMax));
279 template<
size_t a,
size_t b,
size_t c>
282 if (mPos[a] < mMax[a]) { ++mPos[
a]; }
283 else if (mPos[b] < mMax[b]) { mPos[
a] = mMin[
a]; ++mPos[
b]; }
284 else if (mPos[
c] <= mMax[
c]) { mPos[
a] = mMin[
a]; mPos[
b] = mMin[
b]; ++mPos[
c]; }
286 Coord mPos, mMin, mMax;
300 : mMin(xMin, yMin, zMin), mMax(xMax, yMax, zMax)
309 mMax[
n] = (mMin[
n] + mMax[
n]) >> 1;
310 other.mMin[
n] = mMax[
n] + 1;
315 return CoordBBox(min, min.offsetBy(dim - 1));
358 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
359 #pragma GCC diagnostic push
360 #pragma GCC diagnostic ignored "-Wstrict-overflow"
362 return (mMin[0] > mMax[0] || mMin[1] > mMax[1] || mMin[2] > mMax[2]);
363 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
364 #pragma GCC diagnostic pop
369 operator bool()
const {
return !this->
empty(); }
391 bool is_divisible()
const {
return mMin[0]<mMax[0] && mMin[1]<mMax[1] && mMin[2]<mMax[2]; }
402 return !(Coord::lessThan(xyz,mMin) || Coord::lessThan(mMax,xyz));
408 return !(Coord::lessThan(b.mMin,mMin) || Coord::lessThan(mMax,b.mMax));
414 return !(Coord::lessThan(mMax,b.mMin) || Coord::lessThan(b.mMax,mMin));
420 mMin.offset(-padding);
421 mMax.offset( padding);
427 return CoordBBox(mMin.offsetBy(-padding),mMax.offsetBy(padding));
433 mMin.minComponent(xyz);
434 mMax.maxComponent(xyz);
440 mMin.minComponent(bbox.
min());
441 mMax.maxComponent(bbox.
max());
446 mMin.maxComponent(bbox.
min());
447 mMax.minComponent(bbox.
max());
453 mMin.minComponent(min);
454 mMax.maxComponent(min.offsetBy(dim-1));
472 assert(p !=
nullptr);
473 p->reset(mMin.x(), mMin.y(), mMin.z()); ++
p;
474 p->reset(mMin.x(), mMin.y(), mMax.z()); ++
p;
475 p->reset(mMin.x(), mMax.y(), mMin.z()); ++
p;
476 p->reset(mMin.x(), mMax.y(), mMax.z()); ++
p;
477 p->reset(mMax.x(), mMin.y(), mMin.z()); ++
p;
478 p->reset(mMax.x(), mMin.y(), mMax.z()); ++
p;
479 p->reset(mMax.x(), mMax.y(), mMin.z()); ++
p;
480 p->reset(mMax.x(), mMax.y(), mMax.z());
496 void read(std::istream& is) { mMin.read(is); mMax.read(is); }
498 void write(std::ostream& os)
const { mMin.write(os); mMax.write(os); }
510 os << xyz.asVec3i();
return os;
549 template <
typename T>
560 template <
typename T>
575 os << b.
min() <<
" -> " << b.
max();
590 struct hash<openvdb::math::Coord>
595 std::size_t
operator()(
const Coord& ijk)
const noexcept {
return ijk.Coord::hash<>(); }
600 #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.
GLboolean GLboolean GLboolean b
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.
void intersect(const CoordBBox &bbox)
Intersect this bounding box with the given bounding box.
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.
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.
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.
GLboolean GLboolean GLboolean GLboolean a
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
GLdouble GLdouble GLdouble z
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)
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.
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)