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; }
63 { mVec[0] = x; mVec[1] = y; mVec[2] = z; }
67 { mVec[0] = v[0]; mVec[1] = v[1]; mVec[2] = v[2]; }
69 { mVec[0] =
Int32(v[0]); mVec[1] =
Int32(v[1]); mVec[2] =
Int32(v[2]); }
71 { mVec[0] = v[0]; mVec[1] = v[1]; mVec[2] = v[2]; }
81 static_cast<int>(
Round(xyz[1])),
82 static_cast<int>(
Round(xyz[2])));
89 static_cast<int>(
Floor(xyz[1])),
90 static_cast<int>(
Floor(xyz[2])));
97 return Coord(static_cast<int>(
Ceil(xyz[0])),
98 static_cast<int>(
Ceil(xyz[1])),
99 static_cast<int>(
Ceil(xyz[2])));
104 mVec[0] = x; mVec[1] = y; mVec[2] = z;
118 mVec[0]+=dx; mVec[1]+=dy; mVec[2]+=dz;
125 return Coord(mVec[0] + dx, mVec[1] + dy, mVec[2] + dz);
131 mVec[0] += rhs[0]; mVec[1] += rhs[1]; mVec[2] += rhs[2];
return *
this;
135 mVec[0] -= rhs[0]; mVec[1] -= rhs[1]; mVec[2] -= rhs[2];
return *
this;
139 return Coord(mVec[0] + rhs[0], mVec[1] + rhs[1], mVec[2] + rhs[2]);
143 return Coord(mVec[0] - rhs[0], mVec[1] - rhs[1], mVec[2] - rhs[2]);
147 Coord operator>> (
size_t n)
const {
return Coord(mVec[0]>>n, mVec[1]>>n, mVec[2]>>n); }
149 Coord&
operator<<=(
size_t n) { mVec[0]<<=n; mVec[1]<<=n; mVec[2]<<=n; dirty();
return *
this; }
150 Coord&
operator>>=(
size_t n) { mVec[0]>>=n; mVec[1]>>=n; mVec[2]>>=n; dirty();
return *
this; }
151 Coord operator& (
Int32 n)
const {
return Coord(mVec[0] & n, mVec[1] & n, mVec[2] & n); }
152 Coord operator| (
Int32 n)
const {
return Coord(mVec[0] | n, mVec[1] | n, mVec[2] | n); }
153 Coord& operator&= (
Int32 n) { mVec[0]&=n; mVec[1]&=n; mVec[2]&=n; dirty();
return *
this; }
154 Coord& operator|= (
Int32 n) { mVec[0]|=n; mVec[1]|=n; mVec[2]|=n; dirty();
return *
this; }
178 return (mVec[0] == rhs.mVec[0] && mVec[1] == rhs.mVec[1] && mVec[2] == rhs.mVec[2]);
185 return this->x() < rhs.
x() ?
true : this->x() > rhs.
x() ?
false
186 : this->y() < rhs.
y() ?
true : this->y() > rhs.
y() ?
false
187 : this->z() < rhs.
z() ?
true :
false;
192 return this->x() < rhs.
x() ?
true : this->x() > rhs.
x() ?
false
193 : this->y() < rhs.
y() ?
true : this->y() > rhs.
y() ?
false
194 : this->z() <=rhs.
z() ?
true :
false;
206 mVec[0] =
std::min(mVec[0], other.mVec[0]);
207 mVec[1] =
std::min(mVec[1], other.mVec[1]);
208 mVec[2] =
std::min(mVec[2], other.mVec[2]);
214 mVec[0] =
std::max(mVec[0], other.mVec[0]);
215 mVec[1] =
std::max(mVec[1], other.mVec[1]);
216 mVec[2] =
std::max(mVec[2], other.mVec[2]);
236 return (a[0] < b[0] || a[1] < b[1] || a[2] < b[2]);
245 void read(std::istream& is) { is.read(reinterpret_cast<char*>(mVec),
sizeof(mVec)); }
248 os.write(reinterpret_cast<const char*>(mVec),
sizeof(mVec));
281 assert(this->is_divisible());
282 const size_t n = this->maxExtent();
283 mMax[n] = (mMin[n] + mMax[n]) >> 1;
284 other.mMin[n] = mMax[n] + 1;
312 bool empty()
const {
return (mMin[0] > mMax[0] || mMin[1] > mMax[1] || mMin[2] > mMax[2]); }
314 operator bool()
const {
return !this->empty(); }
332 const Coord d = this->dim();
336 bool is_divisible()
const {
return mMin[0]<mMax[0] && mMin[1]<mMax[1] && mMin[2]<mMax[2]; }
339 size_t minExtent()
const {
return this->dim().minIndex(); }
342 size_t maxExtent()
const {
return this->dim().maxIndex(); }
365 mMin.offset(-padding);
366 mMax.offset( padding);
371 mMin.minComponent(xyz);
372 mMax.maxComponent(xyz);
377 mMin.minComponent(bbox.
min());
378 mMax.maxComponent(bbox.
max());
383 mMin.maxComponent(bbox.
min());
384 mMax.minComponent(bbox.
max());
390 mMin.minComponent(min);
391 mMax.maxComponent(min.
offsetBy(dim-1));
397 void read(std::istream& is) { mMin.read(is); mMax.read(is); }
399 void write(std::ostream& os)
const { mMin.write(os); mMax.write(os); }
412 os << xyz.
asVec3i();
return os;
419 inline Vec3<typename promote<T, typename Coord::ValueType>::type>
430 inline Vec3<typename promote<T, typename Coord::ValueType>::type>
443 template <
typename T>
445 inline Vec3<typename promote<T, Coord::ValueType>::type>
455 template <
typename T>
456 inline Vec3<typename promote<T, Coord::ValueType>::type>
470 os << b.
min() <<
" -> " << b.
max();
478 #endif // OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED