OpenVDB  9.0.1
Classes | Namespaces | Macros | Typedefs | Enumerations | Functions
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 <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

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

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

#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; } \
#define OPENVDB_IS_POD (   Type)
Value:
#Type" must be a POD type (satisfy StandardLayoutType.)"); \
#Type" must be a POD type (satisfy TrivialType.)");
ValueT value
Definition: GridBuilder.h:1287
#define OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN
#define OPENVDB_NO_FP_EQUALITY_WARNING_END