31 #ifndef OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED
32 #define OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED
34 #include <openvdb/Platform.h>
38 namespace tbb {
class split; }
56 typedef std::numeric_limits<ValueType>
Limits;
59 { mVec[0] = mVec[1] = mVec[2] = 0; }
61 { mVec[0] = mVec[1] = mVec[2] = xyz; }
62 Coord(Int32 x, Int32 y, Int32 z)
63 { mVec[0] = x; mVec[1] = y; mVec[2] = z; }
65 { mVec[0] = v[0]; mVec[1] = v[1]; mVec[2] = v[2]; }
67 { mVec[0] =
Int32(v[0]); mVec[1] =
Int32(v[1]); mVec[2] =
Int32(v[2]); }
69 { mVec[0] = v[0]; mVec[1] = v[1]; mVec[2] = v[2]; }
92 { mVec[0] = x; mVec[1] = y; mVec[2] = z; this->dirty();
return *
this; }
95 Coord&
setX(Int32 x) { mVec[0] = x; dirty();
return *
this; }
96 Coord&
setY(Int32 y) { mVec[1] = y; dirty();
return *
this; }
97 Coord&
setZ(Int32 z) { mVec[2] = z; dirty();
return *
this; }
100 { mVec[0]+=dx; mVec[1]+=dy; mVec[2]+=dz; this->dirty();
return *
this; }
103 {
return Coord(mVec[0] + dx, mVec[1] + dy, mVec[2] + dz); }
107 { mVec[0] += rhs[0]; mVec[1] += rhs[1]; mVec[2] += rhs[2];
return *
this; }
109 { mVec[0] -= rhs[0]; mVec[1] -= rhs[1]; mVec[2] -= rhs[2];
return *
this; }
111 {
return Coord(mVec[0] + rhs[0], mVec[1] + rhs[1], mVec[2] + rhs[2]); }
113 {
return Coord(mVec[0] - rhs[0], mVec[1] - rhs[1], mVec[2] - rhs[2]); }
116 Coord operator>> (
size_t n)
const {
return Coord(mVec[0]>>n, mVec[1]>>n, mVec[2]>>n); }
118 Coord&
operator<<=(
size_t n) { mVec[0]<<=n; mVec[1]<<=n; mVec[2]<<=n; dirty();
return *
this; }
119 Coord&
operator>>=(
size_t n) { mVec[0]>>=n; mVec[1]>>=n; mVec[2]>>=n; dirty();
return *
this; }
120 Coord operator& (Int32 n)
const {
return Coord(mVec[0] & n, mVec[1] & n, mVec[2] & n); }
121 Coord operator| (Int32 n)
const {
return Coord(mVec[0] | n, mVec[1] | n, mVec[2] | n); }
122 Coord& operator&= (Int32 n) { mVec[0]&=n; mVec[1]&=n; mVec[2]&=n; dirty();
return *
this; }
123 Coord& operator|= (Int32 n) { mVec[0]|=n; mVec[1]|=n; mVec[2]|=n; dirty();
return *
this; }
125 Int32
x()
const {
return mVec[0]; }
126 Int32
y()
const {
return mVec[1]; }
127 Int32
z()
const {
return mVec[2]; }
128 Int32
operator[](
size_t i)
const { assert(i < 3);
return mVec[i]; }
129 Int32&
x() { dirty();
return mVec[0]; }
130 Int32&
y() { dirty();
return mVec[1]; }
131 Int32&
z() { dirty();
return mVec[2]; }
132 Int32&
operator[](
size_t i) { assert(i < 3); dirty();
return mVec[i]; }
140 void asXYZ(Int32& x, Int32& y, Int32& z)
const { x = mVec[0]; y = mVec[1]; z = mVec[2]; }
143 {
return (mVec[0] == rhs.mVec[0] && mVec[1] == rhs.mVec[1] && mVec[2] == rhs.mVec[2]); }
149 return this->x() < rhs.
x() ?
true : this->x() > rhs.
x() ?
false
150 : this->y() < rhs.
y() ?
true : this->y() > rhs.
y() ?
false
151 : this->z() < rhs.
z() ?
true :
false;
156 return this->x() < rhs.
x() ?
true : this->x() > rhs.
x() ?
false
157 : this->y() < rhs.
y() ?
true : this->y() > rhs.
y() ?
false
158 : this->z() <=rhs.
z() ?
true :
false;
170 mVec[0] =
std::min(mVec[0], other.mVec[0]);
171 mVec[1] =
std::min(mVec[1], other.mVec[1]);
172 mVec[2] =
std::min(mVec[2], other.mVec[2]);
178 mVec[0] =
std::max(mVec[0], other.mVec[0]);
179 mVec[1] =
std::max(mVec[1], other.mVec[1]);
180 mVec[2] =
std::max(mVec[2], other.mVec[2]);
200 return (a[0] < b[0] || a[1] < b[1] || a[2] < b[2]);
209 void read(std::istream& is) { is.read(reinterpret_cast<char*>(mVec),
sizeof(mVec)); }
211 { os.write(reinterpret_cast<const char*>(mVec),
sizeof(mVec)); }
243 assert(this->is_divisible());
244 const size_t n = this->maxExtent();
245 mMax[n] = (mMin[n] + mMax[n]) >> 1;
246 other.mMin[n] = mMax[n] + 1;
275 bool empty()
const {
return (mMin[0] > mMax[0] || mMin[1] > mMax[1] || mMin[2] > mMax[2]); }
277 operator bool()
const {
return !this->empty(); }
295 const Coord d = this->dim();
299 bool is_divisible()
const {
return mMin[0]<mMax[0] && mMin[1]<mMax[1] && mMin[2]<mMax[2]; }
302 size_t minExtent()
const {
return this->dim().minIndex(); }
305 size_t maxExtent()
const {
return this->dim().maxIndex(); }
310 return !(Coord::lessThan(xyz,mMin) || Coord::lessThan(mMax,xyz));
316 return !(Coord::lessThan(b.mMin,mMin) || Coord::lessThan(mMax,b.mMax));
322 return !(Coord::lessThan(mMax,b.mMin) || Coord::lessThan(b.mMax,mMin));
328 mMin.offset(-padding);
329 mMax.offset( padding);
334 mMin.minComponent(xyz);
335 mMax.maxComponent(xyz);
340 mMin.minComponent(bbox.
min());
341 mMax.maxComponent(bbox.
max());
346 mMin.maxComponent(bbox.
min());
347 mMax.minComponent(bbox.
max());
353 mMin.minComponent(min);
354 mMax.maxComponent(min.
offsetBy(dim-1));
360 void read(std::istream& is) { mMin.read(is); mMax.read(is); }
362 void write(std::ostream& os)
const { mMin.write(os); mMax.write(os); }
374 os << xyz.
asVec3i();
return os;
381 inline Vec3<typename promote<T, typename Coord::ValueType>::type>
392 inline Vec3<typename promote<T, typename Coord::ValueType>::type>
405 template <
typename T>
407 inline Vec3<typename promote<T, Coord::ValueType>::type>
417 template <
typename T>
418 inline Vec3<typename promote<T, Coord::ValueType>::type>
432 os << b.
min() <<
" -> " << b.
max();
440 #endif // OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED
bool operator<(const Coord &rhs) const
Lexicographic less than.
Definition: Coord.h:147
bool operator==(const Coord &rhs) const
Definition: Coord.h:142
Coord(Int32 x, Int32 y, Int32 z)
Definition: Coord.h:62
Coord & setZ(Int32 z)
Definition: Coord.h:97
Coord()
Definition: Coord.h:58
Coord(const Vec3i &v)
Definition: Coord.h:64
Coord::ValueType ValueType
Definition: Coord.h:233
Coord dim() const
Return the dimensions of the coordinates spanned by this bounding box.
Definition: Coord.h:288
void expand(const CoordBBox &bbox)
Union this bounding box with the given bounding box.
Definition: Coord.h:338
CoordBBox(CoordBBox &other, const tbb::split &)
Splitting constructor for use in TBB ranges.
Definition: Coord.h:241
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
bool is_divisible() const
Return true if this bounding box can be subdivided [mainly for use by TBB].
Definition: Coord.h:299
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
Coord(Int32 xyz)
Definition: Coord.h:60
bool empty() const
Definition: Coord.h:275
uint64_t Index64
Definition: Types.h:58
static Coord min()
Return the smallest possible coordinate.
Definition: Coord.h:72
Vec3d asVec3d() const
Definition: Coord.h:136
Coord & operator>>=(size_t n)
Definition: Coord.h:119
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:229
Vec3< Index32 > Vec3I
Definition: Coord.h:53
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:393
Vec3I asVec3I() const
Definition: Coord.h:139
void read(std::istream &is)
Definition: Coord.h:209
std::ostream & operator<<(std::ostream &os, const CoordBBox &b)
Definition: Coord.h:430
Coord & operator-=(const Coord &rhs)
Definition: Coord.h:108
Coord operator-() const
Definition: Coord.h:114
Coord(const Int32 *v)
Definition: Coord.h:68
Coord(const Vec3I &v)
Definition: Coord.h:66
bool operator!=(const CoordBBox &rhs) const
Definition: Coord.h:273
std::numeric_limits< ValueType > Limits
Definition: Coord.h:56
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:47
Int32 x() const
Definition: Coord.h:125
void resetToCube(const Coord &min, ValueType dim)
Definition: Coord.h:265
static Coord maxComponent(const Coord &lhs, const Coord &rhs)
Return the component-wise maximum of the two Coords.
Definition: Coord.h:192
void expand(ValueType padding)
Pad this bounding box with the specified padding.
Definition: Coord.h:326
Vec3< int32_t > Vec3i
Definition: Vec3.h:626
size_t MaxIndex(const Vec3T &v)
Return the index [0,1,2] of the largest value in a 3D vector.
Definition: Math.h:877
int32_t Int32
Definition: Types.h:61
Coord & min()
Definition: Coord.h:260
Int32 & operator[](size_t i)
Definition: Coord.h:132
const Coord & min() const
Definition: Coord.h:257
Int32 & x()
Definition: Coord.h:129
void write(std::ostream &os) const
Serialize this bounding box to the given stream.
Definition: Coord.h:362
void expand(const Coord &xyz)
Expand this bounding box to enclose point (x, y, z).
Definition: Coord.h:332
bool isInside(const CoordBBox &b) const
Return true if the given bounding box is inside this bounding box.
Definition: Coord.h:314
Coord & operator<<=(size_t n)
Definition: Coord.h:118
math::Vec3< Index32 > Vec3I
Definition: Types.h:78
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Coord offsetBy(Int32 n) const
Definition: Coord.h:104
int32_t Int32
Definition: Coord.h:50
CoordBBox()
The default constructor produces an empty bounding box.
Definition: Coord.h:236
bool hasVolume() const
Return true if this bounding box is nonempty.
Definition: Coord.h:279
void asXYZ(Int32 &x, Int32 &y, Int32 &z) const
Definition: Coord.h:140
uint64_t Index64
Definition: Coord.h:232
size_t minIndex() const
Return the index (0, 1 or 2) with the smallest value.
Definition: Coord.h:204
void minComponent(const Coord &other)
Perform a component-wise minimum with the other Coord.
Definition: Coord.h:168
size_t minExtent() const
Return the index (0, 1 or 2) of the shortest axis.
Definition: Coord.h:302
Int32 & z()
Definition: Coord.h:131
Coord & setX(Int32 x)
Definition: Coord.h:95
Coord & operator+=(const Coord &rhs)
Definition: Coord.h:106
Coord operator-(const Coord &rhs) const
Definition: Coord.h:112
Coord & offset(Int32 dx, Int32 dy, Int32 dz)
Definition: Coord.h:99
static CoordBBox inf()
Return an "infinite" bounding box, as defined by the Coord value range.
Definition: Coord.h:255
Int32 operator[](size_t i) const
Definition: Coord.h:128
Definition: Exceptions.h:39
Coord & reset(Int32 xyz)
Definition: Coord.h:93
OPENVDB_API Hermite min(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
Int32 & y()
Definition: Coord.h:130
Coord getEnd() const
Definition: Coord.h:270
size_t maxExtent() const
Return the index (0, 1 or 2) of the longest axis.
Definition: Coord.h:305
size_t MinIndex(const Vec3T &v)
Return the index [0,1,2] of the smallest value in a 3D vector.
Definition: Math.h:856
CoordBBox(const Coord &min, const Coord &max)
Construct a bounding box with the given min and max bounds.
Definition: Coord.h:238
Vec3< double > Vec3d
Definition: Vec3.h:629
static Coord max()
Return the largest possible coordinate.
Definition: Coord.h:75
bool hasOverlap(const CoordBBox &b) const
Return true if the given bounding box overlaps with this bounding box.
Definition: Coord.h:320
void intersect(const CoordBBox &bbox)
Intersect this bounding box with the given bounding box.
Definition: Coord.h:344
bool operator>(const Coord &rhs) const
Lexicographic greater than.
Definition: Coord.h:161
Int32 ValueType
Definition: Coord.h:55
const Coord & max() const
Definition: Coord.h:258
bool operator>=(const Coord &rhs) const
Lexicographic greater than or equal to.
Definition: Coord.h:163
Int32 z() const
Definition: Coord.h:127
Index64 volume() const
Return the integer volume of coordinates spanned by this bounding box.
Definition: Coord.h:293
Coord & reset(Int32 x, Int32 y, Int32 z)
Definition: Coord.h:91
void translate(const Coord &t)
Translate this bounding box by .
Definition: Coord.h:357
bool operator==(const CoordBBox &rhs) const
Definition: Coord.h:272
Vec3d getCenter() const
Return the floating-point position of the center of this bounding box.
Definition: Coord.h:283
int Floor(float x)
Return the floor of x.
Definition: Math.h:780
static Coord minComponent(const Coord &lhs, const Coord &rhs)
Return the component-wise minimum of the two Coords.
Definition: Coord.h:184
int Ceil(float x)
Return the ceiling of x.
Definition: Math.h:788
Coord offsetBy(Int32 dx, Int32 dy, Int32 dz) const
Definition: Coord.h:102
OPENVDB_API Hermite max(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
static CoordBBox createCube(const Coord &min, ValueType dim)
Definition: Coord.h:249
bool operator<=(const Coord &rhs) const
Lexicographic less than or equal to.
Definition: Coord.h:154
Coord & setY(Int32 y)
Definition: Coord.h:96
static bool lessThan(const Coord &a, const Coord &b)
Definition: Coord.h:198
Int32 y() const
Definition: Coord.h:126
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:419
Int32 * asPointer()
Definition: Coord.h:135
void reset(const Coord &min, const Coord &max)
Definition: Coord.h:264
Vec3i asVec3i() const
Definition: Coord.h:138
bool operator!=(const Coord &rhs) const
Definition: Coord.h:144
static Coord round(const Vec3< T > &xyz)
Return xyz rounded to the closest integer coordinates (cell centered conversion). ...
Definition: Coord.h:79
Coord getStart() const
Definition: Coord.h:268
Coord extents() const
Definition: Coord.h:290
Vec3s asVec3s() const
Definition: Coord.h:137
void maxComponent(const Coord &other)
Perform a component-wise maximum with the other Coord.
Definition: Coord.h:176
uint32_t Index32
Definition: Types.h:57
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:88
float Round(float x)
Return x rounded to the nearest integer.
Definition: Math.h:751
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
uint32_t Index32
Definition: Coord.h:51
Vec3< float > Vec3s
Definition: Vec3.h:628
Coord operator+(const Coord &rhs) const
Definition: Coord.h:110
Coord & offset(Int32 n)
Definition: Coord.h:101
const Int32 * asPointer() const
Definition: Coord.h:134
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:351
Coord & max()
Definition: Coord.h:261
void read(std::istream &is)
Unserialize this bounding box from the given stream.
Definition: Coord.h:360
void reset()
Definition: Coord.h:263
size_t maxIndex() const
Return the index (0, 1 or 2) with the largest value.
Definition: Coord.h:207
Vec3< Int32 > Vec3i
Definition: Coord.h:52
void write(std::ostream &os) const
Definition: Coord.h:210
bool isInside(const Coord &xyz) const
Return true if point (x, y, z) is inside this bounding box.
Definition: Coord.h:308