Loading...
Searching...
No Matches
Math.h File Reference

General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at least arbitrary numeric value types). More...

`#include <openvdb/Platform.h>`
`#include <openvdb/version.h>`
`#include <boost/numeric/conversion/conversion_traits.hpp>`
`#include <algorithm>`
`#include <cassert>`
`#include <cmath>`
`#include <cstdlib>`
`#include <cstring>`
`#include <random>`
`#include <string>`
`#include <type_traits>`

Go to the source code of this file.

## Classes

struct | Tolerance< T >
| Tolerance for floating-point comparison. More...
struct | Tolerance< float >
struct | Tolerance< double >
struct | Delta< T >
| Delta for small floating-point offsets. More...
struct | Delta< float >
struct | Delta< double >
class | Rand01< FloatType, EngineType >
| Simple generator of random numbers over the range [0, 1). More...
class | RandInt< IntType, EngineType >
| Simple random integer generator. More...
struct | promote< S, T >

## Namespaces

namespace | openvdb
namespace | openvdb::v10_0
namespace | openvdb::v10_0::math

## Macros

#define | OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN
#define | OPENVDB_NO_FP_EQUALITY_WARNING_END
#define | OPENVDB_IS_POD(Type)
#define | OPENVDB_EXACT_IS_APPROX_EQUAL(T)

## Typedefs

using | Random01 = Rand01<double, std::mt19937>
using | RandomInt = RandInt<int, std::mt19937>

## Enumerations

enum | Axis { X_AXIS = 0 , Y_AXIS = 1 , Z_AXIS = 2 }
enum | RotationOrder { XYZ_ROTATION = 0 , XZY_ROTATION , YXZ_ROTATION , YZX_ROTATION , ZXY_ROTATION , ZYX_ROTATION , XZX_ROTATION , ZXZ_ROTATION }

## Functions

