OpenVDB  2.1.0
Math.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2013 DreamWorks Animation LLC
4 //
5 // All rights reserved. This software is distributed under the
6 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
7 //
8 // Redistributions of source code must retain the above copyright
9 // and license notice and the following restrictions and disclaimer.
10 //
11 // * Neither the name of DreamWorks Animation nor the names of
12 // its contributors may be used to endorse or promote products derived
13 // from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
27 // LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
28 //
30 //
34 
35 #ifndef OPENVDB_MATH_HAS_BEEN_INCLUDED
36 #define OPENVDB_MATH_HAS_BEEN_INCLUDED
37 
38 #include <assert.h>
39 #include <algorithm> // for std::max()
40 #include <cmath> // for floor(), ceil() and sqrt()
41 #include <math.h> // for pow(), fabs() etc
42 #include <cstdlib> // for srand(), abs(int)
43 #include <limits> // for std::numeric_limits<Type>::max()
44 #include <string>
45 #include <boost/numeric/conversion/conversion_traits.hpp>
46 #include <boost/math/special_functions/cbrt.hpp>
47 #include <boost/random/mersenne_twister.hpp> // for boost::random::mt19937
48 #include <boost/random/uniform_01.hpp>
49 #include <boost/random/uniform_int.hpp>
50 #include <boost/version.hpp> // for BOOST_VERSION
51 #include <openvdb/Platform.h>
52 #include <openvdb/version.h>
53 
54 
55 // Compile pragmas
56 
57 // Intel(r) compiler fires remark #1572: floating-point equality and inequality
58 // comparisons are unrealiable when == or != is used with floating point operands.
59 #if defined(__INTEL_COMPILER)
60  #define OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN \
61  _Pragma("warning (push)") \
62  _Pragma("warning (disable:1572)")
63  #define OPENVDB_NO_FP_EQUALITY_WARNING_END \
64  _Pragma("warning (pop)")
65 #else
66  // For GCC, #pragma GCC diagnostic ignored "-Wfloat-equal"
67  // isn't working until gcc 4.2+,
68  // Trying
69  // #pragma GCC system_header
70  // creates other problems, most notably "warning: will never be executed"
71  // in from templates, unsure of how to work around.
72  // If necessary, could use integer based comparisons for equality
73  #define OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN
74  #define OPENVDB_NO_FP_EQUALITY_WARNING_END
75 #endif
76 
77 namespace openvdb {
79 namespace OPENVDB_VERSION_NAME {
80 
85 template<typename T> inline T zeroVal() { return T(0); }
87 template<> inline std::string zeroVal<std::string>() { return ""; }
89 template<> inline bool zeroVal<bool>() { return false; }
90 
92 
93 inline std::string operator+(const std::string& s, bool) { return s; }
96 inline std::string operator+(const std::string& s, int) { return s; }
97 inline std::string operator+(const std::string& s, float) { return s; }
98 inline std::string operator+(const std::string& s, double) { return s; }
100 
101 
102 namespace math {
103 
107 template<typename T> inline T negative(const T& val) { return T(-val); }
109 template<> inline bool negative(const bool& val) { return !val; }
111 template<> inline std::string negative(const std::string& val) { return val; }
112 
113 
115 template<typename T> struct Tolerance { static T value() { return zeroVal<T>(); } };
117 template<> struct Tolerance<float> { static float value() { return 1e-8f; } };
118 template<> struct Tolerance<double> { static double value() { return 1e-15; } };
120 
122 template<typename T> struct Delta { static T value() { return zeroVal<T>(); } };
124 template<> struct Delta<float> { static float value() { return 1e-5f; } };
125 template<> struct Delta<double> { static double value() { return 1e-9; } };
127 
128 
129 // ==========> Random Values <==================
130 
133 OPENVDB_DEPRECATED inline void randSeed(unsigned int seed) { srand(seed); }
134 
137 OPENVDB_DEPRECATED inline double randUniform() { return (double)(rand() / (RAND_MAX + 1.0)); }
138 
139 
142 template<typename FloatType = double, typename EngineType = boost::mt19937>
143 class Rand01
144 {
145 private:
146  EngineType mEngine;
147  boost::uniform_01<FloatType> mRand;
148 
149 public:
150  typedef FloatType ValueType;
151 
154  Rand01(unsigned int seed): mEngine(static_cast<typename EngineType::result_type>(seed)) {}
155 
157  FloatType operator()() { return mRand(mEngine); }
158 };
159 
161 
162 
165 template<typename EngineType = boost::mt19937>
166 class RandInt
167 {
168 private:
169 #if BOOST_VERSION >= 104700
170  typedef boost::random::uniform_int_distribution<int> Distr;
171 #else
172  typedef boost::uniform_int<int> Distr;
173 #endif
174  EngineType mEngine;
175  Distr mRand;
176 
177 public:
181  RandInt(unsigned int seed, int imin, int imax):
182  mEngine(static_cast<typename EngineType::result_type>(seed)),
183  mRand(std::min(imin, imax), std::max(imin, imax))
184  {}
185 
187  void setRange(int imin, int imax) { mRand = Distr(std::min(imin, imax), std::max(imin, imax)); }
188 
190  int operator()() { return mRand(mEngine); }
193  int operator()(int imin, int imax)
194  {
195  const int lo = std::min(imin, imax), hi = std::max(imin, imax);
196 #if BOOST_VERSION >= 104700
197  return mRand(mEngine, Distr::param_type(lo, hi));
198 #else
199  return Distr(lo, hi)(mEngine);
200 #endif
201  }
202 };
203 
205 
206 
207 // ==========> Clamp <==================
208 
210 template<typename Type>
211 inline Type
212 Clamp(Type x, Type min, Type max)
213 {
214  assert(min<max);
215  return x > min ? x < max ? x : max : min;
216 }
217 
218 
220 template<typename Type>
221 inline Type
222 Clamp01(Type x) { return x > Type(0) ? x < Type(1) ? x : Type(1) : Type(0); }
223 
224 
226 template<typename Type>
227 inline bool
228 ClampTest01(Type &x)
229 {
230  if (x >= Type(0) && x <= Type(1)) return false;
231  x = x < Type(0) ? Type(0) : Type(1);
232  return true;
233 }
234 
235 
238 template<typename Type>
239 inline Type
240 SmoothUnitStep(Type x, Type min, Type max)
241 {
242  assert(min < max);
243  const Type t = (x-min)/(max-min);
244  return t > 0 ? t < 1 ? (3-2*t)*t*t : Type(1) : Type(0);
245 }
246 
247 
248 // ==========> Absolute Value <==================
249 
250 
252 inline int32_t Abs(int32_t i) { return abs(i); }
254 inline int64_t Abs(int64_t i)
255 {
256 #ifdef _MSC_VER
257  return (i < int64_t(0) ? -i : i);
258 #else
259  return abs(i);
260 #endif
261 }
262 inline float Abs(float x) { return fabs(x); }
263 inline double Abs(double x) { return fabs(x); }
264 inline long double Abs(long double x) { return fabs(x); }
265 inline uint32_t Abs(uint32_t i) { return i; }
266 inline uint64_t Abs(uint64_t i) { return i; }
267 // On OSX size_t and uint64_t are different types
268 #if defined(__APPLE__) || defined(MACOSX)
269 inline size_t Abs(size_t i) { return i; }
270 #endif
271 
272 
273 
275 
276 
277 // ==========> Value Comparison <==================
278 
279 
281 template<typename Type>
282 inline bool
283 isZero(const Type& x)
284 {
286  return x == zeroVal<Type>();
288 }
289 
290 
293 template<typename Type>
294 inline bool
295 isApproxZero(const Type& x)
296 {
297  const Type tolerance = Type(zeroVal<Type>() + Tolerance<Type>::value());
298  return x < tolerance && x > -tolerance;
299 }
300 
302 template<typename Type>
303 inline bool
304 isApproxZero(const Type& x, const Type& tolerance)
305 {
306  return x < tolerance && x > -tolerance;
307 }
308 
309 
311 template<typename Type>
312 inline bool
313 isNegative(const Type& x) { return x < zeroVal<Type>(); }
314 
316 template<> inline bool isNegative<bool>(const bool&) { return false; }
317 
318 
321 template<typename Type>
322 inline bool
323 isApproxEqual(const Type& a, const Type& b)
324 {
325  const Type tolerance = Type(zeroVal<Type>() + Tolerance<Type>::value());
326  return !(Abs(a - b) > tolerance);
327 }
328 
329 
331 template<typename Type>
332 inline bool
333 isApproxEqual(const Type& a, const Type& b, const Type& tolerance)
334 {
335  return !(Abs(a - b) > tolerance);
336 }
337 
338 #define OPENVDB_EXACT_IS_APPROX_EQUAL(T) \
339  template<> inline bool isApproxEqual<T>(const T& a, const T& b) { return a == b; } \
340  template<> inline bool isApproxEqual<T>(const T& a, const T& b, const T&) { return a == b; } \
341 
342 
345 
346 
349 template<typename Type>
350 inline bool
351 isApproxLarger(const Type& a, const Type& b, const Type& tolerance)
352 {
353  return (b - a < tolerance);
354 }
355 
356 
358 template<typename T0, typename T1>
359 inline bool
360 isExactlyEqual(const T0& a, const T1& b)
361 {
363  return a == b;
365 }
366 
367 
368 template<typename Type>
369 inline bool
370 isRelOrApproxEqual(const Type& a, const Type& b, const Type& absTol, const Type& relTol)
371 {
372  // First check to see if we are inside the absolute tolerance
373  // Necessary for numbers close to 0
374  if (!(Abs(a - b) > absTol)) return true;
375 
376  // Next check to see if we are inside the relative tolerance
377  // to handle large numbers that aren't within the abs tolerance
378  // but could be the closest floating point representation
379  double relError;
380  if (Abs(b) > Abs(a)) {
381  relError = Abs((a - b) / b);
382  } else {
383  relError = Abs((a - b) / a);
384  }
385  return (relError <= relTol);
386 }
387 
388 template<>
389 inline bool
390 isRelOrApproxEqual(const bool& a, const bool& b, const bool&, const bool&)
391 {
392  return (a == b);
393 }
394 
395 
396 // Avoid strict aliasing issues by using type punning
397 // http://cellperformance.beyond3d.com/articles/2006/06/understanding-strict-aliasing.html
398 // Using "casting through a union(2)"
399 inline int32_t
400 floatToInt32(const float aFloatValue)
401 {
402  union FloatOrInt32 { float floatValue; int32_t int32Value; };
403  const FloatOrInt32* foi = reinterpret_cast<const FloatOrInt32*>(&aFloatValue);
404  return foi->int32Value;
405 }
406 
407 
408 inline int64_t
409 doubleToInt64(const double aDoubleValue)
410 {
411  union DoubleOrInt64 { double doubleValue; int64_t int64Value; };
412  const DoubleOrInt64* dol = reinterpret_cast<const DoubleOrInt64*>(&aDoubleValue);
413  return dol->int64Value;
414 }
415 
416 
417 // aUnitsInLastPlace is the allowed difference between the least significant digits
418 // of the numbers' floating point representation
419 // Please read refernce paper before trying to use isUlpsEqual
420 // http://www.cygnus-software.com/papers/comparingFloats/comparingFloats.htm
421 inline bool
422 isUlpsEqual(const double aLeft, const double aRight, const int64_t aUnitsInLastPlace)
423 {
424  int64_t longLeft = doubleToInt64(aLeft);
425  // Because of 2's complement, must restore lexicographical order
426  if (longLeft < 0) {
427  longLeft = INT64_C(0x8000000000000000) - longLeft;
428  }
429 
430  int64_t longRight = doubleToInt64(aRight);
431  // Because of 2's complement, must restore lexicographical order
432  if (longRight < 0) {
433  longRight = INT64_C(0x8000000000000000) - longRight;
434  }
435 
436  int64_t difference = labs(longLeft - longRight);
437  return (difference <= aUnitsInLastPlace);
438 }
439 
440 inline bool
441 isUlpsEqual(const float aLeft, const float aRight, const int32_t aUnitsInLastPlace)
442 {
443  int32_t intLeft = floatToInt32(aLeft);
444  // Because of 2's complement, must restore lexicographical order
445  if (intLeft < 0) {
446  intLeft = 0x80000000 - intLeft;
447  }
448 
449  int32_t intRight = floatToInt32(aRight);
450  // Because of 2's complement, must restore lexicographical order
451  if (intRight < 0) {
452  intRight = 0x80000000 - intRight;
453  }
454 
455  int32_t difference = abs(intLeft - intRight);
456  return (difference <= aUnitsInLastPlace);
457 }
458 
459 
461 
462 
463 // ==========> Pow <==================
464 
466 template<typename Type>
467 inline Type Pow2(Type x) { return x*x; }
468 
470 template<typename Type>
471 inline Type Pow3(Type x) { return x*x*x; }
472 
474 template<typename Type>
475 inline Type Pow4(Type x) { return Pow2(Pow2(x)); }
476 
478 template<typename Type>
479 Type
480 Pow(Type x, int n)
481 {
482  Type ans = 1;
483  if (n < 0) {
484  n = -n;
485  x = Type(1)/x;
486  }
487  while (n--) ans *= x;
488  return ans;
489 }
490 
492 inline float
494 Pow(float b, float e)
495 {
496  assert( b >= 0.0f && "Pow(float,float): base is negative" );
497  return powf(b,e);
498 }
499 
500 inline double
501 Pow(double b, double e)
502 {
503  assert( b >= 0.0 && "Pow(double,double): base is negative" );
504  return pow(b,e);
505 }
507 
508 
509 // ==========> Max <==================
510 
512 template<typename Type>
513 inline const Type&
514 Max(const Type& a, const Type& b)
515 {
516  return std::max(a,b) ;
517 }
518 
520 template<typename Type>
521 inline const Type&
522 Max(const Type& a, const Type& b, const Type& c)
523 {
524  return std::max( std::max(a,b), c ) ;
525 }
526 
528 template<typename Type>
529 inline const Type&
530 Max(const Type& a, const Type& b, const Type& c, const Type& d)
531 {
532  return std::max(std::max(a,b), std::max(c,d));
533 }
534 
536 template<typename Type>
537 inline const Type&
538 Max(const Type& a, const Type& b, const Type& c, const Type& d, const Type& e)
539 {
540  return std::max(std::max(a,b), Max(c,d,e));
541 }
542 
544 template<typename Type>
545 inline const Type&
546 Max(const Type& a, const Type& b, const Type& c, const Type& d, const Type& e, const Type& f)
547 {
548  return std::max(Max(a,b,c), Max(d,e,f));
549 }
550 
552 template<typename Type>
553 inline const Type&
554 Max(const Type& a, const Type& b, const Type& c, const Type& d,
555  const Type& e, const Type& f, const Type& g)
556 {
557  return std::max(Max(a,b,c,d), Max(e,f,g));
558 }
559 
561 template<typename Type>
562 inline const Type&
563 Max(const Type& a, const Type& b, const Type& c, const Type& d,
564  const Type& e, const Type& f, const Type& g, const Type& h)
565 {
566  return std::max(Max(a,b,c,d), Max(e,f,g,h));
567 }
568 
569 
570 // ==========> Min <==================
571 
573 template<typename Type>
574 inline const Type&
575 Min(const Type& a, const Type& b) { return std::min(a, b); }
576 
578 template<typename Type>
579 inline const Type&
580 Min(const Type& a, const Type& b, const Type& c) { return std::min(std::min(a, b), c); }
581 
583 template<typename Type>
584 inline const Type&
585 Min(const Type& a, const Type& b, const Type& c, const Type& d)
586 {
587  return std::min(std::min(a, b), std::min(c, d));
588 }
589 
591 template<typename Type>
592 inline const Type&
593 Min(const Type& a, const Type& b, const Type& c, const Type& d, const Type& e)
594 {
595  return std::min(std::min(a,b), Min(c,d,e));
596 }
597 
599 template<typename Type>
600 inline const Type&
601 Min(const Type& a, const Type& b, const Type& c, const Type& d, const Type& e, const Type& f)
602 {
603  return std::min(Min(a,b,c), Min(d,e,f));
604 }
605 
607 template<typename Type>
608 inline const Type&
609 Min(const Type& a, const Type& b, const Type& c, const Type& d,
610  const Type& e, const Type& f, const Type& g)
611 {
612  return std::min(Min(a,b,c,d), Min(e,f,g));
613 }
614 
616 template<typename Type>
617 inline const Type&
618 Min(const Type& a, const Type& b, const Type& c, const Type& d,
619  const Type& e, const Type& f, const Type& g, const Type& h)
620 {
621  return std::min(Min(a,b,c,d), Min(e,f,g,h));
622 }
623 
624 
626 
627 
629 template <typename Type>
630 inline int Sign(const Type &x) { return (zeroVal<Type>() < x) - (x < zeroVal<Type>()); }
631 
632 
635 template <typename Type>
636 inline bool
637 SignChange(const Type& a, const Type& b)
638 {
639  return ( (a<zeroVal<Type>()) ^ (b<zeroVal<Type>()) );
640 }
641 
642 
645 template <typename Type>
646 inline bool
647 ZeroCrossing(const Type& a, const Type& b)
648 {
649  return a * b <= zeroVal<Type>();
650 }
651 
652 
654 inline float Sqrt(float x) { return sqrtf(x); }
656 inline double Sqrt(double x) { return sqrt(x); }
657 inline long double Sqrt(long double x) { return sqrtl(x); }
659 
660 
662 inline float Cbrt(float x) { return boost::math::cbrt(x); }
664 inline double Cbrt(double x) { return boost::math::cbrt(x); }
665 inline long double Cbrt(long double x) { return boost::math::cbrt(x); }
667 
668 
670 inline int Mod(int x, int y) { return (x % y); }
672 inline float Mod(float x, float y) { return fmodf(x,y); }
673 inline double Mod(double x, double y) { return fmod(x,y); }
674 inline long double Mod(long double x, long double y) { return fmodl(x,y); }
675 template<typename Type> inline Type Remainder(Type x, Type y) { return Mod(x,y); }
677 
678 
680 inline float RoundUp(float x) { return ceilf(x); }
682 inline double RoundUp(double x) { return ceil(x); }
683 inline long double RoundUp(long double x) { return ceill(x); }
685 template<typename Type>
687 inline Type
688 RoundUp(Type x, Type base)
689 {
690  Type remainder = Remainder(x, base);
691  return remainder ? x-remainder+base : x;
692 }
693 
694 
696 inline float RoundDown(float x) { return floorf(x); }
698 inline double RoundDown(double x) { return floor(x); }
699 inline long double RoundDown(long double x) { return floorl(x); }
700 template <typename Type> inline Type Round(Type x) { return RoundDown(x+0.5); }
702 template<typename Type>
704 inline Type
705 RoundDown(Type x, Type base)
706 {
707  Type remainder = Remainder(x, base);
708  return remainder ? x-remainder : x;
709 }
710 
711 
713 template<typename Type>
714 inline Type
715 IntegerPart(Type x)
716 {
717  return (x > 0 ? RoundDown(x) : RoundUp(x));
718 }
719 
721 template<typename Type>
722 inline Type FractionalPart(Type x) { return Mod(x,Type(1)); }
723 
724 
726 inline int Floor(float x) { return (int)RoundDown(x); }
728 inline int Floor(double x) { return (int)RoundDown(x); }
729 inline int Floor(long double x) { return (int)RoundDown(x); }
731 
732 
734 inline int Ceil(float x) { return (int)RoundUp(x); }
736 inline int Ceil(double x) { return (int)RoundUp(x); }
737 inline int Ceil(long double x) { return (int)RoundUp(x); }
739 
740 
742 template<typename Type>
743 inline Type Chop(Type x, Type delta) { return (Abs(x) < delta ? zeroVal<Type>() : x); }
744 
745 
747 template<typename Type>
748 inline Type
749 Truncate(Type x, unsigned int digits)
750 {
751  Type tenth = Pow(10,digits);
752  return RoundDown(x*tenth+0.5)/tenth;
753 }
754 
755 
757 
758 
760 template<typename Type>
761 inline Type
762 Inv(Type x)
763 {
764  assert(x);
765  return Type(1)/x;
766 }
767 
768 
769 enum Axis {
770  X_AXIS = 0,
771  Y_AXIS = 1,
772  Z_AXIS = 2
773 };
774 
775 // enum values are consistent with their historical mx analogs.
785 };
786 
787 
788 template <typename S, typename T>
789 struct promote {
790  typedef typename boost::numeric::conversion_traits<S, T>::supertype type;
791 };
792 
793 
801 template<typename Vec3T>
802 size_t
803 MinIndex(const Vec3T& v)
804 {
805  static const size_t hashTable[8] = { 2, 1, 9, 1, 2, 9, 0, 0 };//9 is a dummy value
806  const size_t hashKey =
807  ((v[0] < v[1]) << 2) + ((v[0] < v[2]) << 1) + (v[1] < v[2]);// ?*4+?*2+?*1
808  return hashTable[hashKey];
809 }
810 
811 
819 template<typename Vec3T>
820 size_t
821 MaxIndex(const Vec3T& v)
822 {
823  static const size_t hashTable[8] = { 2, 1, 9, 1, 2, 9, 0, 0 };//9 is a dummy value
824  const size_t hashKey =
825  ((v[0] > v[1]) << 2) + ((v[0] > v[2]) << 1) + (v[1] > v[2]);// ?*4+?*2+?*1
826  return hashTable[hashKey];
827 }
828 
829 } // namespace math
830 } // namespace OPENVDB_VERSION_NAME
831 } // namespace openvdb
832 
833 #endif // OPENVDB_MATH_MATH_HAS_BEEN_INCLUDED
834 
835 // Copyright (c) 2012-2013 DreamWorks Animation LLC
836 // All rights reserved. This software is distributed under the
837 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
int operator()()
Return a randomly-generated integer in the current range.
Definition: Math.h:190
bool isApproxZero(const Type &x)
Return true if x is equal to zero to within the default floating-point comparison tolerance...
Definition: Math.h:295
Tolerance for floating-point comparison.
Definition: Math.h:116
FloatType operator()()
Return a uniformly distributed random number in the range [0, 1).
Definition: Math.h:157
#define OPENVDB_DEPRECATED
Definition: Platform.h:47
OPENVDB_API Hermite min(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
static float value()
Definition: Math.h:124
Definition: Math.h:771
OPENVDB_DEPRECATED double randUniform()
Definition: Math.h:137
int Mod(int x, int y)
Return the remainder of x / y.
Definition: Math.h:671
int Floor(float x)
Return the floor of x.
Definition: Math.h:727
int32_t floatToInt32(const float aFloatValue)
Definition: Math.h:400
int operator()(int imin, int imax)
Return a randomly-generated integer in the new range [imin, imax], without changing the current range...
Definition: Math.h:193
Type Clamp(Type x, Type min, Type max)
Return x clamped to [min, max].
Definition: Math.h:212
size_t MaxIndex(const Vec3T &v)
Return the index [0,1,2] of the largest value in a 3D vector.
Definition: Math.h:821
bool ZeroCrossing(const Type &a, const Type &b)
Return true if the interval [a, b] includes zero, i.e., if either a or b is zero or if they have diff...
Definition: Math.h:647
int32_t Abs(int32_t i)
Return the absolute value of the given quantity.
Definition: Math.h:253
T zeroVal()
Return the value of type T that corresponds to zero.
Definition: Math.h:85
Type Inv(Type x)
Return the inverse of x.
Definition: Math.h:762
Type Pow2(Type x)
Return .
Definition: Math.h:467
Delta for small floating-point offsets.
Definition: Math.h:123
bool ClampTest01(Type &x)
Return true if x is outside [0,1].
Definition: Math.h:228
FloatType ValueType
Definition: Math.h:150
Type Round(Type x)
Return x rounded down to the nearest integer.
Definition: Math.h:700
float Sqrt(float x)
Return the square root of a floating-point value.
Definition: Math.h:655
Type Clamp01(Type x)
Return x clamped to [0, 1].
Definition: Math.h:222
Simple random integer generator.
Definition: Math.h:166
float RoundDown(float x)
Return x rounded down to the nearest integer.
Definition: Math.h:697
RotationOrder
Definition: Math.h:776
int Sign(const Type &x)
Return the sign of the given value as an integer (either -1, 0 or 1).
Definition: Math.h:630
static float value()
Definition: Math.h:117
#define OPENVDB_VERSION_NAME
Definition: version.h:45
bool isNegative< bool >(const bool &)
Return false, since bool values are never less than zero.
Definition: Math.h:316
Simple generator of random numbers over the range [0, 1)
Definition: Math.h:143
float Cbrt(float x)
Return the cube root of a floating-point value.
Definition: Math.h:663
Type IntegerPart(Type x)
Return the integer part of x.
Definition: Math.h:715
static double value()
Definition: Math.h:118
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:360
Rand01< double, boost::mt19937 > Random01
Definition: Math.h:160
void setRange(int imin, int imax)
Change the range over which integers are distributed to [imin, imax].
Definition: Math.h:187
#define OPENVDB_NO_FP_EQUALITY_WARNING_END
Definition: Math.h:74
size_t MinIndex(const Vec3T &v)
Return the index [0,1,2] of the smallest value in a 3D vector.
Definition: Math.h:803
Type Pow(Type x, int n)
Return .
Definition: Math.h:480
OPENVDB_API Hermite max(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
Definition: Math.h:770
Rand01(unsigned int seed)
Initialize the generator.
Definition: Math.h:154
float RoundUp(float x)
Return x rounded up to the nearest integer.
Definition: Math.h:681
Type Remainder(Type x, Type y)
Return the remainder of x / y.
Definition: Math.h:675
RandInt(unsigned int seed, int imin, int imax)
Initialize the generator.
Definition: Math.h:181
boost::numeric::conversion_traits< S, T >::supertype type
Definition: Math.h:790
#define OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN
Definition: Math.h:73
bool zeroVal< bool >()
Return the bool value that corresponds to zero.
Definition: Math.h:89
int Ceil(float x)
Return the ceiling of x.
Definition: Math.h:735
const Type & Min(const Type &a, const Type &b)
Return the minimum of two values.
Definition: Math.h:575
bool SignChange(const Type &a, const Type &b)
Return true if a and b have different signs.
Definition: Math.h:637
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition: Math.h:283
bool isRelOrApproxEqual(const Type &a, const Type &b, const Type &absTol, const Type &relTol)
Definition: Math.h:370
OPENVDB_DEPRECATED void randSeed(unsigned int seed)
Definition: Math.h:133
Type Chop(Type x, Type delta)
Return x if it is greater in magnitude than delta. Otherwise, return zero.
Definition: Math.h:743
bool isApproxEqual(const Hermite &lhs, const Hermite &rhs)
Definition: Hermite.h:470
Type Pow3(Type x)
Return .
Definition: Math.h:471
bool isNegative(const Type &x)
Return true if x is less than zero.
Definition: Math.h:313
Vec3< typename promote< T, typename Coord::ValueType >::type > operator+(const Vec3< T > &v0, const Coord &v1)
Allow a Coord to be added to or subtracted from a Vec3.
Definition: Coord.h:382
Axis
Definition: Math.h:769
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:67
Definition: Math.h:789
Type SmoothUnitStep(Type x, Type min, Type max)
Return 0 if x &lt; min, 1 if x &gt; max or else , where .
Definition: Math.h:240
Definition: Math.h:772
T negative(const T &val)
Return the unary negation of the given value.
Definition: Math.h:107
int64_t doubleToInt64(const double aDoubleValue)
Definition: Math.h:409
RandInt< boost::mt19937 > RandomInt
Definition: Math.h:204
bool isApproxLarger(const Type &a, const Type &b, const Type &tolerance)
Return true if a is larger than b to within the given tolerance, i.e., if b - a &lt; tolerance...
Definition: Math.h:351
static double value()
Definition: Math.h:125
Type Truncate(Type x, unsigned int digits)
Return x truncated to the given number of decimal digits.
Definition: Math.h:749
#define OPENVDB_EXACT_IS_APPROX_EQUAL(T)
Definition: Math.h:338
const Type & Max(const Type &a, const Type &b)
Return the maximum of two values.
Definition: Math.h:514
Type FractionalPart(Type x)
Return the fractional part of x.
Definition: Math.h:722
Type Pow4(Type x)
Return .
Definition: Math.h:475
bool isUlpsEqual(const double aLeft, const double aRight, const int64_t aUnitsInLastPlace)
Definition: Math.h:422