31 #ifndef OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED
32 #define OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED
34 #include <openvdb/Platform.h>
54 typedef std::numeric_limits<ValueType>
Limits;
57 { mVec[0] = mVec[1] = mVec[2] = 0; }
59 { mVec[0] = mVec[1] = mVec[2] = xyz; }
61 { 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]; }
79 static_cast<int>(
Round(xyz[1])),
80 static_cast<int>(
Round(xyz[2])));
87 static_cast<int>(
Floor(xyz[1])),
88 static_cast<int>(
Floor(xyz[2])));
93 mVec[0] = x; mVec[1] = y; mVec[2] = z;
107 mVec[0]+=dx; mVec[1]+=dy; mVec[2]+=dz;
114 return Coord(mVec[0] + dx, mVec[1] + dy, mVec[2] + dz);
120 mVec[0] += rhs[0]; mVec[1] += rhs[1]; mVec[2] += rhs[2];
return *
this;
124 mVec[0] -= rhs[0]; mVec[1] -= rhs[1]; mVec[2] -= rhs[2];
return *
this;
128 return Coord(mVec[0] + rhs[0], mVec[1] + rhs[1], mVec[2] + rhs[2]);
132 return Coord(mVec[0] - rhs[0], mVec[1] - rhs[1], mVec[2] - rhs[2]);
136 Coord operator>> (
size_t n)
const {
return Coord(mVec[0]>>n, mVec[1]>>n, mVec[2]>>n); }
138 Coord&
operator<<=(
size_t n) { mVec[0]<<=n; mVec[1]<<=n; mVec[2]<<=n; dirty();
return *
this; }
139 Coord&
operator>>=(
size_t n) { mVec[0]>>=n; mVec[1]>>=n; mVec[2]>>=n; dirty();
return *
this; }
140 Coord operator& (
Int32 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) { mVec[0]&=n; mVec[1]&=n; mVec[2]&=n; dirty();
return *
this; }
143 Coord& operator|= (
Int32 n) { mVec[0]|=n; mVec[1]|=n; mVec[2]|=n; dirty();
return *
this; }
167 x =
static_cast<Index32>(mVec[0]);
168 y =
static_cast<Index32>(mVec[1]);
169 z =
static_cast<Index32>(mVec[2]);
174 return (mVec[0] == rhs.mVec[0] && mVec[1] == rhs.mVec[1] && mVec[2] == rhs.mVec[2]);
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;
186 bool operator<=(
const Coord& rhs)
const
188 return this->x() < rhs.
x() ?
true : this->x() > rhs.
x() ?
false
189 : this->y() < rhs.
y() ?
true : this->y() > rhs.
y() ?
false
190 : this->z() <=rhs.
z() ?
true :
false;
202 mVec[0] =
std::min(mVec[0], other.mVec[0]);
203 mVec[1] =
std::min(mVec[1], other.mVec[1]);
204 mVec[2] =
std::min(mVec[2], other.mVec[2]);
210 mVec[0] =
std::max(mVec[0], other.mVec[0]);
211 mVec[1] =
std::max(mVec[1], other.mVec[1]);
212 mVec[2] =
std::max(mVec[2], other.mVec[2]);
232 return (a[0] < b[0] || a[1] < b[1] || a[2] < b[2]);
234 void read(std::istream& is) { is.read(reinterpret_cast<char*>(mVec),
sizeof(mVec)); }
235 void write(std::ostream& os)
const
237 os.write(reinterpret_cast<const char*>(mVec),
sizeof(mVec));
287 mMin(min), mMax(min.offsetBy(dim-1)) {}
319 bool empty()
const {
return (mMin[0] > mMax[0] || mMin[1] > mMax[1] || mMin[2] > mMax[2]); }
320 operator bool()
const {
return !this->empty(); }
339 size_t maxExtent()
const
341 const Coord d = this->dim();
342 return (d[0] > d[1] && d[0] > d[2]) ? 0 : (d[1] > d[2]) ? 1 : 2;
346 bool isInside(
const Coord& xyz)
const
366 mMin.offset(-padding);
367 mMax.offset( padding);
372 mMin.minComponent(xyz);
373 mMax.maxComponent(xyz);
378 mMin.minComponent(bbox.
min());
379 mMax.maxComponent(bbox.
max());
384 mMin.minComponent(min);
385 mMax.maxComponent(min.
offsetBy(dim-1));
391 void read(std::istream& is) { mMin.read(is); mMax.read(is); }
393 void write(std::ostream& os)
const { mMin.write(os); mMax.write(os); }
405 os << xyz.
asVec3i();
return os;
412 inline Vec3<typename promote<T, typename Coord::ValueType>::type>
423 inline Vec3<typename promote<T, typename Coord::ValueType>::type>
437 template <
typename T>
438 inline Vec3<typename promote<T, Coord::ValueType>::type>
448 template <
typename T>
449 inline Vec3<typename promote<T, Coord::ValueType>::type>
463 os << b.
min() <<
" -> " << b.
max();
471 #endif // OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED