OpenVDB  2.0.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 
121 
122 // ==========> Random Values <==================
123 
126 OPENVDB_DEPRECATED inline void randSeed(unsigned int seed) { srand(seed); }
127 
130 OPENVDB_DEPRECATED inline double randUniform() { return (double)(rand() / (RAND_MAX + 1.0)); }
131 
132 
135 template<typename FloatType = double, typename EngineType = boost::mt19937>
136 class Rand01
137 {
138 private:
139  EngineType mEngine;
140  boost::uniform_01<FloatType> mRand;
141 
142 public:
143  typedef FloatType ValueType;
144 
147  Rand01(unsigned int seed): mEngine(static_cast<typename EngineType::result_type>(seed)) {}
148 
150  FloatType operator()() { return mRand(mEngine); }
151 };
152 
154 
155 
158 template<typename EngineType = boost::mt19937>
159 class RandInt
160 {
161 private:
162 #if BOOST_VERSION >= 104700
163  typedef boost::random::uniform_int_distribution<int> Distr;
164 #else
165  typedef boost::uniform_int<int> Distr;
166 #endif
167  EngineType mEngine;
168  Distr mRand;
169 
170 public:
174  RandInt(unsigned int seed, int imin, int imax):
175  mEngine(static_cast<typename EngineType::result_type>(seed)),
176  mRand(std::min(imin, imax), std::max(imin, imax))
177  {}
178 
180  void setRange(int imin, int imax) { mRand = Distr(std::min(imin, imax), std::max(imin, imax)); }
181 
183  int operator()() { return mRand(mEngine); }
186  int operator()(int imin, int imax)
187  {
188  const int lo = std::min(imin, imax), hi = std::max(imin, imax);
189 #if BOOST_VERSION >= 104700
190  return mRand(mEngine, Distr::param_type(lo, hi));
191 #else
192  return Distr(lo, hi)(mEngine);
193 #endif
194  }
195 };
196 
198 
199 
200 // ==========> Clamp <==================
201 
203 template<typename Type>
204 inline Type
205 Clamp(Type x, Type min, Type max)
206 {
207  assert(min<max);
208  return x > min ? x < max ? x : max : min;
209 }
210 
211 
213 template<typename Type>
214 inline Type
215 Clamp01(Type x) { return x > Type(0) ? x < Type(1) ? x : Type(1) : Type(0); }
216 
217 
219 template<typename Type>
220 inline bool
221 ClampTest01(Type &x)
222 {
223  if (x >= Type(0) && x <= Type(1)) return false;
224  x = x < Type(0) ? Type(0) : Type(1);
225  return true;
226 }
227 
228 
231 template<typename Type>
232 inline Type
233 SmoothUnitStep(Type x, Type min, Type max)
234 {
235  assert(min < max);
236  const Type t = (x-min)/(max-min);
237  return t > 0 ? t < 1 ? (3-2*t)*t*t : Type(1) : Type(0);
238 }
239 
240 
241 // ==========> Absolute Value <==================
242 
243 
245 inline int32_t Abs(int32_t i) { return abs(i); }
247 inline int64_t Abs(int64_t i)
248 {
249 #ifdef _MSC_VER
250  return (i < int64_t(0) ? -i : i);
251 #else
252  return abs(i);
253 #endif
254 }
255 inline float Abs(float x) { return fabs(x); }
256 inline double Abs(double x) { return fabs(x); }
257 inline long double Abs(long double x) { return fabs(x); }
258 inline uint32_t Abs(uint32_t i) { return i; }
259 inline uint64_t Abs(uint64_t i) { return i; }
260 // On OSX size_t and uint64_t are different types
261 #if defined(__APPLE__) || defined(MACOSX)
262 inline size_t Abs(size_t i) { return i; }
263 #endif
264 
265 
266 
268 
269 
270 // ==========> Value Comparison <==================
271 
272 
274 template<typename Type>
275 inline bool
276 isZero(const Type& x)
277 {
279  return x == zeroVal<Type>();
281 }
282 
283 
286 template<typename Type>
287 inline bool
288 isApproxZero(const Type& x)
289 {
290  const Type tolerance = Type(zeroVal<Type>() + Tolerance<Type>::value());
291  return x < tolerance && x > -tolerance;
292 }
293 
295 template<typename Type>
296 inline bool
297 isApproxZero(const Type& x, const Type& tolerance)
298 {
299  return x < tolerance && x > -tolerance;
300 }
301 
302 
304 template<typename Type>
305 inline bool
306 isNegative(const Type& x) { return x < zeroVal<Type>(); }
307 
309 template<> inline bool isNegative<bool>(const bool&) { return false; }
310 
311 
314 template<typename Type>
315 inline bool
316 isApproxEqual(const Type& a, const Type& b)
317 {
318  const Type tolerance = Type(zeroVal<Type>() + Tolerance<Type>::value());
319  return !(Abs(a - b) > tolerance);
320 }
321 
322 
324 template<typename Type>
325 inline bool
326 isApproxEqual(const Type& a, const Type& b, const Type& tolerance)
327 {
328  return !(Abs(a - b) > tolerance);
329 }
330 
331 #define OPENVDB_EXACT_IS_APPROX_EQUAL(T) \
332  template<> inline bool isApproxEqual<T>(const T& a, const T& b) { return a == b; } \
333  template<> inline bool isApproxEqual<T>(const T& a, const T& b, const T&) { return a == b; } \
334 
335 
338 
339 
342 template<typename Type>
343 inline bool
344 isApproxLarger(const Type& a, const Type& b, const Type& tolerance)
345 {
346  return (b - a < tolerance);
347 }
348 
349 
351 template<typename T0, typename T1>
352 inline bool
353 isExactlyEqual(const T0& a, const T1& b)
354 {
356  return a == b;
358 }
359 
360 
361 template<typename Type>
362 inline bool
363 isRelOrApproxEqual(const Type& a, const Type& b, const Type& absTol, const Type& relTol)
364 {
365  // First check to see if we are inside the absolute tolerance
366  // Necessary for numbers close to 0
367  if (!(Abs(a - b) > absTol)) return true;
368 
369  // Next check to see if we are inside the relative tolerance
370  // to handle large numbers that aren't within the abs tolerance
371  // but could be the closest floating point representation
372  double relError;
373  if (Abs(b) > Abs(a)) {
374  relError = Abs((a - b) / b);
375  } else {
376  relError = Abs((a - b) / a);
377  }
378  return (relError <= relTol);
379 }
380 
381 template<>
382 inline bool
383 isRelOrApproxEqual(const bool& a, const bool& b, const bool&, const bool&)
384 {
385  return (a == b);
386 }
387 
388 
389 // Avoid strict aliasing issues by using type punning
390 // http://cellperformance.beyond3d.com/articles/2006/06/understanding-strict-aliasing.html
391 // Using "casting through a union(2)"
392 inline int32_t
393 floatToInt32(const float aFloatValue)
394 {
395  union FloatOrInt32 { float floatValue; int32_t int32Value; };
396  const FloatOrInt32* foi = reinterpret_cast<const FloatOrInt32*>(&aFloatValue);
397  return foi->int32Value;
398 }
399 
400 
401 inline int64_t
402 doubleToInt64(const double aDoubleValue)
403 {
404  union DoubleOrInt64 { double doubleValue; int64_t int64Value; };
405  const DoubleOrInt64* dol = reinterpret_cast<const DoubleOrInt64*>(&aDoubleValue);
406  return dol->int64Value;
407 }
408 
409 
410 // aUnitsInLastPlace is the allowed difference between the least significant digits
411 // of the numbers' floating point representation
412 // Please read refernce paper before trying to use isUlpsEqual
413 // http://www.cygnus-software.com/papers/comparingFloats/comparingFloats.htm
414 inline bool
415 isUlpsEqual(const double aLeft, const double aRight, const int64_t aUnitsInLastPlace)
416 {
417  int64_t longLeft = doubleToInt64(aLeft);
418  // Because of 2's complement, must restore lexicographical order
419  if (longLeft < 0) {
420  longLeft = INT64_C(0x8000000000000000) - longLeft;
421  }
422 
423  int64_t longRight = doubleToInt64(aRight);
424  // Because of 2's complement, must restore lexicographical order
425  if (longRight < 0) {
426  longRight = INT64_C(0x8000000000000000) - longRight;
427  }
428 
429  int64_t difference = labs(longLeft - longRight);
430  return (difference <= aUnitsInLastPlace);
431 }
432 
433 inline bool
434 isUlpsEqual(const float aLeft, const float aRight, const int32_t aUnitsInLastPlace)
435 {
436  int32_t intLeft = floatToInt32(aLeft);
437  // Because of 2's complement, must restore lexicographical order
438  if (intLeft < 0) {
439  intLeft = 0x80000000 - intLeft;
440  }
441 
442  int32_t intRight = floatToInt32(aRight);
443  // Because of 2's complement, must restore lexicographical order
444  if (intRight < 0) {
445  intRight = 0x80000000 - intRight;
446  }
447 
448  int32_t difference = abs(intLeft - intRight);
449  return (difference <= aUnitsInLastPlace);
450 }
451 
452 
454 
455 
456 // ==========> Pow <==================
457 
459 template<typename Type>
460 inline Type Pow2(Type x) { return x*x; }
461 
463 template<typename Type>
464 inline Type Pow3(Type x) { return x*x*x; }
465 
467 template<typename Type>
468 inline Type Pow4(Type x) { return Pow2(Pow2(x)); }
469 
471 template<typename Type>
472 Type
473 Pow(Type x, int n)
474 {
475  Type ans = 1;
476  if (n < 0) {
477  n = -n;
478  x = Type(1)/x;
479  }
480  while (n--) ans *= x;
481  return ans;
482 }
483 
485 inline float
487 Pow(float b, float e)
488 {
489  assert( b >= 0.0f && "Pow(float,float): base is negative" );
490  return powf(b,e);
491 }
492 
493 inline double
494 Pow(double b, double e)
495 {
496  assert( b >= 0.0 && "Pow(double,double): base is negative" );
497  return pow(b,e);
498 }
500 
501 
502 // ==========> Max <==================
503 
505 template<typename Type>
506 inline const Type&
507 Max(const Type& a, const Type& b)
508 {
509  return std::max(a,b) ;
510 }
511 
513 template<typename Type>
514 inline const Type&
515 Max(const Type& a, const Type& b, const Type& c)
516 {
517  return std::max( std::max(a,b), c ) ;
518 }
519 
521 template<typename Type>
522 inline const Type&
523 Max(const Type& a, const Type& b, const Type& c, const Type& d)
524 {
525  return std::max(std::max(a,b), std::max(c,d));
526 }
527 
529 template<typename Type>
530 inline const Type&
531 Max(const Type& a, const Type& b, const Type& c, const Type& d, const Type& e)
532 {
533  return std::max(std::max(a,b), Max(c,d,e));
534 }
535 
537 template<typename Type>
538 inline const Type&
539 Max(const Type& a, const Type& b, const Type& c, const Type& d, const Type& e, const Type& f)
540 {
541  return std::max(Max(a,b,c), Max(d,e,f));
542 }
543 
545 template<typename Type>
546 inline const Type&
547 Max(const Type& a, const Type& b, const Type& c, const Type& d,
548  const Type& e, const Type& f, const Type& g)
549 {
550  return std::max(Max(a,b,c,d), Max(e,f,g));
551 }
552 
554 template<typename Type>
555 inline const Type&
556 Max(const Type& a, const Type& b, const Type& c, const Type& d,
557  const Type& e, const Type& f, const Type& g, const Type& h)
558 {
559  return std::max(Max(a,b,c,d), Max(e,f,g,h));
560 }
561 
562 
563 // ==========> Min <==================
564 
566 template<typename Type>
567 inline const Type&
568 Min(const Type& a, const Type& b) { return std::min(a, b); }
569 
571 template<typename Type>
572 inline const Type&
573 Min(const Type& a, const Type& b, const Type& c) { return std::min(std::min(a, b), c); }
574 
576 template<typename Type>
577 inline const Type&
578 Min(const Type& a, const Type& b, const Type& c, const Type& d)
579 {
580  return std::min(std::min(a, b), std::min(c, d));
581 }
582 
584 template<typename Type>
585 inline const Type&
586 Min(const Type& a, const Type& b, const Type& c, const Type& d, const Type& e)
587 {
588  return std::min(std::min(a,b), Min(c,d,e));
589 }
590 
592 template<typename Type>
593 inline const Type&
594 Min(const Type& a, const Type& b, const Type& c, const Type& d, const Type& e, const Type& f)
595 {
596  return std::min(Min(a,b,c), Min(d,e,f));
597 }
598 
600 template<typename Type>
601 inline const Type&
602 Min(const Type& a, const Type& b, const Type& c, const Type& d,
603  const Type& e, const Type& f, const Type& g)
604 {
605  return std::min(Min(a,b,c,d), Min(e,f,g));
606 }
607 
609 template<typename Type>
610 inline const Type&
611 Min(const Type& a, const Type& b, const Type& c, const Type& d,
612  const Type& e, const Type& f, const Type& g, const Type& h)
613 {
614  return std::min(Min(a,b,c,d), Min(e,f,g,h));
615 }
616 
617 
619 
620 
622 template <typename Type>
623 inline int Sign(const Type &x) { return (zeroVal<Type>() < x) - (x < zeroVal<Type>()); }
624 
625 
628 template <typename Type>
629 inline bool
630 SignChange(const Type& a, const Type& b)
631 {
632  return ( (a<zeroVal<Type>()) ^ (b<zeroVal<Type>()) );
633 }
634 
635 
638 template <typename Type>
639 inline bool
640 ZeroCrossing(const Type& a, const Type& b)
641 {
642  return a * b <= zeroVal<Type>();
643 }
644 
645 
647 inline float Sqrt(float x) { return sqrtf(x); }
649 inline double Sqrt(double x) { return sqrt(x); }
650 inline long double Sqrt(long double x) { return sqrtl(x); }
652 
653 
655 inline float Cbrt(float x) { return boost::math::cbrt(x); }
657 inline double Cbrt(double x) { return boost::math::cbrt(x); }
658 inline long double Cbrt(long double x) { return boost::math::cbrt(x); }
660 
661 
663 inline int Mod(int x, int y) { return (x % y); }
665 inline float Mod(float x, float y) { return fmodf(x,y); }
666 inline double Mod(double x, double y) { return fmod(x,y); }
667 inline long double Mod(long double x, long double y) { return fmodl(x,y); }
668 template<typename Type> inline Type Remainder(Type x, Type y) { return Mod(x,y); }
670 
671 
673 inline float RoundUp(float x) { return ceilf(x); }
675 inline double RoundUp(double x) { return ceil(x); }
676 inline long double RoundUp(long double x) { return ceill(x); }
678 template<typename Type>
680 inline Type
681 RoundUp(Type x, Type base)
682 {
683  Type remainder = Remainder(x, base);
684  return remainder ? x-remainder+base : x;
685 }
686 
687 
689 inline float RoundDown(float x) { return floorf(x); }
691 inline double RoundDown(double x) { return floor(x); }
692 inline long double RoundDown(long double x) { return floorl(x); }
693 template <typename Type> inline Type Round(Type x) { return RoundDown(x+0.5); }
695 template<typename Type>
697 inline Type
698 RoundDown(Type x, Type base)
699 {
700  Type remainder = Remainder(x, base);
701  return remainder ? x-remainder : x;
702 }
703 
704 
706 template<typename Type>
707 inline Type
708 IntegerPart(Type x)
709 {
710  return (x > 0 ? RoundDown(x) : RoundUp(x));
711 }
712 
714 template<typename Type>
715 inline Type FractionalPart(Type x) { return Mod(x,Type(1)); }
716 
717 
719 inline int Floor(float x) { return (int)RoundDown(x); }
721 inline int Floor(double x) { return (int)RoundDown(x); }
722 inline int Floor(long double x) { return (int)RoundDown(x); }
724 
725 
727 inline int Ceil(float x) { return (int)RoundUp(x); }
729 inline int Ceil(double x) { return (int)RoundUp(x); }
730 inline int Ceil(long double x) { return (int)RoundUp(x); }
732 
733 
735 template<typename Type>
736 inline Type Chop(Type x, Type delta) { return (Abs(x) < delta ? zeroVal<Type>() : x); }
737 
738 
740 template<typename Type>
741 inline Type
742 Truncate(Type x, unsigned int digits)
743 {
744  Type tenth = Pow(10,digits);
745  return RoundDown(x*tenth+0.5)/tenth;
746 }
747 
748 
750 
751 
753 template<typename Type>
754 inline Type
755 Inv(Type x)
756 {
757  assert(x);
758  return Type(1)/x;
759 }
760 
761 
762 enum Axis {
763  X_AXIS = 0,
764  Y_AXIS = 1,
765  Z_AXIS = 2
766 };
767 
768 // enum values are consistent with their historical mx analogs.
778 };
779 
780 
781 template <typename S, typename T>
782 struct promote {
783  typedef typename boost::numeric::conversion_traits<S, T>::supertype type;
784 };
785 
786 
794 template<typename Vec3T>
795 size_t
796 MinIndex(const Vec3T& v)
797 {
798  static const size_t hashTable[8] = { 2, 1, 9, 1, 2, 9, 0, 0 };//9 is a dummy value
799  const size_t hashKey =
800  ((v[0] < v[1]) << 2) + ((v[0] < v[2]) << 1) + (v[1] < v[2]);// ?*4+?*2+?*1
801  return hashTable[hashKey];
802 }
803 
804 
812 template<typename Vec3T>
813 size_t
814 MaxIndex(const Vec3T& v)
815 {
816  static const size_t hashTable[8] = { 2, 1, 9, 1, 2, 9, 0, 0 };//9 is a dummy value
817  const size_t hashKey =
818  ((v[0] > v[1]) << 2) + ((v[0] > v[2]) << 1) + (v[1] > v[2]);// ?*4+?*2+?*1
819  return hashTable[hashKey];
820 }
821 
822 } // namespace math
823 } // namespace OPENVDB_VERSION_NAME
824 } // namespace openvdb
825 
826 #endif // OPENVDB_MATH_MATH_HAS_BEEN_INCLUDED
827 
828 // Copyright (c) 2012-2013 DreamWorks Animation LLC
829 // All rights reserved. This software is distributed under the
830 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
int Ceil(float x)
Return the ceiling of x.
Definition: Math.h:728
OPENVDB_API Hermite max(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
int operator()()
Return a randomly-generated integer in the current range.
Definition: Math.h:183
Type Remainder(Type x, Type y)
Return the remainder of x / y.
Definition: Math.h:668
#define OPENVDB_DEPRECATED
Definition: Platform.h:47
int64_t doubleToInt64(const double aDoubleValue)
Definition: Math.h:402
Type Pow3(Type x)
Return .
Definition: Math.h:464
bool isApproxZero(const Type &x)
Return true if x is equal to zero to within the default floating-point comparison tolerance...
Definition: Math.h:288
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:186
Type FractionalPart(Type x)
Return the fractional part of x.
Definition: Math.h:715
float Sqrt(float x)
Return the square root of a floating-point value.
Definition: Math.h:648
float Cbrt(float x)
Return the cube root of a floating-point value.
Definition: Math.h:656
Type Pow2(Type x)
Return .
Definition: Math.h:460
const Type & Max(const Type &a, const Type &b)
Return the maximum of two values.
Definition: Math.h:507
OPENVDB_DEPRECATED double randUniform()
Definition: Math.h:130
Type Chop(Type x, Type delta)
Return x if it is greater in magnitude than delta. Otherwise, return zero.
Definition: Math.h:736
Rand01(unsigned int seed)
Initialize the generator.
Definition: Math.h:147
Tolerance for floating-point comparison.
Definition: Math.h:116
int32_t floatToInt32(const float aFloatValue)
Definition: Math.h:393
Type Clamp01(Type x)
Return x clamped to [0, 1].
Definition: Math.h:215
T zeroVal()
Return the value of type T that corresponds to zero.
Definition: Math.h:85
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:233
Type Round(Type x)
Return x rounded down to the nearest integer.
Definition: Math.h:693
Definition: Math.h:764
Type Inv(Type x)
Return the inverse of x.
Definition: Math.h:755
T negative(const T &val)
Return the unary negation of the given value.
Definition: Math.h:107
bool isNegative(const Type &x)
Return true if x is less than zero.
Definition: Math.h:306
Definition: Math.h:763
size_t MaxIndex(const Vec3T &v)
Return the index [0,1,2] of the largest value in a 3D vector.
Definition: Math.h:814
#define OPENVDB_VERSION_NAME
Definition: version.h:45
float RoundDown(float x)
Return x rounded down to the nearest integer.
Definition: Math.h:690
RotationOrder
Definition: Math.h:769
Definition: Math.h:782
bool ClampTest01(Type &x)
Return true if x is outside [0,1].
Definition: Math.h:221
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition: Math.h:276
Simple generator of random numbers over the range [0, 1)
Definition: Math.h:136
static double value()
Definition: Math.h:118
bool isNegative< bool >(const bool &)
Return false, since bool values are never less than zero.
Definition: Math.h:309
FloatType operator()()
Return a uniformly distributed random number in the range [0, 1).
Definition: Math.h:150
Rand01< double, boost::mt19937 > Random01
Definition: Math.h:153
Type Clamp(Type x, Type min, Type max)
Return x clamped to [min, max].
Definition: Math.h:205
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
bool SignChange(const Type &a, const Type &b)
Return true if a and b have different signs.
Definition: Math.h:630
OPENVDB_API Hermite min(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
void setRange(int imin, int imax)
Change the range over which integers are distributed to [imin, imax].
Definition: Math.h:180
#define OPENVDB_NO_FP_EQUALITY_WARNING_END
Definition: Math.h:74
OPENVDB_DEPRECATED void randSeed(unsigned int seed)
Definition: Math.h:126
size_t MinIndex(const Vec3T &v)
Return the index [0,1,2] of the smallest value in a 3D vector.
Definition: Math.h:796
bool isRelOrApproxEqual(const Type &a, const Type &b, const Type &absTol, const Type &relTol)
Definition: Math.h:363
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:353
Definition: Math.h:765
RandInt(unsigned int seed, int imin, int imax)
Initialize the generator.
Definition: Math.h:174
float RoundUp(float x)
Return x rounded up to the nearest integer.
Definition: Math.h:674
int Sign(const Type &x)
Return the sign of the given value as an integer (either -1, 0 or 1).
Definition: Math.h:623
FloatType ValueType
Definition: Math.h:143
Type Pow4(Type x)
Return .
Definition: Math.h:468
boost::numeric::conversion_traits< S, T >::supertype type
Definition: Math.h:783
static float value()
Definition: Math.h:117
#define OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN
Definition: Math.h:73
Type IntegerPart(Type x)
Return the integer part of x.
Definition: Math.h:708
int Mod(int x, int y)
Return the remainder of x / y.
Definition: Math.h:664
int32_t Abs(int32_t i)
Return the absolute value of the given quantity.
Definition: Math.h:246
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:344
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:640
Type Truncate(Type x, unsigned int digits)
Return x truncated to the given number of decimal digits.
Definition: Math.h:742
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:56
Axis
Definition: Math.h:762
const Type & Min(const Type &a, const Type &b)
Return the minimum of two values.
Definition: Math.h:568
bool isApproxEqual(const Hermite &lhs, const Hermite &rhs)
Definition: Hermite.h:470
bool isUlpsEqual(const double aLeft, const double aRight, const int64_t aUnitsInLastPlace)
Definition: Math.h:415
Type Pow(Type x, int n)
Return .
Definition: Math.h:473
RandInt< boost::mt19937 > RandomInt
Definition: Math.h:197
int Floor(float x)
Return the floor of x.
Definition: Math.h:720
#define OPENVDB_EXACT_IS_APPROX_EQUAL(T)
Definition: Math.h:331
Simple random integer generator.
Definition: Math.h:159
bool zeroVal< bool >()
Return the bool value that corresponds to zero.
Definition: Math.h:89