OpenVDB: Math.h Source File

OpenVDB 7.1.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
78
81 template <typename T> inline constexpr T pi() { return 3.141592653589793238462643383279502884e+00; }
82 template <> inline constexpr float pi() { return 3.141592653589793238462643383279502884e+00F; }
83 template <> inline constexpr double pi() { return 3.141592653589793238462643383279502884e+00; }
84 template <> inline constexpr long double pi() { return 3.141592653589793238462643383279502884e+00L; }
85
86
90 template<typename T> inline T negative(const T& val)
91 {
92 // disable unary minus on unsigned warning
93 #if defined(_MSC_VER)
94 #pragma warning(push)
95 #pragma warning(disable:4146)
96 #endif
97 return T(-val);
98 #if defined(_MSC_VER)
99 #pragma warning(pop)
100 #endif
101 }
103 template<> inline bool negative(const bool& val) { return !val; }
105 template<> inline std::string negative(const std::string& val) { return val; }
106
107
109 template<typename T> struct Tolerance { static T value() { return zeroVal<T>(); } };
111 template<> struct Tolerance<float> { static float value() { return 1e-8f; } };
112 template<> struct Tolerance<double> { static double value() { return 1e-15; } };
114
116 template<typename T> struct Delta { static T value() { return zeroVal<T>(); } };
118 template<> struct Delta<float> { static float value() { return 1e-5f; } };
119 template<> struct Delta<double> { static double value() { return 1e-9; } };
121
122
123 // ==========> Random Values <==================
124
127 template<typename FloatType = double, typename EngineType = std::mt19937>
128 class Rand01
129 {
130 private:
131 EngineType mEngine;
132 std::uniform_real_distribution<FloatType> mRand;
133
134 public:
135 using ValueType = FloatType;
136
139 Rand01(const EngineType& engine): mEngine(engine) {}
140
143 Rand01(unsigned int seed): mEngine(static_cast<typename EngineType::result_type>(seed)) {}
144
146 void setSeed(unsigned int seed)
147 {
148 mEngine.seed(static_cast<typename EngineType::result_type>(seed));
149 }
150
152 const EngineType& engine() const { return mEngine; }
153
155 FloatType operator()() { return mRand(mEngine); }
156 };
157
158 using Random01 = Rand01<double, std::mt19937>;
159
160
163 template<typename IntType = int, typename EngineType = std::mt19937>
164 class RandInt
165 {
166 private:
167 using Distr = std::uniform_int_distribution<IntType>;
168 EngineType mEngine;
169 Distr mRand;
170
171 public:
175 RandInt(const EngineType& engine, IntType imin, IntType imax):
176 mEngine(engine),
177 mRand(std::min(imin, imax), std::max(imin, imax))
178 {}
179
183 RandInt(unsigned int seed, IntType imin, IntType imax):
184 mEngine(static_cast<typename EngineType::result_type>(seed)),
185 mRand(std::min(imin, imax), std::max(imin, imax))
186 {}
187
189 void setRange(IntType imin, IntType imax)
190 {
191 mRand = Distr(std::min(imin, imax), std::max(imin, imax));
192 }
193
195 void setSeed(unsigned int seed)
196 {
197 mEngine.seed(static_cast<typename EngineType::result_type>(seed));
198 }
199
201 const EngineType& engine() const { return mEngine; }
202
204 IntType operator()() { return mRand(mEngine); }
205
208 IntType operator()(IntType imin, IntType imax)
209 {
210 const IntType lo = std::min(imin, imax), hi = std::max(imin, imax);
211 return mRand(mEngine, typename Distr::param_type(lo, hi));
212 }
213 };
214
215 using RandomInt = RandInt<int, std::mt19937>;
216
217
218 // ==========> Clamp <==================
219
221 template<typename Type>
222 inline Type
223 Clamp(Type x, Type min, Type max)
224 {
225 assert( !(min>max) );
226 return x > min ? x < max ? x : max : min;
227 }
228
229
231 template<typename Type>
232 inline Type
233 Clamp01(Type x) { return x > Type(0) ? x < Type(1) ? x : Type(1) : Type(0); }
234
235
237 template<typename Type>
238 inline bool
239 ClampTest01(Type &x)
240 {
241 if (x >= Type(0) && x <= Type(1)) return false;
242 x = x < Type(0) ? Type(0) : Type(1);
243 return true;
244 }
245
247 template<typename Type>
248 inline Type
249 SmoothUnitStep(Type x)
250 {
251 return x > 0 ? x < 1 ? (3-2*x)*x*x : Type(1) : Type(0);
252 }
253
256 template<typename Type>
257 inline Type
258 SmoothUnitStep(Type x, Type min, Type max)
259 {
260 assert(min < max);
261 return SmoothUnitStep((x-min)/(max-min));
262 }
263
264
265 // ==========> Absolute Value <==================
266
267
269 inline int32_t Abs(int32_t i) { return abs(i); }
271 inline int64_t Abs(int64_t i)
272 {
273 #ifdef _MSC_VER
274 return (i < int64_t(0) ? -i : i);
275 #else
276 return labs(i);
277 #endif
278 }
279 inline float Abs(float x) { return std::fabs(x); }
280 inline double Abs(double x) { return std::fabs(x); }
281 inline long double Abs(long double x) { return std::fabs(x); }
282 inline uint32_t Abs(uint32_t i) { return i; }
283 inline uint64_t Abs(uint64_t i) { return i; }
284 inline bool Abs(bool b) { return b; }
285 // On OSX size_t and uint64_t are different types
286 #if defined(__APPLE__) || defined(MACOSX)
287 inline size_t Abs(size_t i) { return i; }
288 #endif
289
290
291
293
294
295 // ==========> Value Comparison <==================
296
297
299 template<typename Type>
300 inline bool
301 isZero(const Type& x)
302 {
303 OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN
304 return x == zeroVal<Type>();
305 OPENVDB_NO_FP_EQUALITY_WARNING_END
306 }
307
308
311 template<typename Type>
312 inline bool
313 isApproxZero(const Type& x)
314 {
315 const Type tolerance = Type(zeroVal<Type>() + Tolerance<Type>::value());
316 return !(x > tolerance) && !(x < -tolerance);
317 }
318
320 template<typename Type>
321 inline bool
322 isApproxZero(const Type& x, const Type& tolerance)
323 {
324 return !(x > tolerance) && !(x < -tolerance);
325 }
326
327
329 template<typename Type>
330 inline bool
331 isNegative(const Type& x) { return x < zeroVal<Type>(); }
332
333 // Return false, since bool values are never less than zero.
334 template<> inline bool isNegative<bool>(const bool&) { return false; }
335
336
338 inline bool
339 isFinite(const float x) { return std::isfinite(x); }
340
342 template<typename Type, typename std::enable_if<std::is_arithmetic<Type>::value, int>::type = 0>
343 inline bool
344 isFinite(const Type& x) { return std::isfinite(static_cast<double>(x)); }
345
346
348 inline bool
349 isInfinite(const float x) { return std::isinf(x); }
350
352 template<typename Type, typename std::enable_if<std::is_arithmetic<Type>::value, int>::type = 0>
353 inline bool
354 isInfinite(const Type& x) { return std::isinf(static_cast<double>(x)); }
355
356
358 inline bool
359 isNan(const float x) { return std::isnan(x); }
360
362 template<typename Type, typename std::enable_if<std::is_arithmetic<Type>::value, int>::type = 0>
363 inline bool
364 isNan(const Type& x) { return std::isnan(static_cast<double>(x)); }
365
366
369 template<typename Type>
370 inline bool
371 isApproxEqual(const Type& a, const Type& b)
372 {
373 const Type tolerance = Type(zeroVal<Type>() + Tolerance<Type>::value());
374 return !(Abs(a - b) > tolerance);
375 }
376
377
379 template<typename Type>
380 inline bool
381 isApproxEqual(const Type& a, const Type& b, const Type& tolerance)
382 {
383 return !(Abs(a - b) > tolerance);
384 }
385
386 #define OPENVDB_EXACT_IS_APPROX_EQUAL(T) \
387 template<> inline bool isApproxEqual<T>(const T& a, const T& b) { return a == b; } \
388 template<> inline bool isApproxEqual<T>(const T& a, const T& b, const T&) { return a == b; } \
389
390
391 OPENVDB_EXACT_IS_APPROX_EQUAL(bool)
392 OPENVDB_EXACT_IS_APPROX_EQUAL(std::string)
393
394
397 template<typename Type>
398 inline bool
399 isApproxLarger(const Type& a, const Type& b, const Type& tolerance)
400 {
401 return (b - a < tolerance);
402 }
403
404
406 template<typename T0, typename T1>
407 inline bool
408 isExactlyEqual(const T0& a, const T1& b)
409 {
410 OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN
411 return a == b;
412 OPENVDB_NO_FP_EQUALITY_WARNING_END
413 }
414
415
416 template<typename Type>
417 inline bool
418 isRelOrApproxEqual(const Type& a, const Type& b, const Type& absTol, const Type& relTol)
419 {
420 // First check to see if we are inside the absolute tolerance
421 // Necessary for numbers close to 0
422 if (!(Abs(a - b) > absTol)) return true;
423
424 // Next check to see if we are inside the relative tolerance
425 // to handle large numbers that aren't within the abs tolerance
426 // but could be the closest floating point representation
427 double relError;
428 if (Abs(b) > Abs(a)) {
429 relError = Abs((a - b) / b);
430 } else {
431 relError = Abs((a - b) / a);
432 }
433 return (relError <= relTol);
434 }
435
436 template<>
437 inline bool
438 isRelOrApproxEqual(const bool& a, const bool& b, const bool&, const bool&)
439 {
440 return (a == b);
441 }
442
443
444 // Avoid strict aliasing issues by using type punning
445 // http://cellperformance.beyond3d.com/articles/2006/06/understanding-strict-aliasing.html
446 // Using "casting through a union(2)"
447 inline int32_t
448 floatToInt32(const float aFloatValue)
449 {
450 union FloatOrInt32 { float floatValue; int32_t int32Value; };
451 const FloatOrInt32* foi = reinterpret_cast<const FloatOrInt32*>(&aFloatValue);
452 return foi->int32Value;
453 }
454
455
456 inline int64_t
457 doubleToInt64(const double aDoubleValue)
458 {
459 union DoubleOrInt64 { double doubleValue; int64_t int64Value; };
460 const DoubleOrInt64* dol = reinterpret_cast<const DoubleOrInt64*>(&aDoubleValue);
461 return dol->int64Value;
462 }
463
464
465 // aUnitsInLastPlace is the allowed difference between the least significant digits
466 // of the numbers' floating point representation
467 // Please read the reference paper before trying to use isUlpsEqual
468 // http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
469 inline bool
470 isUlpsEqual(const double aLeft, const double aRight, const int64_t aUnitsInLastPlace)
471 {
472 int64_t longLeft = doubleToInt64(aLeft);
473 // Because of 2's complement, must restore lexicographical order
474 if (longLeft < 0) {
475 longLeft = INT64_C(0x8000000000000000) - longLeft;
476 }
477
478 int64_t longRight = doubleToInt64(aRight);
479 // Because of 2's complement, must restore lexicographical order
480 if (longRight < 0) {
481 longRight = INT64_C(0x8000000000000000) - longRight;
482 }
483
484 int64_t difference = labs(longLeft - longRight);
485 return (difference <= aUnitsInLastPlace);
486 }
487
488 inline bool
489 isUlpsEqual(const float aLeft, const float aRight, const int32_t aUnitsInLastPlace)
490 {
491 int32_t intLeft = floatToInt32(aLeft);
492 // Because of 2's complement, must restore lexicographical order
493 if (intLeft < 0) {
494 intLeft = 0x80000000 - intLeft;
495 }
496
497 int32_t intRight = floatToInt32(aRight);
498 // Because of 2's complement, must restore lexicographical order
499 if (intRight < 0) {
500 intRight = 0x80000000 - intRight;
501 }
502
503 int32_t difference = abs(intLeft - intRight);
504 return (difference <= aUnitsInLastPlace);
505 }
506
507
509
510
511 // ==========> Pow <==================
512
514 template<typename Type>
515 inline Type Pow2(Type x) { return x*x; }
516
518 template<typename Type>
519 inline Type Pow3(Type x) { return x*x*x; }
520
522 template<typename Type>
523 inline Type Pow4(Type x) { return Pow2(Pow2(x)); }
524
526 template<typename Type>
527 Type
528 Pow(Type x, int n)
529 {
530 Type ans = 1;
531 if (n < 0) {
532 n = -n;
533 x = Type(1)/x;
534 }
535 while (n--) ans *= x;
536 return ans;
537 }
538
540 inline float
542 Pow(float b, float e)
543 {
544 assert( b >= 0.0f && "Pow(float,float): base is negative" );
545 return powf(b,e);
546 }
547
548 inline double
549 Pow(double b, double e)
550 {
551 assert( b >= 0.0 && "Pow(double,double): base is negative" );
552 return std::pow(b,e);
553 }
555
556
557 // ==========> Max <==================
558
560 template<typename Type>
561 inline const Type&
562 Max(const Type& a, const Type& b)
563 {
564 return std::max(a,b);
565 }
566
568 template<typename Type>
569 inline const Type&
570 Max(const Type& a, const Type& b, const Type& c)
571 {
572 return std::max(std::max(a,b), c);
573 }
574
576 template<typename Type>
577 inline const Type&
578 Max(const Type& a, const Type& b, const Type& c, const Type& d)
579 {
580 return std::max(std::max(a,b), std::max(c,d));
581 }
582
584 template<typename Type>
585 inline const Type&
586 Max(const Type& a, const Type& b, const Type& c, const Type& d, const Type& e)
587 {
588 return std::max(std::max(a,b), Max(c,d,e));
589 }
590
592 template<typename Type>
593 inline const Type&
594 Max(const Type& a, const Type& b, const Type& c, const Type& d, const Type& e, const Type& f)
595 {
596 return std::max(Max(a,b,c), Max(d,e,f));
597 }
598
600 template<typename Type>
601 inline const Type&
602 Max(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::max(Max(a,b,c,d), Max(e,f,g));
606 }
607
609 template<typename Type>
610 inline const Type&
611 Max(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::max(Max(a,b,c,d), Max(e,f,g,h));
615 }
616
617
618 // ==========> Min <==================
619
621 template<typename Type>
622 inline const Type&
623 Min(const Type& a, const Type& b) { return std::min(a, b); }
624
626 template<typename Type>
627 inline const Type&
628 Min(const Type& a, const Type& b, const Type& c) { return std::min(std::min(a, b), c); }
629
631 template<typename Type>
632 inline const Type&
633 Min(const Type& a, const Type& b, const Type& c, const Type& d)
634 {
635 return std::min(std::min(a, b), std::min(c, d));
636 }
637
639 template<typename Type>
640 inline const Type&
641 Min(const Type& a, const Type& b, const Type& c, const Type& d, const Type& e)
642 {
643 return std::min(std::min(a,b), Min(c,d,e));
644 }
645
647 template<typename Type>
648 inline const Type&
649 Min(const Type& a, const Type& b, const Type& c, const Type& d, const Type& e, const Type& f)
650 {
651 return std::min(Min(a,b,c), Min(d,e,f));
652 }
653
655 template<typename Type>
656 inline const Type&
657 Min(const Type& a, const Type& b, const Type& c, const Type& d,
658 const Type& e, const Type& f, const Type& g)
659 {
660 return std::min(Min(a,b,c,d), Min(e,f,g));
661 }
662
664 template<typename Type>
665 inline const Type&
666 Min(const Type& a, const Type& b, const Type& c, const Type& d,
667 const Type& e, const Type& f, const Type& g, const Type& h)
668 {
669 return std::min(Min(a,b,c,d), Min(e,f,g,h));
670 }
671
672
673 // ============> Exp <==================
674
676 template<typename Type>
677 inline Type Exp(const Type& x) { return std::exp(x); }
678
679 // ============> Sin <==================
680
682 inline float Sin(const float& x) { return std::sin(x); }
684
685 inline double Sin(const double& x) { return std::sin(x); }
687
688 // ============> Cos <==================
689
691 inline float Cos(const float& x) { return std::cos(x); }
693
694 inline double Cos(const double& x) { return std::cos(x); }
696
697
699
700
702 template <typename Type>
703 inline int Sign(const Type &x) { return (zeroVal<Type>() < x) - (x < zeroVal<Type>()); }
704
705
708 template <typename Type>
709 inline bool
710 SignChange(const Type& a, const Type& b)
711 {
712 return ( (a<zeroVal<Type>()) ^ (b<zeroVal<Type>()) );
713 }
714
715
718 template <typename Type>
719 inline bool
720 ZeroCrossing(const Type& a, const Type& b)
721 {
722 return a * b <= zeroVal<Type>();
723 }
724
725
727 inline float Sqrt(float x) { return std::sqrt(x); }
729 inline double Sqrt(double x) { return std::sqrt(x); }
730 inline long double Sqrt(long double x) { return std::sqrt(x); }
732
733
735 inline float Cbrt(float x) { return std::cbrt(x); }
737 inline double Cbrt(double x) { return std::cbrt(x); }
738 inline long double Cbrt(long double x) { return std::cbrt(x); }
740
741
743 inline int Mod(int x, int y) { return (x % y); }
745 inline float Mod(float x, float y) { return std::fmod(x, y); }
746 inline double Mod(double x, double y) { return std::fmod(x, y); }
747 inline long double Mod(long double x, long double y) { return std::fmod(x, y); }
748 template<typename Type> inline Type Remainder(Type x, Type y) { return Mod(x, y); }
750
751
753 inline float RoundUp(float x) { return std::ceil(x); }
755 inline double RoundUp(double x) { return std::ceil(x); }
756 inline long double RoundUp(long double x) { return std::ceil(x); }
758 template<typename Type>
760 inline Type
761 RoundUp(Type x, Type base)
762 {
763 Type remainder = Remainder(x, base);
764 return remainder ? x-remainder+base : x;
765 }
766
767
769 inline float RoundDown(float x) { return std::floor(x); }
771 inline double RoundDown(double x) { return std::floor(x); }
772 inline long double RoundDown(long double x) { return std::floor(x); }
774 template<typename Type>
776 inline Type
777 RoundDown(Type x, Type base)
778 {
779 Type remainder = Remainder(x, base);
780 return remainder ? x-remainder : x;
781 }
782
783
785 inline float Round(float x) { return RoundDown(x + 0.5f); }
787 inline double Round(double x) { return RoundDown(x + 0.5); }
788 inline long double Round(long double x) { return RoundDown(x + 0.5l); }
790
791
794 template<typename Type>
795 inline Type
796 EuclideanRemainder(Type x) { return x - RoundDown(x); }
797
798
800 template<typename Type>
801 inline Type
802 IntegerPart(Type x)
803 {
804 return (x > 0 ? RoundDown(x) : RoundUp(x));
805 }
806
808 template<typename Type>
809 inline Type
810 FractionalPart(Type x) { return Mod(x,Type(1)); }
811
812
814 inline int Floor(float x) { return int(RoundDown(x)); }
816 inline int Floor(double x) { return int(RoundDown(x)); }
817 inline int Floor(long double x) { return int(RoundDown(x)); }
819
820
822 inline int Ceil(float x) { return int(RoundUp(x)); }
824 inline int Ceil(double x) { return int(RoundUp(x)); }
825 inline int Ceil(long double x) { return int(RoundUp(x)); }
827
828
830 template<typename Type>
831 inline Type Chop(Type x, Type delta) { return (Abs(x) < delta ? zeroVal<Type>() : x); }
832
833
835 template<typename Type>
836 inline Type
837 Truncate(Type x, unsigned int digits)
838 {
839 Type tenth = Pow(10,digits);
840 return RoundDown(x*tenth+0.5)/tenth;
841 }
842
843
845
846
849 template<typename T>
850 inline auto PrintCast(const T& val) -> typename std::enable_if<!std::is_same<T, int8_t>::value
851 && !std::is_same<T, uint8_t>::value, const T&>::type { return val; }
852 inline int32_t PrintCast(int8_t val) { return int32_t(val); }
853 inline uint32_t PrintCast(uint8_t val) { return uint32_t(val); }
854
855
857
858
860 template<typename Type>
861 inline Type
862 Inv(Type x)
863 {
864 assert(x);
865 return Type(1)/x;
866 }
867
868
869 enum Axis {
870 X_AXIS = 0,
871 Y_AXIS = 1,
872 Z_AXIS = 2
873 };
874
875 // enum values are consistent with their historical mx analogs.
876 enum RotationOrder {
877 XYZ_ROTATION = 0,
878 XZY_ROTATION,
879 YXZ_ROTATION,
880 YZX_ROTATION,
881 ZXY_ROTATION,
882 ZYX_ROTATION,
883 XZX_ROTATION,
884 ZXZ_ROTATION
885 };
886
887
888 template <typename S, typename T>
889 struct promote {
890 using type = typename boost::numeric::conversion_traits<S, T>::supertype;
891 };
892
893
901 template<typename Vec3T>
902 size_t
903 MinIndex(const Vec3T& v)
904 {
905 static const size_t hashTable[8] = { 2, 1, 9, 1, 2, 9, 0, 0 };//9 is a dummy value
906 const size_t hashKey =
907 ((v[0] < v[1]) << 2) + ((v[0] < v[2]) << 1) + (v[1] < v[2]);// ?*4+?*2+?*1
908 return hashTable[hashKey];
909 }
910
911
919 template<typename Vec3T>
920 size_t
921 MaxIndex(const Vec3T& v)
922 {
923 static const size_t hashTable[8] = { 2, 1, 9, 1, 2, 9, 0, 0 };//9 is a dummy value
924 const size_t hashKey =
925 ((v[0] > v[1]) << 2) + ((v[0] > v[2]) << 1) + (v[1] > v[2]);// ?*4+?*2+?*1
926 return hashTable[hashKey];
927 }
928
929 } // namespace math
930 } // namespace OPENVDB_VERSION_NAME
931 } // namespace openvdb
932
933 #endif // OPENVDB_MATH_MATH_HAS_BEEN_INCLUDED
openvdb::v7_1::math::YXZ_ROTATION
@ YXZ_ROTATION
Definition: Math.h:879
openvdb::v7_1::math::IntegerPart
Type IntegerPart(Type x)
Return the integer part of x.
Definition: Math.h:802
openvdb::v7_1::math::RandInt::operator()
IntType operator()()
Return a randomly-generated integer in the current range.
Definition: Math.h:204
openvdb::v7_1::math::ClampTest01
bool ClampTest01(Type &x)
Return true if x is outside [0,1].
Definition: Math.h:239
openvdb::v7_1::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:666
openvdb::v7_1::math::SignChange
bool SignChange(const Type &a, const Type &b)
Return true if a and b have different signs.
Definition: Math.h:710
openvdb::v7_1::math::XZY_ROTATION
@ XZY_ROTATION
Definition: Math.h:878
openvdb::v7_1::math::Pow
double Pow(double b, double e)
Definition: Math.h:549
openvdb::v7_1::math::Z_AXIS
@ Z_AXIS
Definition: Math.h:872
openvdb::v7_1::math::XYZ_ROTATION
@ XYZ_ROTATION
Definition: Math.h:877
openvdb::v7_1::math::Cbrt
long double Cbrt(long double x)
Definition: Math.h:738
openvdb::v7_1::math::YZX_ROTATION
@ YZX_ROTATION
Definition: Math.h:880
openvdb::v7_1::math::isInfinite
bool isInfinite(const Type &x)
Return true if x is an infinity value (either positive infinity or negative infinity).
Definition: Math.h:354
openvdb::v7_1::math::RandInt::setRange
void setRange(IntType imin, IntType imax)
Change the range over which integers are distributed to [imin, imax].
Definition: Math.h:189
openvdb::v7_1::math::Pow3
Type Pow3(Type x)
Return x3.
Definition: Math.h:519
openvdb::v7_1::math::Floor
int Floor(long double x)
Definition: Math.h:817
openvdb::v7_1::math::RoundDown
Type RoundDown(Type x, Type base)
Return x rounded down to the nearest multiple of base.
Definition: Math.h:777
openvdb::v7_1::math::Rand01::operator()
FloatType operator()()
Return a uniformly distributed random number in the range [0, 1).
Definition: Math.h:155
openvdb::v7_1::math::RandInt::engine
const EngineType & engine() const
Return a const reference to the random number generator.
Definition: Math.h:201
openvdb::v7_1::math::Rand01::setSeed
void setSeed(unsigned int seed)
Set the seed value for the random number generator.
Definition: Math.h:146
openvdb::v7_1::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:703
openvdb::v7_1::math::Clamp01
Type Clamp01(Type x)
Return x clamped to [0, 1].
Definition: Math.h:233
openvdb::v7_1::zeroVal
T zeroVal()
Return the value of type T that corresponds to zero.
Definition: Math.h:59
openvdb::v7_1::math::RandInt
Simple random integer generator.
Definition: Math.h:165
openvdb::v7_1::math::RoundUp
Type RoundUp(Type x, Type base)
Return x rounded up to the nearest multiple of base.
Definition: Math.h:761
openvdb::v7_1::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_1::math::doubleToInt64
int64_t doubleToInt64(const double aDoubleValue)
Definition: Math.h:457
openvdb::v7_1::math::Delta< double >::value
static double value()
Definition: Math.h:119
openvdb::v7_1::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:720
openvdb::v7_1::math::ZXY_ROTATION
@ ZXY_ROTATION
Definition: Math.h:881
openvdb::v7_1::math::floatToInt32
int32_t floatToInt32(const float aFloatValue)
Definition: Math.h:448
openvdb::v7_1::math::promote
Definition: Math.h:889
openvdb::v7_1::math::X_AXIS
@ X_AXIS
Definition: Math.h:870
openvdb::v7_1::math::Rand01
Simple generator of random numbers over the range [0, 1)
Definition: Math.h:129
version.h
Library and file format version numbers.
openvdb::v7_1::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:903
openvdb::v7_1::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:208
openvdb::v7_1::math::Tolerance
Tolerance for floating-point comparison.
Definition: Math.h:110
openvdb::v7_1::math::isNegative< bool >
bool isNegative< bool >(const bool &)
Definition: Math.h:334
Platform.h
openvdb::v7_1::math::Sin
double Sin(const double &x)
Definition: Math.h:685
openvdb::v7_1::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:831
openvdb::v7_1::math::Rand01::Rand01
Rand01(unsigned int seed)
Initialize the generator.
Definition: Math.h:143
openvdb::v7_1::math::Pow4
Type Pow4(Type x)
Return x4.
Definition: Math.h:523
openvdb::v7_1::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:258
openvdb::v7_1::math::Y_AXIS
@ Y_AXIS
Definition: Math.h:871
openvdb::v7_1::math::Pow2
Type Pow2(Type x)
Return x2.
Definition: Math.h:515
openvdb::v7_1::math::RandInt::RandInt
RandInt(unsigned int seed, IntType imin, IntType imax)
Initialize the generator.
Definition: Math.h:183
openvdb::v7_1::math::negative
std::string negative(const std::string &val)
Return the "negation" of the given string.
Definition: Math.h:105
openvdb::v7_1::math::isExactlyEqual
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:408
openvdb::v7_1::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:322
openvdb::v7_1::math::Remainder
Type Remainder(Type x, Type y)
Definition: Math.h:748
openvdb::v7_1::math::RotationOrder
RotationOrder
Definition: Math.h:876
openvdb::v7_1::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:381
openvdb::v7_1::math::ZXZ_ROTATION
@ ZXZ_ROTATION
Definition: Math.h:884
openvdb::v7_1::math::Abs
bool Abs(bool b)
Definition: Math.h:284
openvdb::v7_1::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:611
OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN
#define OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN
Definition: Math.h:47
openvdb::v7_1::math::Mod
long double Mod(long double x, long double y)
Definition: Math.h:747
openvdb::v7_1::operator+
std::string operator+(const std::string &s, double)
Definition: Math.h:72
openvdb::v7_1::math::Rand01::Rand01
Rand01(const EngineType &engine)
Initialize the generator.
Definition: Math.h:139
openvdb::v7_1::math::Sqrt
long double Sqrt(long double x)
Definition: Math.h:730
openvdb::v7_1::math::isUlpsEqual
bool isUlpsEqual(const float aLeft, const float aRight, const int32_t aUnitsInLastPlace)
Definition: Math.h:489
openvdb::v7_1::math::Tolerance< double >::value
static double value()
Definition: Math.h:112
openvdb::v7_1::math::Ceil
int Ceil(long double x)
Definition: Math.h:825
openvdb::v7_1::math::Round
long double Round(long double x)
Definition: Math.h:788
openvdb::v7_1::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:399
openvdb::v7_1::math::pi
constexpr float pi()
Definition: Math.h:82
openvdb::v7_1::math::Exp
Type Exp(const Type &x)
Return ex.
Definition: Math.h:677
openvdb::v7_1::math::isFinite
bool isFinite(const Type &x)
Return true if x is finite.
Definition: Math.h:344
OPENVDB_EXACT_IS_APPROX_EQUAL
#define OPENVDB_EXACT_IS_APPROX_EQUAL(T)
Definition: Math.h:386
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:146
openvdb::v7_1::math::Inv
Type Inv(Type x)
Return the inverse of x.
Definition: Math.h:862
openvdb::v7_1::math::EuclideanRemainder
Type EuclideanRemainder(Type x)
Definition: Math.h:796
openvdb::v7_1::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:921
openvdb::v7_1::math::isNegative
bool isNegative(const Type &x)
Return true if x is less than zero.
Definition: Math.h:331
openvdb::v7_1::math::Delta
Delta for small floating-point offsets.
Definition: Math.h:117
openvdb::v7_1::math::PrintCast
uint32_t PrintCast(uint8_t val)
Definition: Math.h:853
openvdb::v7_1::math::Clamp
Type Clamp(Type x, Type min, Type max)
Return x clamped to [min, max].
Definition: Math.h:223
openvdb::v7_1::math::promote::type
typename boost::numeric::conversion_traits< S, T >::supertype type
Definition: Math.h:890
openvdb::v7_1::math::Tolerance< float >::value
static float value()
Definition: Math.h:111
openvdb::v7_1::math::Rand01< double, RandomGenerator >::ValueType
double ValueType
Definition: Math.h:135
openvdb::v7_1::math::RandInt::RandInt
RandInt(const EngineType &engine, IntType imin, IntType imax)
Initialize the generator.
Definition: Math.h:175
openvdb::v7_1::math::XZX_ROTATION
@ XZX_ROTATION
Definition: Math.h:883
std
Definition: Coord.h:587
openvdb::v7_1::math::Rand01::engine
const EngineType & engine() const
Return a const reference to the random number generator.
Definition: Math.h:152
openvdb::v7_1::math::Truncate
Type Truncate(Type x, unsigned int digits)
Return x truncated to the given number of decimal digits.
Definition: Math.h:837
openvdb::v7_1::math::ZYX_ROTATION
@ ZYX_ROTATION
Definition: Math.h:882
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:94
openvdb::v7_1::math::Cos
double Cos(const double &x)
Definition: Math.h:694
openvdb::v7_1::math::isZero
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition: Math.h:301
openvdb::v7_1::math::isNan
bool isNan(const Type &x)
Return true if x is a NaN (Not-A-Number) value.
Definition: Math.h:364
openvdb
Definition: Exceptions.h:13
openvdb::v7_1::math::isRelOrApproxEqual
bool isRelOrApproxEqual(const bool &a, const bool &b, const bool &, const bool &)
Definition: Math.h:438
openvdb::v7_1::zeroVal< bool >
bool zeroVal< bool >()
Return the bool value that corresponds to zero.
Definition: Math.h:63
openvdb::v7_1::math::RandInt::setSeed
void setSeed(unsigned int seed)
Set the seed value for the random number generator.
Definition: Math.h:195
openvdb::v7_1::math::Delta< float >::value
static float value()
Definition: Math.h:118
openvdb::v7_1::math::FractionalPart
Type FractionalPart(Type x)
Return the fractional part of x.
Definition: Math.h:810
openvdb::v7_1::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_1::math::Axis
Axis
Definition: Math.h:869
OPENVDB_NO_FP_EQUALITY_WARNING_END
#define OPENVDB_NO_FP_EQUALITY_WARNING_END
Definition: Math.h:48