template<typename T>
T | zeroVal ()
| Return the value of type T that corresponds to zero.
template<>
std::string | zeroVal< std::string > ()
| Return the `std::string` value that corresponds to zero.
template<>
bool | zeroVal< bool > ()
| Return the `bool` value that corresponds to zero.
std::string | operator+ (const std::string &s, bool)
| Needed to support the (zeroVal<ValueType>() + val) idiom when `ValueType` is `std::string`.
std::string | operator+ (const std::string &s, int)
std::string | operator+ (const std::string &s, float)
std::string | operator+ (const std::string &s, double)
template<typename Type1, typename Type2>
auto | cwiseAdd (const Type1 &v, const Type2 s)
| Componentwise adder for POD types.
template<typename Type1, typename Type2>
bool | cwiseLessThan (const Type1 &a, const Type2 &b)
| Componentwise less than for POD types.
template<typename Type1, typename Type2>
bool | cwiseGreaterThan (const Type1 &a, const Type2 &b)
| Componentwise greater than for POD types.
template<typename T>
constexpr T | pi ()
| Pi constant taken from Boost to match old behaviour.
template<>
constexpr float | pi ()
template<>
constexpr double | pi ()
template<>
constexpr long double | pi ()
template<typename T>
T | negative (const T &val)
| Return the unary negation of the given value.
template<>
bool | negative (const bool &val)
| Return the negation of the given boolean.
template<>
std::string | negative (const std::string &val)
| Return the "negation" of the given string.
template<typename Type>
Type | Clamp (Type x, Type min, Type max)
| Return x clamped to [min, max].
template<typename Type>
Type | Clamp01 (Type x)
| Return x clamped to [0, 1].
template<typename Type>
bool | ClampTest01 (Type &x)
| Return `true` if x is outside [0,1].
template<typename Type>
Type | SmoothUnitStep (Type x)
| Return 0 if x < 0, 1 if x > 1 or else (3 − 2 x) x².
template<typename Type>
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).
int32_t | Abs (int32_t i)
| Return the absolute value of the given quantity.
int64_t | Abs (int64_t i)
float | Abs (float x)
double | Abs (double x)
long double | Abs (long double x)
uint32_t | Abs (uint32_t i)
uint64_t | Abs (uint64_t i)
bool | Abs (bool b)
template<typename T>
std::enable_if< std::is_same< T, size_t >::value, T >::type | Abs (T i)
template<typename Type>
bool | isZero (const Type &x)
| Return `true` if x is exactly equal to zero.
template<typename Type>
bool | isApproxZero (const Type &x)
| Return `true` if x is equal to zero to within the default floating-point comparison tolerance.
template<typename Type>
bool | isApproxZero (const Type &x, const Type &tolerance)
| Return `true` if x is equal to zero to within the given tolerance.
template<typename Type>
bool | isNegative (const Type &x)
| Return `true` if x is less than zero.
template<>
bool | isNegative< bool > (const bool &)
bool | isFinite (const float x)
| Return `true` if x is finite.
template<typename Type, typename std::enable_if< std::is_arithmetic< Type >::value, int >::type = 0>
bool | isFinite (const Type &x)
| Return `true` if x is finite.
bool | isInfinite (const float x)
| Return `true` if x is an infinity value (either positive infinity or negative infinity).
template<typename Type, typename std::enable_if< std::is_arithmetic< Type >::value, int >::type = 0>
bool | isInfinite (const Type &x)
| Return `true` if x is an infinity value (either positive infinity or negative infinity).
bool | isNan (const float x)
| Return `true` if x is a NaN (Not-A-Number) value.
template<typename Type, typename std::enable_if< std::is_arithmetic< Type >::value, int >::type = 0>
bool | isNan (const Type &x)
| Return `true` if x is a NaN (Not-A-Number) value.
template<typename Type>
bool | isApproxEqual (const Type &a, const Type &b, const Type &tolerance)
| Return `true` if a is equal to b to within the given tolerance.
template<typename Type>
bool | isApproxEqual (const Type &a, const Type &b)
| Return `true` if a is equal to b to within the default floating-point comparison tolerance.
template<>
bool | isApproxEqual< bool > (const bool &a, const bool &b)
template<>
bool | isApproxEqual< bool > (const bool &a, const bool &b, const bool &)
template<>
bool | isApproxEqual< std::string > (const std::string &a, const std::string &b)
template<>
bool | isApproxEqual< std::string > (const std::string &a, const std::string &b, const std::string &)
template<typename Type>
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.
template<typename T0, typename T1>
bool | isExactlyEqual (const T0 &a, const T1 &b)
| Return `true` if a is exactly equal to b.
template<typename Type>
bool | isRelOrApproxEqual (const Type &a, const Type &b, const Type &absTol, const Type &relTol)
template<>
bool | isRelOrApproxEqual (const bool &a, const bool &b, const bool &, const bool &)
int32_t | floatToInt32 (const float f)
int64_t | doubleToInt64 (const double d)
bool | isUlpsEqual (const double aLeft, const double aRight, const int64_t aUnitsInLastPlace)
bool | isUlpsEqual (const float aLeft, const float aRight, const int32_t aUnitsInLastPlace)
template<typename Type>
Type | Pow2 (Type x)
| Return x2.
template<typename Type>
Type | Pow3 (Type x)
| Return x3.
template<typename Type>
Type | Pow4 (Type x)
| Return x4.
template<typename Type>
Type | Pow (Type x, int n)
| Return xn.
float | Pow (float b, float e)
| Return be.
double | Pow (double b, double e)
template<typename Type>
const Type & | Max (const Type &a, const Type &b)
| Return the maximum of two values.
template<typename Type>
const Type & | Max (const Type &a, const Type &b, const Type &c)
| Return the maximum of three values.
template<typename Type>
const Type & | Max (const Type &a, const Type &b, const Type &c, const Type &d)
| Return the maximum of four values.
template<typename Type>
const Type & | Max (const Type &a, const Type &b, const Type &c, const Type &d, const Type &e)
| Return the maximum of five values.
template<typename Type>
const Type & | Max (const Type &a, const Type &b, const Type &c, const Type &d, const Type &e, const Type &f)
| Return the maximum of six values.
template<typename Type>
const Type & | Max (const Type &a, const Type &b, const Type &c, const Type &d, const Type &e, const Type &f, const Type &g)
| Return the maximum of seven values.
template<typename Type>
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.
template<typename Type>
const Type & | Min (const Type &a, const Type &b)
| Return the minimum of two values.
template<typename Type>
const Type & | Min (const Type &a, const Type &b, const Type &c)
| Return the minimum of three values.
template<typename Type>
const Type & | Min (const Type &a, const Type &b, const Type &c, const Type &d)
| Return the minimum of four values.
template<typename Type>
const Type & | Min (const Type &a, const Type &b, const Type &c, const Type &d, const Type &e)
| Return the minimum of five values.
template<typename Type>
const Type & | Min (const Type &a, const Type &b, const Type &c, const Type &d, const Type &e, const Type &f)
| Return the minimum of six values.
template<typename Type>
const Type & | Min (const Type &a, const Type &b, const Type &c, const Type &d, const Type &e, const Type &f, const Type &g)
| Return the minimum of seven values.
template<typename Type>
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.
template<typename Type>
Type | Exp (const Type &x)
| Return ex.
float | Sin (const float &x)
| Return sin x.
double | Sin (const double &x)
float | Cos (const float &x)
| Return cos x.
double | Cos (const double &x)
template<typename Type>
int | Sign (const Type &x)
| Return the sign of the given value as an integer (either -1, 0 or 1).
template<typename Type>
bool | SignChange (const Type &a, const Type &b)
| Return `true` if a and b have different signs.
template<typename Type>
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 different signs.
float | Sqrt (float x)
| Return the square root of a floating-point value.
double | Sqrt (double x)
long double | Sqrt (long double x)
float | Cbrt (float x)
| Return the cube root of a floating-point value.
double | Cbrt (double x)
long double | Cbrt (long double x)
int | Mod (int x, int y)
| Return the remainder of x / y.
float | Mod (float x, float y)
double | Mod (double x, double y)
long double | Mod (long double x, long double y)
template<typename Type>
Type | Remainder (Type x, Type y)
float | RoundUp (float x)
| Return x rounded up to the nearest integer.
double | RoundUp (double x)
long double | RoundUp (long double x)
template<typename Type>
Type | RoundUp (Type x, Type base)
| Return x rounded up to the nearest multiple of base.
float | RoundDown (float x)
| Return x rounded down to the nearest integer.
double | RoundDown (double x)
long double | RoundDown (long double x)
template<typename Type>
Type | RoundDown (Type x, Type base)
| Return x rounded down to the nearest multiple of base.
float | Round (float x)
| Return x rounded to the nearest integer.
double | Round (double x)
long double | Round (long double x)
template<typename Type>
Type | EuclideanRemainder (Type x)
template<typename Type>
Type | IntegerPart (Type x)
| Return the integer part of x.
template<typename Type>
Type | FractionalPart (Type x)
| Return the fractional part of x.
int | Floor (float x)
| Return the floor of x.
int | Floor (double x)
int | Floor (long double x)
int | Ceil (float x)
| Return the ceiling of x.
int | Ceil (double x)
int | Ceil (long double x)
template<typename Type>
Type | Chop (Type x, Type delta)
| Return x if it is greater or equal in magnitude than delta. Otherwise, return zero.
template<typename Type>
Type | Truncate (Type x, unsigned int digits)
| Return x truncated to the given number of decimal digits.
template<typename T>
auto | PrintCast (const T &val) -> typename std::enable_if<!std::is_same< T, int8_t >::value &&!std::is_same< T, uint8_t >::value, const T & >::type
| 8-bit integer values print to std::ostreams as characters. Cast them so that they print as integers instead.
int32_t | PrintCast (int8_t val)
uint32_t | PrintCast (uint8_t val)
template<typename Type>
Type | Inv (Type x)
| Return the inverse of x.
template<typename Vec3T>
size_t | MinIndex (const Vec3T &v)
| Return the index [0,1,2] of the smallest value in a 3D vector.
template<typename Vec3T>
size_t | MaxIndex (const Vec3T &v)
| Return the index [0,1,2] of the largest value in a 3D vector.

## Detailed Description

General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at least arbitrary numeric value types).

## Macro Definition Documentation

## OPENVDB_EXACT_IS_APPROX_EQUAL

#define OPENVDB_EXACT_IS_APPROX_EQUAL | ( |  | T | ) |

Value:
template<> inline bool isApproxEqual<T>(const T& a, const T& b) { return a == b; } \
template<> inline bool isApproxEqual<T>(const T& a, const T& b, const T&) { return a == b; } \

## OPENVDB_IS_POD

#define OPENVDB_IS_POD | ( |  | Type | ) |

Value:
static_assert(std::is_standard_layout<Type>::value, \
#Type" must be a POD type (satisfy StandardLayoutType.)"); \
static_assert(std::is_trivial<Type>::value, \
#Type" must be a POD type (satisfy TrivialType.)");

## OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN

#define OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN

## OPENVDB_NO_FP_EQUALITY_WARNING_END

#define OPENVDB_NO_FP_EQUALITY_WARNING_END