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])));
95 return Coord(static_cast<int>(
Ceil(xyz[0])),
96 static_cast<int>(
Ceil(xyz[1])),
97 static_cast<int>(
Ceil(xyz[2])));
102 mVec[0] = x; mVec[1] = y; mVec[2] = z;
116 mVec[0]+=dx; mVec[1]+=dy; mVec[2]+=dz;
123 return Coord(mVec[0] + dx, mVec[1] + dy, mVec[2] + dz);
129 mVec[0] += rhs[0]; mVec[1] += rhs[1]; mVec[2] += rhs[2];
return *
this;
133 mVec[0] -= rhs[0]; mVec[1] -= rhs[1]; mVec[2] -= rhs[2];
return *
this;
137 return Coord(mVec[0] + rhs[0], mVec[1] + rhs[1], mVec[2] + rhs[2]);
141 return Coord(mVec[0] - rhs[0], mVec[1] - rhs[1], mVec[2] - rhs[2]);
145 Coord operator>> (
size_t n)
const {
return Coord(mVec[0]>>n, mVec[1]>>n, mVec[2]>>n); }
147 Coord&
operator<<=(
size_t n) { mVec[0]<<=n; mVec[1]<<=n; mVec[2]<<=n; dirty();
return *
this; }
148 Coord&
operator>>=(
size_t n) { mVec[0]>>=n; mVec[1]>>=n; mVec[2]>>=n; dirty();
return *
this; }
149 Coord operator& (
Int32 n)
const {
return Coord(mVec[0] & n, mVec[1] & n, mVec[2] & n); }
150 Coord operator| (
Int32 n)
const {
return Coord(mVec[0] | n, mVec[1] | n, mVec[2] | n); }
151 Coord& operator&= (
Int32 n) { mVec[0]&=n; mVec[1]&=n; mVec[2]&=n; dirty();
return *
this; }
152 Coord& operator|= (
Int32 n) { mVec[0]|=n; mVec[1]|=n; mVec[2]|=n; dirty();
return *
this; }
176 return (mVec[0] == rhs.mVec[0] && mVec[1] == rhs.mVec[1] && mVec[2] == rhs.mVec[2]);
183 return this->x() < rhs.
x() ?
true : this->x() > rhs.
x() ?
false
184 : this->y() < rhs.
y() ?
true : this->y() > rhs.
y() ?
false
185 : this->z() < rhs.
z() ?
true :
false;
188 bool operator<=(
const Coord& rhs)
const
190 return this->x() < rhs.
x() ?
true : this->x() > rhs.
x() ?
false
191 : this->y() < rhs.
y() ?
true : this->y() > rhs.
y() ?
false
192 : this->z() <=rhs.
z() ?
true :
false;
204 mVec[0] =
std::min(mVec[0], other.mVec[0]);
205 mVec[1] =
std::min(mVec[1], other.mVec[1]);
206 mVec[2] =
std::min(mVec[2], other.mVec[2]);
212 mVec[0] =
std::max(mVec[0], other.mVec[0]);
213 mVec[1] =
std::max(mVec[1], other.mVec[1]);
214 mVec[2] =
std::max(mVec[2], other.mVec[2]);
234 return (a[0] < b[0] || a[1] < b[1] || a[2] < b[2]);
236 void read(std::istream& is) { is.read(reinterpret_cast<char*>(mVec),
sizeof(mVec)); }
237 void write(std::ostream& os)
const
239 os.write(reinterpret_cast<const char*>(mVec),
sizeof(mVec));
297 bool empty()
const {
return (mMin[0] > mMax[0] || mMin[1] > mMax[1] || mMin[2] > mMax[2]); }
298 operator bool()
const {
return !this->empty(); }
317 size_t maxExtent()
const
319 const Coord d = this->dim();
320 return (d[0] > d[1] && d[0] > d[2]) ? 0 : (d[1] > d[2]) ? 1 : 2;
324 bool isInside(
const Coord& xyz)
const
344 mMin.offset(-padding);
345 mMax.offset( padding);
350 mMin.minComponent(xyz);
351 mMax.maxComponent(xyz);
356 mMin.minComponent(bbox.
min());
357 mMax.maxComponent(bbox.
max());
362 mMin.minComponent(min);
363 mMax.maxComponent(min.
offsetBy(dim-1));
369 void read(std::istream& is) { mMin.read(is); mMax.read(is); }
371 void write(std::ostream& os)
const { mMin.write(os); mMax.write(os); }
383 os << xyz.
asVec3i();
return os;
390 inline Vec3<typename promote<T, typename Coord::ValueType>::type>
401 inline Vec3<typename promote<T, typename Coord::ValueType>::type>
415 template <
typename T>
416 inline Vec3<typename promote<T, Coord::ValueType>::type>
426 template <
typename T>
427 inline Vec3<typename promote<T, Coord::ValueType>::type>
441 os << b.
min() <<
" -> " << b.
max();
449 #endif // OPENVDB_MATH_COORD_HAS_BEEN_INCLUDED