31 #ifndef OPENVDB_MATH_HERMITE_HAS_BEEN_INCLUDED
32 #define OPENVDB_MATH_HERMITE_HAS_BEEN_INCLUDED
34 #include <openvdb/Platform.h>
35 #include <openvdb/version.h>
78 operator bool()
const;
92 void setX(T offset,
const Vec3<T>&);
95 void setY(T offset,
const Vec3<T>&);
98 void setZ(T offset,
const Vec3<T>&);
103 bool isInside()
const {
return MASK_SIGN & mData; }
106 void setIsInside(
bool);
109 bool hasOffsetX()
const {
return mXNormal; };
117 bool isGreaterX(
const Hermite& other)
const;
120 bool isGreaterY(
const Hermite& other)
const;
121 bool isGreaterZ(
const Hermite& other)
const;
125 bool isLessX(
const Hermite& other)
const;
128 bool isLessY(
const Hermite& other)
const;
129 bool isLessZ(
const Hermite& other)
const;
133 float getOffsetX()
const;
135 float getOffsetY()
const;
136 float getOffsetZ()
const;
140 Vec3s getNormalX()
const {
return QuantizedUnitVec::unpack(mXNormal); }
155 std::string str()
const;
158 void read(std::istream&);
160 void write(std::ostream&)
const;
173 template <
typename T>
174 static uint32_t quantizeOffset(T offset);
178 static void getSignedOffsets(
const Hermite& lhs,
const Hermite& rhs,
179 const uint32_t bitmask,
int& lhsV,
int& rhsV);
184 static const uint32_t MASK_SIGN = 0x80000000;
186 static const uint32_t MASK_ZFLAG = 0x40000000;
188 static const uint32_t MASK_XSLOT = 0x3FF00000;
190 static const uint32_t MASK_YSLOT = 0x000FFC00;
192 static const uint32_t MASK_ZSLOT = 0x000003FF;
194 static const uint32_t MASK_SLOTS = 0x3FFFFFFF;
197 uint16_t mXNormal, mYNormal, mZNormal;
223 mXNormal = rhs.mXNormal;
224 mYNormal = rhs.mYNormal;
225 mZNormal = rhs.mZNormal;
245 Hermite::operator bool()
const
247 if (0 != (mXNormal | mYNormal))
return true;
255 if(mXNormal != rhs.mXNormal)
return false;
256 if(mYNormal != rhs.mYNormal)
return false;
257 if(mZNormal != rhs.mZNormal)
return false;
258 return mData == rhs.mData;
270 QuantizedUnitVec::flipSignBits(ret.mXNormal);
271 QuantizedUnitVec::flipSignBits(ret.mYNormal);
272 QuantizedUnitVec::flipSignBits(ret.mZNormal);
273 ret.mData = (~MASK_SIGN & ret.mData) | (MASK_SIGN & ~ret.mData);
282 template <
typename T>
284 Hermite::quantizeOffset(T offset)
287 assert(offset < 1.0);
288 assert(offset > -1.0e-8);
291 return uint32_t(1023 * offset) & MASK_ZSLOT;
296 const uint32_t bitmask,
int& lhsV,
int& rhsV)
298 lhsV = bitmask & lhs.mData;
299 rhsV = bitmask & rhs.mData;
310 template <
typename T>
314 mData &= ~MASK_XSLOT;
315 mData |= quantizeOffset(offset) << 20;
316 mXNormal = QuantizedUnitVec::pack(n);
319 template <
typename T>
323 mData &= ~MASK_YSLOT;
324 mData |= quantizeOffset(offset) << 10;
325 mYNormal = QuantizedUnitVec::pack(n);
328 template <
typename T>
332 mData &= ~MASK_ZSLOT;
333 mData |= MASK_ZFLAG | quantizeOffset(offset);
334 mZNormal = QuantizedUnitVec::pack(n);
346 mData |= uint32_t(isInside) * MASK_SIGN;
358 return float((mData >> 20) & MASK_ZSLOT) * 0.000977517;
364 return float((mData >> 10) & MASK_ZSLOT) * 0.000977517;
370 return float(mData & MASK_ZSLOT) * 0.000977517;
381 mData &= ~MASK_XSLOT;
382 mData |= MASK_XSLOT & rhs.mData;
383 mXNormal = rhs.mXNormal;
387 if(hasOffsetX() && isInside() != rhs.
isInside())
388 QuantizedUnitVec::flipSignBits(mXNormal);
394 mData &= ~MASK_YSLOT;
395 mData |= MASK_YSLOT & rhs.mData;
396 mYNormal = rhs.mYNormal;
398 if(hasOffsetY() && isInside() != rhs.
isInside())
399 QuantizedUnitVec::flipSignBits(mYNormal);
405 mData &= ~MASK_ZSLOT;
406 mData |= (MASK_ZFLAG | MASK_ZSLOT) & rhs.mData;
407 mZNormal = rhs.mZNormal;
408 if(hasOffsetZ() && isInside() != rhs.
isInside())
409 QuantizedUnitVec::flipSignBits(mZNormal);
421 getSignedOffsets(*
this, rhs, MASK_XSLOT, lhsV, rhsV);
429 getSignedOffsets(*
this, rhs, MASK_YSLOT, lhsV, rhsV);
437 getSignedOffsets(*
this, rhs, MASK_ZSLOT, lhsV, rhsV);
445 getSignedOffsets(*
this, rhs, MASK_XSLOT, lhsV, rhsV);
453 getSignedOffsets(*
this, rhs, MASK_YSLOT, lhsV, rhsV);
461 getSignedOffsets(*
this, rhs, MASK_ZSLOT, lhsV, rhsV);
489 #endif // OPENVDB_MATH_HERMITE_HAS_BEEN_INCLUDED
OPENVDB_API Hermite max(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
float getOffsetY() const
Definition: Hermite.h:362
float getOffsetZ() const
Definition: Hermite.h:368
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
float getOffsetX() const
Definition: Hermite.h:356
void setIsInside(bool)
Definition: Hermite.h:343
Vec3s getNormalZ() const
Definition: Hermite.h:143
bool isGreaterZ(const Hermite &other) const
Definition: Hermite.h:434
std::ostream & operator<<(std::ostream &os, const BBox< Vec3T > &b)
Definition: BBox.h:410
Vec3s getNormalY() const
Definition: Hermite.h:142
bool hasOffsetZ() const
Definition: Hermite.h:113
void setZ(T offset, const Vec3< T > &)
methods to compress and store edge data.
Definition: Hermite.h:330
Hermite operator-(const T &) const
Definition: Hermite.h:168
bool isLessY(const Hermite &other) const
Definition: Hermite.h:450
bool isLessZ(const Hermite &other) const
Definition: Hermite.h:458
const Hermite & operator=(const Hermite &)
Definition: Hermite.h:220
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:430
std::string str() const
String representation.
Hermite operator+(const T &) const
Definition: Hermite.h:167
#define OPENVDB_VERSION_NAME
Definition: version.h:45
bool isLessX(const Hermite &other) const
Definition: Hermite.h:442
void setX(T offset, const Vec3< T > &)
methods to compress and store edge data.
Definition: Hermite.h:312
OPENVDB_API Hermite min(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
void setY(T offset, const Vec3< T > &)
methods to compress and store edge data.
Definition: Hermite.h:321
bool operator==(const Hermite &) const
equality operator
Definition: Hermite.h:253
bool operator!=(const Hermite &rhs) const
inequality operator
Definition: Hermite.h:83
void clear()
clears all intersection data
Definition: Hermite.h:231
Quantized Hermite data object that stores compressed intersection information (offsets and normlas) f...
Definition: Hermite.h:66
Vec3< typename promote< T, Coord::ValueType >::type > operator-(const Vec3< T > &v0, const Coord &v1)
Allow a Coord to be subtracted from a Vec3.
Definition: Coord.h:408
Hermite operator-() const
unary negation operator, flips inside/outside state and normals.
Definition: Hermite.h:267
bool isGreaterX(const Hermite &other) const
Definition: Hermite.h:418
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:56
bool isApproxEqual(const Hermite &lhs, const Hermite &rhs)
Definition: Hermite.h:470
bool operator<(const Tuple< SIZE, T0 > &t0, const Tuple< SIZE, T1 > &t1)
Definition: Tuple.h:158
bool isGreaterY(const Hermite &other) const
Definition: Hermite.h:426
bool isInside() const
Definition: Hermite.h:103
math::Hermite Hermite
Definition: Types.h:104
bool hasOffsetY() const
Definition: Hermite.h:112
bool operator>(const Tuple< SIZE, T0 > &t0, const Tuple< SIZE, T1 > &t1)
Definition: Tuple.h:170