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;
58 Coord() { mVec[0] = mVec[1] = mVec[2] = 0; }
59 explicit Coord(Int32 xyz) { mVec[0] = mVec[1] = mVec[2] = xyz; }
60 Coord(Int32 x, Int32 y, Int32 z) { mVec[0] = x; mVec[1] = y; mVec[2] = z; }
61 explicit Coord(
const Vec3i& v) { mVec[0] = v[0]; mVec[1] = v[1]; mVec[2] = v[2]; }
66 explicit Coord(
const Int32* v) { mVec[0] = v[0]; mVec[1] = v[1]; mVec[2] = v[2]; }
96 mVec[0] = x; mVec[1] = y; mVec[2] = z;
107 mVec[0]+=dx; mVec[1]+=dy; mVec[2]+=dz;
113 return Coord(mVec[0] + dx, mVec[1] + dy, mVec[2] + dz);
119 mVec[0] += rhs[0]; mVec[1] += rhs[1]; mVec[2] += rhs[2];
124 mVec[0] -= rhs[0]; mVec[1] -= rhs[1]; mVec[2] -= rhs[2];
129 return Coord(mVec[0] + rhs[0], mVec[1] + rhs[1], mVec[2] + rhs[2]);
133 return Coord(mVec[0] - rhs[0], mVec[1] - rhs[1], mVec[2] - rhs[2]);
137 Coord operator>> (
size_t n)
const {
return Coord(mVec[0]>>n, mVec[1]>>n, mVec[2]>>n); }
141 Coord operator& (Int32 n)
const {
return Coord(mVec[0] & n, mVec[1] & n, mVec[2] & n); }
142 Coord operator| (Int32 n)
const {
return Coord(mVec[0] | n, mVec[1] | n, mVec[2] | n); }
143 Coord& operator&= (Int32 n) { mVec[0]&=n; mVec[1]&=n; mVec[2]&=n;
return *
this; }
144 Coord& operator|= (Int32 n) { mVec[0]|=n; mVec[1]|=n; mVec[2]|=n;
return *
this; }
146 Int32
x()
const {
return mVec[0]; }
147 Int32
y()
const {
return mVec[1]; }
148 Int32
z()
const {
return mVec[2]; }
149 Int32
operator[](
size_t i)
const { assert(i < 3);
return mVec[i]; }
150 Int32&
x() {
return mVec[0]; }
151 Int32&
y() {
return mVec[1]; }
152 Int32&
z() {
return mVec[2]; }
153 Int32&
operator[](
size_t i) { assert(i < 3);
return mVec[i]; }
155 const Int32*
data()
const {
return mVec; }
163 void asXYZ(Int32& x, Int32& y, Int32& z)
const { x = mVec[0]; y = mVec[1]; z = mVec[2]; }
167 return (mVec[0] == rhs.mVec[0] && mVec[1] == rhs.mVec[1] && mVec[2] == rhs.mVec[2]);
174 return this->x() < rhs.
x() ?
true : this->x() > rhs.
x() ?
false 175 : this->y() < rhs.
y() ?
true : this->y() > rhs.
y() ?
false 176 : this->z() < rhs.
z() ?
true :
false;
181 return this->x() < rhs.
x() ?
true : this->x() > rhs.
x() ?
false 182 : this->y() < rhs.
y() ?
true : this->y() > rhs.
y() ?
false 183 : this->z() <=rhs.
z() ?
true :
false;
193 mVec[0] =
std::min(mVec[0], other.mVec[0]);
194 mVec[1] =
std::min(mVec[1], other.mVec[1]);
195 mVec[2] =
std::min(mVec[2], other.mVec[2]);
201 mVec[0] =
std::max(mVec[0], other.mVec[0]);
202 mVec[1] =
std::max(mVec[1], other.mVec[1]);
203 mVec[2] =
std::max(mVec[2], other.mVec[2]);
226 return (a[0] < b[0] || a[1] < b[1] || a[2] < b[2]);
235 void read(std::istream& is) { is.read(reinterpret_cast<char*>(mVec),
sizeof(mVec)); }
238 os.write(reinterpret_cast<const char*>(mVec),
sizeof(mVec));
278 ZYX ? this->next<2,1,0>() : this->next<0,1,2>();
282 operator bool()
const {
283 return ZYX ? mPos[0] <= mMax[0] : mPos[2] <= mMax[2];
288 template<
size_t a,
size_t b,
size_t c>
290 if ( mPos[a] < mMax[a] ) {
292 }
else if ( mPos[b] < mMax[b] ) {
295 }
else if ( mPos[c] <= mMax[c] ) {
301 Coord mPos, mMin, mMax;
309 CoordBBox(ValueType x_min, ValueType y_min, ValueType z_min,
310 ValueType x_max, ValueType y_max, ValueType z_max)
311 : mMin(x_min, y_min, z_min), mMax(x_max, y_max, z_max)
318 assert(this->is_divisible());
319 const size_t n = this->maxExtent();
320 mMax[n] = (mMin[n] + mMax[n]) >> 1;
321 other.mMin[n] = mMax[n] + 1;
350 bool empty()
const {
return (mMin[0] > mMax[0] || mMin[1] > mMax[1] || mMin[2] > mMax[2]); }
352 operator bool()
const {
return !this->empty(); }
370 const Coord d = this->dim();
374 bool is_divisible()
const {
return mMin[0]<mMax[0] && mMin[1]<mMax[1] && mMin[2]<mMax[2]; }
377 size_t minExtent()
const {
return this->dim().minIndex(); }
380 size_t maxExtent()
const {
return this->dim().maxIndex(); }
385 return !(Coord::lessThan(xyz,mMin) || Coord::lessThan(mMax,xyz));
391 return !(Coord::lessThan(b.mMin,mMin) || Coord::lessThan(mMax,b.mMax));
397 return !(Coord::lessThan(mMax,b.mMin) || Coord::lessThan(b.mMax,mMin));
403 mMin.offset(-padding);
404 mMax.offset( padding);
410 return CoordBBox(mMin.offsetBy(-padding),mMax.offsetBy(padding));
416 mMin.minComponent(xyz);
417 mMax.maxComponent(xyz);
423 mMin.minComponent(bbox.
min());
424 mMax.maxComponent(bbox.
max());
429 mMin.maxComponent(bbox.
min());
430 mMax.minComponent(bbox.
max());
436 mMin.minComponent(min);
437 mMax.maxComponent(min.
offsetBy(dim-1));
449 p->
reset(mMin.x(), mMin.y(), mMin.z()); ++p;
450 p->
reset(mMin.x(), mMin.y(), mMax.z()); ++p;
451 p->
reset(mMin.x(), mMax.y(), mMin.z()); ++p;
452 p->
reset(mMin.x(), mMax.y(), mMax.z()); ++p;
453 p->
reset(mMax.x(), mMin.y(), mMin.z()); ++p;
454 p->
reset(mMax.x(), mMin.y(), mMax.z()); ++p;
455 p->
reset(mMax.x(), mMax.y(), mMin.z()); ++p;
456 p->
reset(mMax.x(), mMax.y(), mMax.z());
472 void read(std::istream& is) { mMin.read(is); mMax.read(is); }
474 void write(std::ostream& os)
const { mMin.write(os); mMax.write(os); }
486 os << xyz.
asVec3i();
return os;
517 template <
typename T>
529 template <
typename T>
544 os << b.
min() <<
" -> " << b.
max();
552 #endif // OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED size_t minIndex() const
Return the index (0, 1 or 2) with the smallest value.
Definition: Coord.h:230
int32_t Int32
Definition: Coord.h:50
Vec3< float > Vec3s
Definition: Vec3.h:650
static Coord max()
Return the largest possible coordinate.
Definition: Coord.h:72
Coord Abs(const Coord &xyz)
Definition: Coord.h:247
bool isInside(const CoordBBox &b) const
Return true if the given bounding box is inside this bounding box.
Definition: Coord.h:389
void minComponent(const Coord &other)
Perform a component-wise minimum with the other Coord.
Definition: Coord.h:191
Int32 & z()
Definition: Coord.h:152
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:434
Coord & setX(Int32 x)
Definition: Coord.h:101
Coord & max()
Definition: Coord.h:336
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Coord & operator+=(const Coord &rhs)
Definition: Coord.h:117
Coord & offset(Int32 dx, Int32 dy, Int32 dz)
Definition: Coord.h:105
void read(std::istream &is)
Unserialize this bounding box from the given stream.
Definition: Coord.h:472
void reset()
Definition: Coord.h:338
Coord & reset(Int32 x, Int32 y, Int32 z)
Definition: Coord.h:94
size_t maxExtent() const
Return the index (0, 1 or 2) of the longest axis.
Definition: Coord.h:380
Int32 & y()
Definition: Coord.h:151
Coord operator-(const Coord &rhs) const
Definition: Coord.h:131
static Coord minComponent(const Coord &lhs, const Coord &rhs)
Return the component-wise minimum of the two Coords.
Definition: Coord.h:207
size_t minExtent() const
Return the index (0, 1 or 2) of the shortest axis.
Definition: Coord.h:377
void asXYZ(Int32 &x, Int32 &y, Int32 &z) const
Definition: Coord.h:163
Int32 ValueType
Definition: Coord.h:55
void expand(const Coord &xyz)
Expand this bounding box to enclose point (x, y, z).
Definition: Coord.h:414
Coord operator-() const
Definition: Coord.h:135
Coord::ValueType ValueType
Definition: Coord.h:263
bool is_divisible() const
Return true if this bounding box can be subdivided [mainly for use by TBB].
Definition: Coord.h:374
int Ceil(float x)
Return the ceiling of x.
Definition: Math.h:822
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:47
void expand(const CoordBBox &bbox)
Union this bounding box with the given bounding box.
Definition: Coord.h:421
CoordBBox(CoordBBox &other, const tbb::split &)
Splitting constructor for use in TBB ranges.
Definition: Coord.h:316
Coord getStart() const
Definition: Coord.h:343
void maxComponent(const Coord &other)
Perform a component-wise maximum with the other Coord.
Definition: Coord.h:199
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:89
size_t maxIndex() const
Return the index (0, 1 or 2) with the largest value.
Definition: Coord.h:233
bool operator==(const Coord &rhs) const
Definition: Coord.h:165
Vec3s asVec3s() const
Definition: Coord.h:160
const Coord & operator*() const
Return a const reference to the coordinate currently pointed to.
Definition: Coord.h:286
bool operator>=(const Coord &rhs) const
Lexicographic greater than or equal to.
Definition: Coord.h:188
Int32 x() const
Definition: Coord.h:146
Coord & offset(Int32 n)
Definition: Coord.h:110
bool operator==(const CoordBBox &rhs) const
Definition: Coord.h:347
Vec3< int32_t > Vec3i
Definition: Vec3.h:648
static CoordBBox inf()
Return an "infinite" bounding box, as defined by the Coord value range.
Definition: Coord.h:330
Coord & setY(Int32 y)
Definition: Coord.h:102
Vec3I asVec3I() const
Definition: Coord.h:162
Iterator & operator++()
Increments iterator to point to the next coordinate.
Definition: Coord.h:277
static bool lessThan(const Coord &a, const Coord &b)
Definition: Coord.h:224
Int32 * asPointer()
Definition: Coord.h:158
static Coord round(const Vec3< T > &xyz)
Return xyz rounded to the closest integer coordinates (cell centered conversion). ...
Definition: Coord.h:76
int32_t Int32
Definition: Types.h:60
uint64_t Index64
Definition: Types.h:57
bool operator<(const Coord &rhs) const
Lexicographic less than.
Definition: Coord.h:172
uint32_t Index32
Definition: Coord.h:51
bool operator!=(const Coord &rhs) const
Definition: Coord.h:169
std::ostream & operator<<(std::ostream &os, const CoordBBox &b)
Definition: Coord.h:542
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Vec3< double > Vec3d
Definition: Vec3.h:651
void resetToCube(const Coord &min, ValueType dim)
Definition: Coord.h:340
Coord & setZ(Int32 z)
Definition: Coord.h:103
void expand(ValueType padding)
Pad this bounding box with the specified padding.
Definition: Coord.h:401
Coord()
Definition: Coord.h:58
Coord(const Vec3i &v)
Definition: Coord.h:61
CoordBBox & operator>>=(size_t n)
Bit-wise operations performed on both the min and max members.
Definition: Coord.h:464
Index64 volume() const
Return the integer volume of coordinates spanned by this bounding box.
Definition: Coord.h:368
void getCornerPoints(Coord *p) const
Populates an array with the eight corner points of this bounding box.
Definition: Coord.h:446
Coord & min()
Definition: Coord.h:335
CoordBBox expandBy(ValueType padding) const
Return a new instance that is expanded by the specified padding.
Definition: Coord.h:408
Coord extents() const
Definition: Coord.h:365
math::Vec3< Index32 > Vec3I
Definition: Types.h:77
Vec3d asVec3d() const
Definition: Coord.h:159
Vec3< Int32 > Vec3i
Definition: Coord.h:52
void translate(const Coord &t)
Translate this bounding box by .
Definition: Coord.h:440
Int32 operator[](size_t i) const
Definition: Coord.h:149
Coord offsetBy(Int32 dx, Int32 dy, Int32 dz) const
Definition: Coord.h:111
static Coord floor(const Vec3< T > &xyz)
Return the largest integer coordinates that are not greater than xyz (node centered conversion)...
Definition: Coord.h:82
Definition: Exceptions.h:39
Iterator(const CoordBBox &b)
C-tor from a bounding box.
Definition: Coord.h:273
uint32_t Index32
Definition: Types.h:56
const Int32 * data() const
Definition: Coord.h:155
Coord(Int32 x, Int32 y, Int32 z)
Definition: Coord.h:60
Coord & operator>>=(size_t n)
Definition: Coord.h:140
Coord operator+(const Coord &rhs) const
Definition: Coord.h:127
Vec3< Index32 > Vec3I
Definition: Coord.h:53
Coord dim() const
Return the dimensions of the coordinates spanned by this bounding box.
Definition: Coord.h:363
CoordBBox()
The default constructor produces an empty bounding box.
Definition: Coord.h:305
Vec3i asVec3i() const
Definition: Coord.h:161
Int32 z() const
Definition: Coord.h:148
uint64_t Index64
Definition: Coord.h:262
bool operator!=(const CoordBBox &rhs) const
Definition: Coord.h:348
void write(std::ostream &os) const
Definition: Coord.h:236
Coord(const Vec3I &v)
Definition: Coord.h:62
std::numeric_limits< ValueType > Limits
Definition: Coord.h:56
const Coord & min() const
Definition: Coord.h:332
Coord(Int32 xyz)
Definition: Coord.h:59
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:505
bool operator>(const Coord &rhs) const
Lexicographic greater than.
Definition: Coord.h:186
static Coord maxComponent(const Coord &lhs, const Coord &rhs)
Return the component-wise maximum of the two Coords.
Definition: Coord.h:215
static Coord min()
Return the smallest possible coordinate.
Definition: Coord.h:69
int Floor(float x)
Return the floor of x.
Definition: Math.h:814
bool hasOverlap(const CoordBBox &b) const
Return true if the given bounding box overlaps with this bounding box.
Definition: Coord.h:395
const Coord & max() const
Definition: Coord.h:333
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:259
void read(std::istream &is)
Definition: Coord.h:235
Coord offsetBy(Int32 n) const
Definition: Coord.h:115
Coord & operator-=(const Coord &rhs)
Definition: Coord.h:122
Int32 y() const
Definition: Coord.h:147
bool operator<=(const Coord &rhs) const
Lexicographic less than or equal to.
Definition: Coord.h:179
size_t MaxIndex(const Vec3T &v)
Return the index [0,1,2] of the largest value in a 3D vector.
Definition: Math.h:911
CoordBBox(const Coord &min, const Coord &max)
Construct a bounding box with the given min and max bounds.
Definition: Coord.h:307
Int32 & x()
Definition: Coord.h:150
void intersect(const CoordBBox &bbox)
Intersect this bounding box with the given bounding box.
Definition: Coord.h:427
Coord(const Int32 *v)
Definition: Coord.h:66
Coord getEnd() const
Definition: Coord.h:345
Coord & operator<<=(size_t n)
Definition: Coord.h:139
Int32 * data()
Definition: Coord.h:156
bool isInside(const Coord &xyz) const
Return true if point (x, y, z) is inside this bounding box.
Definition: Coord.h:383
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
Iterator over Coord domain covered by a CoordBBox.
Definition: Coord.h:270
Int32 & operator[](size_t i)
Definition: Coord.h:153
void write(std::ostream &os) const
Serialize this bounding box to the given stream.
Definition: Coord.h:474
Vec3d getCenter() const
Return the floating-point position of the center of this bounding box.
Definition: Coord.h:358
bool empty() const
Definition: Coord.h:350
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:531
const Int32 * asPointer() const
Definition: Coord.h:157
size_t MinIndex(const Vec3T &v)
Return the index [0,1,2] of the smallest value in a 3D vector.
Definition: Math.h:890
bool hasVolume() const
Return true if this bounding box is nonempty.
Definition: Coord.h:354
float Round(float x)
Return x rounded to the nearest integer.
Definition: Math.h:785
CoordBBox(ValueType x_min, ValueType y_min, ValueType z_min, ValueType x_max, ValueType y_max, ValueType z_max)
Construct from individual components of the min and max bounds.
Definition: Coord.h:309
CoordBBox & operator<<=(size_t n)
Bit-wise operations performed on both the min and max members.
Definition: Coord.h:463
static CoordBBox createCube(const Coord &min, ValueType dim)
Definition: Coord.h:324
Coord & reset(Int32 xyz)
Definition: Coord.h:99
void reset(const Coord &min, const Coord &max)
Definition: Coord.h:339