OpenVDB 7.0.0

Math.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3 //
7
8 #ifndef OPENVDB_MATH_HAS_BEEN_INCLUDED
9 #define OPENVDB_MATH_HAS_BEEN_INCLUDED
10
11 #include <openvdb/Platform.h>
12 #include <openvdb/version.h>
13 #include <boost/numeric/conversion/conversion_traits.hpp>
14 #include <algorithm> // for std::max()
15 #include <cassert>
16 #include <cmath> // for std::ceil(), std::fabs(), std::pow(), std::sqrt(), etc.
17 #include <cstdlib> // for abs(int)
18 #include <random>
19 #include <string>
20 #include <type_traits> // for std::is_arithmetic
21
22
23 // Compile pragmas
24
25 // Intel(r) compiler fires remark #1572: floating-point equality and inequality
26 // comparisons are unrealiable when == or != is used with floating point operands.
27 #if defined(__INTEL_COMPILER)
28 #define OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN \
29 _Pragma("warning (push)") \
30 _Pragma("warning (disable:1572)")
31 #define OPENVDB_NO_FP_EQUALITY_WARNING_END \
32 _Pragma("warning (pop)")
33 #elif defined(__clang__)
34 #define OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN \
35 PRAGMA(clang diagnostic push) \
36 PRAGMA(clang diagnostic ignored "-Wfloat-equal")
37 #define OPENVDB_NO_FP_EQUALITY_WARNING_END \
38 PRAGMA(clang diagnostic pop)
39 #else
40 // For GCC, #pragma GCC diagnostic ignored "-Wfloat-equal"
41 // isn't working until gcc 4.2+,
42 // Trying
43 // #pragma GCC system_header
44 // creates other problems, most notably "warning: will never be executed"
45 // in from templates, unsure of how to work around.
46 // If necessary, could use integer based comparisons for equality
47 #define OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN
48 #define OPENVDB_NO_FP_EQUALITY_WARNING_END
49 #endif
50
51 namespace openvdb {
52 OPENVDB_USE_VERSION_NAMESPACE
53 namespace OPENVDB_VERSION_NAME {
54
59 template<typename T> inline T zeroVal() { return T(0); }
61 template<> inline std::string zeroVal<std::string>() { return ""; }
63 template<> inline bool zeroVal<bool>() { return false; }
64
66
67 inline std::string operator+(const std::string& s, bool) { return s; }
70 inline std::string operator+(const std::string& s, int) { return s; }
71 inline std::string operator+(const std::string& s, float) { return s; }
72 inline std::string operator+(const std::string& s, double) { return s; }
74
75
76 namespace math {
77
81 template<typename T> inline T negative(const T& val) { return T(-val); }
83 template<> inline bool negative(const bool& val) { return !val; }
85 template<> inline std::string negative(const std::string& val) { return val; }
86
87
89 template<typename T> struct Tolerance { static T value() { return zeroVal<T>(); } };
91 template<> struct Tolerance<float> { static float value() { return 1e-8f; } };
92 template<> struct Tolerance<double> { static double value() { return 1e-15; } };
94
96 template<typename T> struct Delta { static T value() { return zeroVal<T>(); } };
98 template<> struct Delta<float> { static float value() { return 1e-5f; } };
99 template<> struct Delta<double> { static double value() { return 1e-9; } };
101
102
103 // ==========> Random Values <==================
104
107 template<typename FloatType = double, typename EngineType = std::mt19937>
108 class Rand01
109 {
110 private:
111 EngineType mEngine;
112 std::uniform_real_distribution<FloatType> mRand;
113
114 public:
115 using ValueType = FloatType;
116
119 Rand01(const EngineType& engine): mEngine(engine) {}
120
123 Rand01(unsigned int seed): mEngine(static_cast<typename EngineType::result_type>(seed)) {}
124
126 void setSeed(unsigned int seed)
127 {
128 mEngine.seed(static_cast<typename EngineType::result_type>(seed));
129 }
130
132 const EngineType& engine() const { return mEngine; }
133
135 FloatType operator()() { return mRand(mEngine); }
136 };
137
138 using Random01 = Rand01<double, std::mt19937>;
139
140
143 template<typename IntType = int, typename EngineType = std::mt19937>
144 class RandInt
145 {
146 private:
147 using Distr = std::uniform_int_distribution<IntType>;
148 EngineType mEngine;
149 Distr mRand;
150
151 public:
155 RandInt(const EngineType& engine, IntType imin, IntType imax):
156 mEngine(engine),
157 mRand(std::min(imin, imax), std::max(imin, imax))
158 {}
159
163 RandInt(unsigned int seed, IntType imin, IntType imax):
164 mEngine(static_cast<typename EngineType::result_type>(seed)),
165 mRand(std::min(imin, imax), std::max(imin, imax))
166 {}
167
169 void setRange(IntType imin, IntType imax)
170 {
171 mRand = Distr(std::min(imin, imax), std::max(imin, imax));
172 }
173
175 void setSeed(unsigned int seed)
176 {
177 mEngine.seed(static_cast<typename EngineType::result_type>(seed));
178 }
179
181 const EngineType& engine() const { return mEngine; }
182
184 IntType operator()() { return mRand(mEngine); }
185
188 IntType operator()(IntType imin, IntType imax)
189 {
190 const IntType lo = std::min(imin, imax), hi = std::max(imin, imax);
191 return mRand(mEngine, typename Distr::param_type(lo, hi));
192 }
193 };
194
195 using RandomInt = RandInt<int, std::mt19937>;
196
197
198 // ==========> Clamp <==================
199
201 template<typename Type>
202 inline Type
203 Clamp(Type x, Type min, Type max)
204 {
205 assert( !(min>max) );
206 return x > min ? x < max ? x : max : min;
207 }
208
209
211 template<typename Type>
212 inline Type
213 Clamp01(Type x) { return x > Type(0) ? x < Type(1) ? x : Type(1) : Type(0); }
214
215
217 template<typename Type>
218 inline bool
219 ClampTest01(Type &x)
220 {
221 if (x >= Type(0) && x <= Type(1)) return false;
222 x = x < Type(0) ? Type(0) : Type(1);
223 return true;
224 }
225
227 template<typename Type>
228 inline Type
229 SmoothUnitStep(Type x)
230 {
231 return x > 0 ? x < 1 ? (3-2*x)*x*x : Type(1) : Type(0);
232 }
233
236 template<typename Type>
237 inline Type
238 SmoothUnitStep(Type x, Type min, Type max)
239 {
240 assert(min < max);
241 return SmoothUnitStep((x-min)/(max-min));
242 }
243
244
245 // ==========> Absolute Value <==================
246
247
249 inline int32_t Abs(int32_t i) { return abs(i); }
251 inline int64_t Abs(int64_t i)
252 {
253 #ifdef _MSC_VER
254 return (i < int64_t(0) ? -i : i);
255 #else
256 return labs(i);
257 #endif
258 }
259 inline float Abs(float x) { return std::fabs(x); }
260 inline double Abs(double x) { return std::fabs(x); }
261 inline long double Abs(long double x) { return std::fabs(x); }
262 inline uint32_t Abs(uint32_t i) { return i; }
263 inline uint64_t Abs(uint64_t i) { return i; }
264 inline bool Abs(bool b) { return b; }
265 // On OSX size_t and uint64_t are different types
266 #if defined(__APPLE__) || defined(MACOSX)
267 inline size_t Abs(size_t i) { return i; }
268 #endif
269
270
271
273
274
275 // ==========> Value Comparison <==================
276
277
279 template<typename Type>
280 inline bool
281 isZero(const Type& x)
282 {
283 OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN
284 return x == zeroVal<Type>();
285 OPENVDB_NO_FP_EQUALITY_WARNING_END
286 }
287
288
291 template<typename Type>
292 inline bool
293 isApproxZero(const Type& x)
294 {
295 const Type tolerance = Type(zeroVal<Type>() + Tolerance<Type>::value());
296 return !(x > tolerance) && !(x < -tolerance);
297 }
298
300 template<typename Type>
301 inline bool
302 isApproxZero(const Type& x, const Type& tolerance)
303 {
304 return !(x > tolerance) && !(x < -tolerance);
305 }
306
307
309 template<typename Type>
310 inline bool
311 isNegative(const Type& x) { return x < zeroVal<Type>(); }
312
313 // Return false, since bool values are never less than zero.
314 template<> inline bool isNegative<bool>(const bool&) { return false; }
315
316
318 inline bool
319 isFinite(const float x) { return std::isfinite(x); }
320
322 template<typename Type, typename std::enable_if<std::is_arithmetic<Type>::value, int>::type = 0>
323 inline bool
324 isFinite(const Type& x) { return std::isfinite(static_cast<double>(x)); }
325
326
328 inline bool
329 isInfinite(const float x) { return std::isinf(x); }
330
332 template<typename Type, typename std::enable_if<std::is_arithmetic<Type>::value, int>::type = 0>
333 inline bool
334 isInfinite(const Type& x) { return std::isinf(static_cast<double>(x)); }
335
336
338 inline bool
339 isNan(const float x) { return std::isnan(x); }
340
342 template<typename Type, typename std::enable_if<std::is_arithmetic<Type>::value, int>::type = 0>
343 inline bool
344 isNan(const Type& x) { return std::isnan(static_cast<double>(x)); }
345
346
349 template<typename Type>
350 inline bool
351 isApproxEqual(const Type& a, const Type& b)
352 {
353 const Type tolerance = Type(zeroVal<Type>() + Tolerance<Type>::value());
354 return !(Abs(a - b) > tolerance);
355 }
356
357
359 template<typename Type>
360 inline bool
361 isApproxEqual(const Type& a, const Type& b, const Type& tolerance)
362 {
363 return !(Abs(a - b) > tolerance);
364 }
365
366 #define OPENVDB_EXACT_IS_APPROX_EQUAL(T) \
367 template<> inline bool isApproxEqual<T>(const T& a, const T& b) { return a == b; } \
368 template<> inline bool isApproxEqual<T>(const T& a, const T& b, const T&) { return a == b; } \
369
370
371 OPENVDB_EXACT_IS_APPROX_EQUAL(bool)
372 OPENVDB_EXACT_IS_APPROX_EQUAL(std::string)
373
374
377 template<typename Type>
378 inline bool
379 isApproxLarger(const Type& a, const Type& b, const Type& tolerance)
380 {
381 return (b - a < tolerance);
382 }
383
384
386 template<typename T0, typename T1>
387 inline bool
388 isExactlyEqual(const T0& a, const T1& b)
389 {
390 OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN
391 return a == b;
392 OPENVDB_NO_FP_EQUALITY_WARNING_END
393 }
394
395
396 template<typename Type>
397 inline bool
398 isRelOrApproxEqual(const Type& a, const Type& b, const Type& absTol, const Type& relTol)
399 {
400 // First check to see if we are inside the absolute tolerance
401 // Necessary for numbers close to 0
402 if (!(Abs(a - b) > absTol)) return true;
403
404 // Next check to see if we are inside the relative tolerance
405 // to handle large numbers that aren't within the abs tolerance
406 // but could be the closest floating point representation
407 double relError;
408 if (Abs(b) > Abs(a)) {
409 relError = Abs((a - b) / b);
410 } else {
411 relError = Abs((a - b) / a);
412 }
413 return (relError <= relTol);
414 }
415
416 template<>
417 inline bool
418 isRelOrApproxEqual(const bool& a, const bool& b, const bool&, const bool&)
419 {
420 return (a == b);
421 }
422
423
424 // Avoid strict aliasing issues by using type punning
425 // http://cellperformance.beyond3d.com/articles/2006/06/understanding-strict-aliasing.html
426 // Using "casting through a union(2)"
427 inline int32_t
428 floatToInt32(const float aFloatValue)
429 {
430 union FloatOrInt32 { float floatValue; int32_t int32Value; };
431 const FloatOrInt32* foi = reinterpret_cast<const FloatOrInt32*>(&aFloatValue);
432 return foi->int32Value;
433 }
434
435
436 inline int64_t
437 doubleToInt64(const double aDoubleValue)
438 {
439 union DoubleOrInt64 { double doubleValue; int64_t int64Value; };
440 const DoubleOrInt64* dol = reinterpret_cast<const DoubleOrInt64*>(&aDoubleValue);
441 return dol->int64Value;
442 }
443
444
445 // aUnitsInLastPlace is the allowed difference between the least significant digits
446 // of the numbers' floating point representation
447 // Please read the reference paper before trying to use isUlpsEqual
448 // http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
449 inline bool
450 isUlpsEqual(const double aLeft, const double aRight, const int64_t aUnitsInLastPlace)
451 {
452 int64_t longLeft = doubleToInt64(aLeft);
453 // Because of 2's complement, must restore lexicographical order
454 if (longLeft < 0) {
455 longLeft = INT64_C(0x8000000000000000) - longLeft;
456 }
457
458 int64_t longRight = doubleToInt64(aRight);
459 // Because of 2's complement, must restore lexicographical order
460 if (longRight < 0) {
461 longRight = INT64_C(0x8000000000000000) - longRight;
462 }
463
464 int64_t difference = labs(longLeft - longRight);
465 return (difference <= aUnitsInLastPlace);
466 }
467
468 inline bool
469 isUlpsEqual(const float aLeft, const float aRight, const int32_t aUnitsInLastPlace)
470 {
471 int32_t intLeft = floatToInt32(aLeft);
472 // Because of 2's complement, must restore lexicographical order
473 if (intLeft < 0) {
474 intLeft = 0x80000000 - intLeft;
475 }
476
477 int32_t intRight = floatToInt32(aRight);
478 // Because of 2's complement, must restore lexicographical order
479 if (intRight < 0) {
480 intRight = 0x80000000 - intRight;
481 }
482
483 int32_t difference = abs(intLeft - intRight);
484 return (difference <= aUnitsInLastPlace);
485 }
486
487
489
490
491 // ==========> Pow <==================
492
494 template<typename Type>
495 inline Type Pow2(Type x) { return x*x; }
496
498 template<typename Type>
499 inline Type Pow3(Type x) { return x*x*x; }
500
502 template<typename Type>
503 inline Type Pow4(Type x) { return Pow2(Pow2(x)); }
504
506 template<typename Type>
507 Type
508 Pow(Type x, int n)
509 {
510 Type ans = 1;
511 if (n < 0) {
512 n = -n;
513 x = Type(1)/x;
514 }
515 while (n--) ans *= x;
516 return ans;
517 }
518
520 inline float
522 Pow(float b, float e)
523 {
524 assert( b >= 0.0f && "Pow(float,float): base is negative" );
525 return powf(b,e);
526 }
527
528 inline double
529 Pow(double b, double e)
530 {
531 assert( b >= 0.0 && "Pow(double,double): base is negative" );
532 return std::pow(b,e);
533 }
535
536
537 // ==========> Max <==================
538
540 template<typename Type>
541 inline const Type&
542 Max(const Type& a, const Type& b)
543 {
544 return std::max(a,b);
545 }
546
548 template<typename Type>
549 inline const Type&
550 Max(const Type& a, const Type& b, const Type& c)
551 {
552 return std::max(std::max(a,b), c);
553 }
554
556 template<typename Type>
557 inline const Type&
558 Max(const Type& a, const Type& b, const Type& c, const Type& d)
559 {
560 return std::max(std::max(a,b), std::max(c,d));
561 }
562
564 template<typename Type>
565 inline const Type&
566 Max(const Type& a, const Type& b, const Type& c, const Type& d, const Type& e)
567 {
568 return std::max(std::max(a,b), Max(c,d,e));
569 }
570
572 template<typename Type>
573 inline const Type&
574 Max(const Type& a, const Type& b, const Type& c, const Type& d, const Type& e, const Type& f)
575 {
576 return std::max(Max(a,b,c), Max(d,e,f));
577 }
578
580 template<typename Type>
581 inline const Type&
582 Max(const Type& a, const Type& b, const Type& c, const Type& d,
583 const Type& e, const Type& f, const Type& g)
584 {
585 return std::max(Max(a,b,c,d), Max(e,f,g));
586 }
587
589 template<typename Type>
590 inline const Type&
591 Max(const Type& a, const Type& b, const Type& c, const Type& d,
592 const Type& e, const Type& f, const Type& g, const Type& h)
593 {
594 return std::max(Max(a,b,c,d), Max(e,f,g,h));
595 }
596
597
598 // ==========> Min <==================
599
601 template<typename Type>
602 inline const Type&
603 Min(const Type& a, const Type& b) { return std::min(a, b); }
604
606 template<typename Type>
607 inline const Type&
608 Min(const Type& a, const Type& b, const Type& c) { return std::min(std::min(a, b), c); }
609
611 template<typename Type>
612 inline const Type&
613 Min(const Type& a, const Type& b, const Type& c, const Type& d)
614 {
615 return std::min(std::min(a, b), std::min(c, d));
616 }
617
619 template<typename Type>
620 inline const Type&
621 Min(const Type& a, const Type& b, const Type& c, const Type& d, const Type& e)
622 {
623 return std::min(std::min(a,b), Min(c,d,e));
624 }
625
627 template<typename Type>
628 inline const Type&
629 Min(const Type& a, const Type& b, const Type& c, const Type& d, const Type& e, const Type& f)
630 {
631 return std::min(Min(a,b,c), Min(d,e,f));
632 }
633
635 template<typename Type>
636 inline const Type&
637 Min(const Type& a, const Type& b, const Type& c, const Type& d,
638 const Type& e, const Type& f, const Type& g)
639 {
640 return std::min(Min(a,b,c,d), Min(e,f,g));
641 }
642
644 template<typename Type>
645 inline const Type&
646 Min(const Type& a, const Type& b, const Type& c, const Type& d,
647 const Type& e, const Type& f, const Type& g, const Type& h)
648 {
649 return std::min(Min(a,b,c,d), Min(e,f,g,h));
650 }
651
652
653 // ============> Exp <==================
654
656 template<typename Type>
657 inline Type Exp(const Type& x) { return std::exp(x); }
658
659 // ============> Sin <==================
660
662 inline float Sin(const float& x) { return std::sin(x); }
664
665 inline double Sin(const double& x) { return std::sin(x); }
667
668 // ============> Cos <==================
669
671 inline float Cos(const float& x) { return std::cos(x); }
673
674 inline double Cos(const double& x) { return std::cos(x); }
676
677
679
680
682 template <typename Type>
683 inline int Sign(const Type &x) { return (zeroVal<Type>() < x) - (x < zeroVal<Type>()); }
684
685
688 template <typename Type>
689 inline bool
690 SignChange(const Type& a, const Type& b)
691 {
692 return ( (a<zeroVal<Type>()) ^ (b<zeroVal<Type>()) );
693 }
694
695
698 template <typename Type>
699 inline bool
700 ZeroCrossing(const Type& a, const Type& b)
701 {
702 return a * b <= zeroVal<Type>();
703 }
704
705
707 inline float Sqrt(float x) { return std::sqrt(x); }
709 inline double Sqrt(double x) { return std::sqrt(x); }
710 inline long double Sqrt(long double x) { return std::sqrt(x); }
712
713
715 inline float Cbrt(float x) { return std::cbrt(x); }
717 inline double Cbrt(double x) { return std::cbrt(x); }
718 inline long double Cbrt(long double x) { return std::cbrt(x); }
720
721
723 inline int Mod(int x, int y) { return (x % y); }
725 inline float Mod(float x, float y) { return std::fmod(x, y); }
726 inline double Mod(double x, double y) { return std::fmod(x, y); }
727 inline long double Mod(long double x, long double y) { return std::fmod(x, y); }
728 template<typename Type> inline Type Remainder(Type x, Type y) { return Mod(x, y); }
730
731
733 inline float RoundUp(float x) { return std::ceil(x); }
735 inline double RoundUp(double x) { return std::ceil(x); }
736 inline long double RoundUp(long double x) { return std::ceil(x); }
738 template<typename Type>
740 inline Type
741 RoundUp(Type x, Type base)
742 {
743 Type remainder = Remainder(x, base);
744 return remainder ? x-remainder+base : x;
745 }
746
747
749 inline float RoundDown(float x) { return std::floor(x); }
751 inline double RoundDown(double x) { return std::floor(x); }
752 inline long double RoundDown(long double x) { return std::floor(x); }
754 template<typename Type>
756 inline Type
757 RoundDown(Type x, Type base)
758 {
759 Type remainder = Remainder(x, base);
760 return remainder ? x-remainder : x;
761 }
762
763
765 inline float Round(float x) { return RoundDown(x + 0.5f); }
767 inline double Round(double x) { return RoundDown(x + 0.5); }
768 inline long double Round(long double x) { return RoundDown(x + 0.5l); }
770
771
774 template<typename Type>
775 inline Type
776 EuclideanRemainder(Type x) { return x - RoundDown(x); }
777
778
780 template<typename Type>
781 inline Type
782 IntegerPart(Type x)
783 {
784 return (x > 0 ? RoundDown(x) : RoundUp(x));
785 }
786
788 template<typename Type>
789 inline Type
790 FractionalPart(Type x) { return Mod(x,Type(1)); }
791
792
794 inline int Floor(float x) { return int(RoundDown(x)); }
796 inline int Floor(double x) { return int(RoundDown(x)); }
797 inline int Floor(long double x) { return int(RoundDown(x)); }
799
800
802 inline int Ceil(float x) { return int(RoundUp(x)); }
804 inline int Ceil(double x) { return int(RoundUp(x)); }
805 inline int Ceil(long double x) { return int(RoundUp(x)); }
807
808
810 template<typename Type>
811 inline Type Chop(Type x, Type delta) { return (Abs(x) < delta ? zeroVal<Type>() : x); }
812
813
815 template<typename Type>
816 inline Type
817 Truncate(Type x, unsigned int digits)
818 {
819 Type tenth = Pow(10,digits);
820 return RoundDown(x*tenth+0.5)/tenth;
821 }
822
823
825
826
829 template<typename T>
830 inline auto PrintCast(const T& val) -> typename std::enable_if<!std::is_same<T, int8_t>::value
831 && !std::is_same<T, uint8_t>::value, const T&>::type { return val; }
832 inline int32_t PrintCast(int8_t val) { return int32_t(val); }
833 inline uint32_t PrintCast(uint8_t val) { return uint32_t(val); }
834
835
837
838
840 template<typename Type>
841 inline Type
842 Inv(Type x)
843 {
844 assert(x);
845 return Type(1)/x;
846 }
847
848
849 enum Axis {
850 X_AXIS = 0,
851 Y_AXIS = 1,
852 Z_AXIS = 2
853 };
854
855 // enum values are consistent with their historical mx analogs.
856 enum RotationOrder {
857 XYZ_ROTATION = 0,
858 XZY_ROTATION,
859 YXZ_ROTATION,
860 YZX_ROTATION,
861 ZXY_ROTATION,
862 ZYX_ROTATION,
863 XZX_ROTATION,
864 ZXZ_ROTATION
865 };
866
867
868 template <typename S, typename T>
869 struct promote {
870 using type = typename boost::numeric::conversion_traits<S, T>::supertype;
871 };
872
873
881 template<typename Vec3T>
882 size_t
883 MinIndex(const Vec3T& v)
884 {
885 static const size_t hashTable[8] = { 2, 1, 9, 1, 2, 9, 0, 0 };//9 is a dummy value
886 const size_t hashKey =
887 ((v[0] < v[1]) << 2) + ((v[0] < v[2]) << 1) + (v[1] < v[2]);// ?*4+?*2+?*1
888 return hashTable[hashKey];
889 }
890
891
899 template<typename Vec3T>
900 size_t
901 MaxIndex(const Vec3T& v)
902 {
903 static const size_t hashTable[8] = { 2, 1, 9, 1, 2, 9, 0, 0 };//9 is a dummy value
904 const size_t hashKey =
905 ((v[0] > v[1]) << 2) + ((v[0] > v[2]) << 1) + (v[1] > v[2]);// ?*4+?*2+?*1
906 return hashTable[hashKey];
907 }
908
909 } // namespace math
910 } // namespace OPENVDB_VERSION_NAME
911 } // namespace openvdb
912
913 #endif // OPENVDB_MATH_MATH_HAS_BEEN_INCLUDED
openvdb::v7_0::math::SignChange
bool SignChange(const Type &a, const Type &b)
Return true if a and b have different signs.
Definition: Math.h:690
openvdb::v7_0::math::Tolerance< float >::value
static float value()
Definition: Math.h:91
openvdb::v7_0::math::YXZ_ROTATION
Definition: Math.h:859
openvdb::v7_0::math::isNegative< bool >
bool isNegative< bool >(const bool &)
Definition: Math.h:314
openvdb::v7_0::math::Rand01
Simple generator of random numbers over the range [0, 1)
Definition: Math.h:108
openvdb::v7_0::math::isInfinite
bool isInfinite(const Type &x)
Return true if x is an infinity value (either positive infinity or negative infinity).
Definition: Math.h:334
openvdb::v7_0::math::isApproxLarger
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 < tolerance.
Definition: Math.h:379
openvdb::v7_0::math::ZeroCrossing
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:700
openvdb::v7_0::math::Rand01::operator()
FloatType operator()()
Return a uniformly distributed random number in the range [0, 1).
Definition: Math.h:135
openvdb::v7_0::math::Round
long double Round(long double x)
Definition: Math.h:768
openvdb::v7_0::math::YZX_ROTATION
Definition: Math.h:860
openvdb::v7_0::math::Rand01::setSeed
void setSeed(unsigned int seed)
Set the seed value for the random number generator.
Definition: Math.h:126
openvdb::v7_0::math::Delta
Delta for small floating-point offsets.
Definition: Math.h:97
openvdb::v7_0::math::RotationOrder
RotationOrder
Definition: Math.h:856
openvdb::v7_0::math::XZY_ROTATION
Definition: Math.h:858
openvdb::v7_0::math::Z_AXIS
Definition: Math.h:852
openvdb::v7_0::math::XYZ_ROTATION
Definition: Math.h:857
openvdb::v7_0::math::FractionalPart
Type FractionalPart(Type x)
Return the fractional part of x.
Definition: Math.h:790
openvdb::v7_0::math::Inv
Type Inv(Type x)
Return the inverse of x.
Definition: Math.h:842
openvdb::v7_0::math::negative
std::string negative(const std::string &val)
Return the "negation" of the given string.
Definition: Math.h:85
openvdb::v7_0::math::Remainder
Type Remainder(Type x, Type y)
Definition: Math.h:728
openvdb::v7_0::math::Chop
Type Chop(Type x, Type delta)
Return x if it is greater or equal in magnitude than delta. Otherwise, return zero.
Definition: Math.h:811
openvdb::v7_0::math::ZXY_ROTATION
Definition: Math.h:861
openvdb::v7_0::math::isNan
bool isNan(const Type &x)
Return true if x is a NaN (Not-A-Number) value.
Definition: Math.h:344
openvdb::v7_0::math::X_AXIS
Definition: Math.h:850
openvdb::v7_0::math::Pow3
Type Pow3(Type x)
Return x3.
Definition: Math.h:499
version.h
Library and file format version numbers.
openvdb::v7_0::math::Rand01< double, RandomGenerator >::ValueType
double ValueType
Definition: Math.h:115
Platform.h
openvdb::v7_0::math::Axis
Axis
Definition: Math.h:849
openvdb::v7_0::math::Rand01::Rand01
Rand01(const EngineType &engine)
Initialize the generator.
Definition: Math.h:119
openvdb::v7_0::math::Exp
Type Exp(const Type &x)
Return ex.
Definition: Math.h:657
openvdb::v7_0::math::promote::type
typename boost::numeric::conversion_traits< S, T >::supertype type
Definition: Math.h:870
openvdb::v7_0::math::Pow4
Type Pow4(Type x)
Return x4.
Definition: Math.h:503
openvdb::v7_0::math::RandInt::RandInt
RandInt(const EngineType &engine, IntType imin, IntType imax)
Initialize the generator.
Definition: Math.h:155
openvdb::v7_0::operator+
std::string operator+(const std::string &s, double)
Definition: Math.h:72
openvdb::v7_0::math::Pow2
Type Pow2(Type x)
Return x2.
Definition: Math.h:495
openvdb::v7_0::math::Clamp01
Type Clamp01(Type x)
Return x clamped to [0, 1].
Definition: Math.h:213
openvdb::v7_0::math::Sign
int Sign(const Type &x)
Return the sign of the given value as an integer (either -1, 0 or 1).
Definition: Math.h:683
openvdb::v7_0::math::Tolerance< double >::value
static double value()
Definition: Math.h:92
openvdb::v7_0::math::Y_AXIS
Definition: Math.h:851
openvdb::v7_0::math::Delta< float >::value
static float value()
Definition: Math.h:98
openvdb::v7_0::math::Tolerance
Tolerance for floating-point comparison.
Definition: Math.h:90
openvdb::v7_0::math::RoundUp
Type RoundUp(Type x, Type base)
Return x rounded up to the nearest multiple of base.
Definition: Math.h:741
openvdb::v7_0::math::floatToInt32
int32_t floatToInt32(const float aFloatValue)
Definition: Math.h:428
openvdb::v7_0::math::SmoothUnitStep
Type SmoothUnitStep(Type x, Type min, Type max)
Return 0 if x < min, 1 if x > max or else (3 − 2 t) t², where t = (x − min)/(max − min).
Definition: Math.h:238
openvdb::v7_0::math::RandInt::operator()
IntType operator()()
Return a randomly-generated integer in the current range.
Definition: Math.h:184
openvdb::v7_0::zeroVal< bool >
bool zeroVal< bool >()
Return the bool value that corresponds to zero.
Definition: Math.h:63
openvdb::v7_0::math::ClampTest01
bool ClampTest01(Type &x)
Return true if x is outside [0,1].
Definition: Math.h:219
openvdb::v7_0::math::Max
const Type & Max(const Type &a, const Type &b, const Type &c, const Type &d, const Type &e, const Type &f, const Type &g, const Type &h)
Return the maximum of eight values.
Definition: Math.h:591
openvdb::v7_0::math::isApproxEqual
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
Definition: Math.h:361
openvdb::v7_0::math::RandInt::engine
const EngineType & engine() const
Return a const reference to the random number generator.
Definition: Math.h:181
openvdb::v7_0::math::Min
const Type & Min(const Type &a, const Type &b, const Type &c, const Type &d, const Type &e, const Type &f, const Type &g, const Type &h)
Return the minimum of eight values.
Definition: Math.h:646
openvdb::v7_0::math::Cbrt
long double Cbrt(long double x)
Definition: Math.h:718
openvdb::v7_0::math::EuclideanRemainder
Type EuclideanRemainder(Type x)
Definition: Math.h:776
openvdb::v7_0::math::isUlpsEqual
bool isUlpsEqual(const float aLeft, const float aRight, const int32_t aUnitsInLastPlace)
Definition: Math.h:469
openvdb::v7_0::math::RandInt::setRange
void setRange(IntType imin, IntType imax)
Change the range over which integers are distributed to [imin, imax].
Definition: Math.h:169
OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN
#define OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN
Definition: Math.h:47
openvdb::v7_0::tools::composite::max
const std::enable_if<!VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:106
openvdb::v7_0::math::isNegative
bool isNegative(const Type &x)
Return true if x is less than zero.
Definition: Math.h:311
openvdb::v7_0::math::ZXZ_ROTATION
Definition: Math.h:864
openvdb::v7_0::math::RandInt::setSeed
void setSeed(unsigned int seed)
Set the seed value for the random number generator.
Definition: Math.h:175
openvdb::v7_0::math::Floor
int Floor(long double x)
Definition: Math.h:797
openvdb::v7_0::math::IntegerPart
Type IntegerPart(Type x)
Return the integer part of x.
Definition: Math.h:782
OPENVDB_EXACT_IS_APPROX_EQUAL
#define OPENVDB_EXACT_IS_APPROX_EQUAL(T)
Definition: Math.h:366
openvdb::v7_0::math::XZX_ROTATION
Definition: Math.h:863
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154
openvdb::v7_0::math::RandInt
Simple random integer generator.
Definition: Math.h:144
openvdb::v7_0::math::RoundDown
Type RoundDown(Type x, Type base)
Return x rounded down to the nearest multiple of base.
Definition: Math.h:757
openvdb::v7_0::math::Sin
double Sin(const double &x)
Definition: Math.h:665
openvdb::v7_0::math::Mod
long double Mod(long double x, long double y)
Definition: Math.h:727
openvdb::v7_0::math::Sqrt
long double Sqrt(long double x)
Definition: Math.h:710
openvdb::v7_0::math::doubleToInt64
int64_t doubleToInt64(const double aDoubleValue)
Definition: Math.h:437
openvdb::v7_0::math::isFinite
bool isFinite(const Type &x)
Return true if x is finite.
Definition: Math.h:324
openvdb::v7_0::math::ZYX_ROTATION
Definition: Math.h:862
openvdb::v7_0::tools::composite::min
const std::enable_if<!VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:102
openvdb::v7_0::math::Abs
bool Abs(bool b)
Definition: Math.h:264
openvdb::v7_0::math::promote
Definition: Math.h:869
openvdb::v7_0::math::Pow
double Pow(double b, double e)
Definition: Math.h:529
std
Definition: Coord.h:587
openvdb::v7_0::math::isRelOrApproxEqual
bool isRelOrApproxEqual(const bool &a, const bool &b, const bool &, const bool &)
Definition: Math.h:418
openvdb::v7_0::math::Cos
double Cos(const double &x)
Definition: Math.h:674
openvdb::v7_0::math::isExactlyEqual
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:388
openvdb::v7_0::math::Rand01::engine
const EngineType & engine() const
Return a const reference to the random number generator.
Definition: Math.h:132
openvdb::v7_0::math::RandInt::RandInt
RandInt(unsigned int seed, IntType imin, IntType imax)
Initialize the generator.
Definition: Math.h:163
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
openvdb::v7_0::math::Clamp
Type Clamp(Type x, Type min, Type max)
Return x clamped to [min, max].
Definition: Math.h:203
openvdb::v7_0::math::RandInt::operator()
IntType operator()(IntType imin, IntType imax)
Return a randomly-generated integer in the new range [imin, imax], without changing the current range...
Definition: Math.h:188
openvdb::v7_0::zeroVal
T zeroVal()
Return the value of type T that corresponds to zero.
Definition: Math.h:59
openvdb
Definition: Exceptions.h:13
openvdb::v7_0::math::isApproxZero
bool isApproxZero(const Type &x, const Type &tolerance)
Return true if x is equal to zero to within the given tolerance.
Definition: Math.h:302
openvdb::v7_0::math::Truncate
Type Truncate(Type x, unsigned int digits)
Return x truncated to the given number of decimal digits.
Definition: Math.h:817
openvdb::v7_0::math::MaxIndex
size_t MaxIndex(const Vec3T &v)
Return the index [0,1,2] of the largest value in a 3D vector.
Definition: Math.h:901
openvdb::v7_0::math::MinIndex
size_t MinIndex(const Vec3T &v)
Return the index [0,1,2] of the smallest value in a 3D vector.
Definition: Math.h:883
openvdb::v7_0::math::Rand01::Rand01
Rand01(unsigned int seed)
Initialize the generator.
Definition: Math.h:123
openvdb::v7_0::math::Ceil
int Ceil(long double x)
Definition: Math.h:805
openvdb::v7_0::math::PrintCast
uint32_t PrintCast(uint8_t val)
Definition: Math.h:833
openvdb::v7_0::math::Delta< double >::value
static double value()
Definition: Math.h:99
OPENVDB_NO_FP_EQUALITY_WARNING_END
#define OPENVDB_NO_FP_EQUALITY_WARNING_END
Definition: Math.h:48
openvdb::v7_0::math::isZero
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition: Math.h:281