Math API nvidia_logo_transpbg.gif Up
vector.h File Reference

Math vector class template of fixed dimension with arithmetic operators and generic functions. More...

Go to the source code of this file.

Classes

struct  mi::math::Color_struct
 Generic storage class template for an RGBA color representation storing four floating points elements. More...
 
struct  mi::math::Vector_struct<T, DIM>
 Generic storage class template for math vector representations storing DIM elements of type T. More...
 
struct  mi::math::Vector_struct<T, 1>
 Specialization for dimension 1 to create x member. More...
 
struct  mi::math::Vector_struct<T, 2>
 Specialization for dimension 2 to create x and y member. More...
 
struct  mi::math::Vector_struct<T, 3>
 Specialization for dimension 3 to create x, y, and z members. More...
 
struct  mi::math::Vector_struct<T, 4>
 Specialization for dimension 4 to create x, y, z, and w members. More...
 
class  mi::math::Vector<T, DIM>
 Fixed-size math vector class template with generic operations. More...
 

Namespaces

namespace  mi
 Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH.
 
namespace  mi::math
 Namespace for the Math API.
 

Enumerations

enum  mi::math::From_iterator_tag { mi::math::FROM_ITERATOR }
 Enum used for initializing a vector from an iterator. More...
 

Functions

template<typename T , Size DIM>
T * mi::math::vector_base_ptr (Vector_struct<T, DIM> &vec)
 Returns the base pointer to the vector data. More...
 
template<typename T , Size DIM>
const T * mi::math::vector_base_ptr (const Vector_struct<T, DIM> &vec)
 Returns the base pointer to the vector data. More...
 
template<typename T>
T * mi::math::vector_base_ptr (Vector_struct<T, 1> &vec)
 Returns the base pointer to the vector data, specialization for DIM==1. More...
 
template<typename T>
const T * mi::math::vector_base_ptr (const Vector_struct<T, 1> &vec)
 Returns the base pointer to the vector data, specialization for DIM==1. More...
 
template<typename T>
T * mi::math::vector_base_ptr (Vector_struct<T, 2> &vec)
 Returns the base pointer to the vector data, specialization for DIM==2. More...
 
template<typename T>
const T * mi::math::vector_base_ptr (const Vector_struct<T, 2> &vec)
 Returns the base pointer to the vector data, specialization for DIM==2. More...
 
template<typename T>
T * mi::math::vector_base_ptr (Vector_struct<T, 3> &vec)
 Returns the base pointer to the vector data, specialization for DIM==3. More...
 
template<typename T>
const T * mi::math::vector_base_ptr (const Vector_struct<T, 3> &vec)
 Returns the base pointer to the vector data, specialization for DIM==3. More...
 
template<typename T>
T * mi::math::vector_base_ptr (Vector_struct<T, 4> &vec)
 Returns the base pointer to the vector data, specialization for DIM==4. More...
 
template<typename T>
const T * mi::math::vector_base_ptr (const Vector_struct<T, 4> &vec)
 Returns the base pointer to the vector data, specialization for DIM==4. More...
 
template<typename T , Size DIM>
Vector<T, DIM> & mi::math::operator+= (Vector<T, DIM> &lhs, const Vector_struct<T, DIM> &rhs)
 Adds rhs elementwise to lhs and returns the modified lhs. More...
 
template<typename T , Size DIM>
Vector<T, DIM> & mi::math::operator-= (Vector<T, DIM> &lhs, const Vector_struct<T, DIM> &rhs)
 Subtracts rhs elementwise from lhs and returns the modified lhs. More...
 
template<typename T , Size DIM>
Vector<T, DIM> & mi::math::operator*= (Vector<T, DIM> &lhs, const Vector_struct<T, DIM> &rhs)
 Multiplies rhs elementwise with lhs and returns the modified lhs. More...
 
template<typename T , Size DIM>
Vector<T, DIM> & mi::math::operator%= (Vector<T, DIM> &lhs, const Vector_struct<T, DIM> &rhs)
 Computes lhs modulo rhs elementwise and returns the modified lhs. More...
 
template<typename T , typename U , Size DIM>
Vector<T, DIM> & mi::math::operator/= (Vector<T, DIM> &lhs, const Vector_struct<U, DIM> &rhs)
 Divides lhs elementwise by rhs and returns the modified lhs. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::operator+ (const Vector_struct<T, DIM> &lhs, const Vector_struct<T, DIM> &rhs)
 Adds lhs and rhs elementwise and returns the new result. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::operator- (const Vector_struct<T, DIM> &lhs, const Vector_struct<T, DIM> &rhs)
 Subtracts rhs elementwise from lhs and returns the new result. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::operator* (const Vector_struct<T, DIM> &lhs, const Vector_struct<T, DIM> &rhs)
 Multiplies rhs elementwise with lhs and returns the new result. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::operator% (const Vector_struct<T, DIM> &lhs, const Vector_struct<T, DIM> &rhs)
 Computes lhs modulo rhs elementwise and returns the new result. More...
 
template<typename T , typename U , Size DIM>
Vector<T, DIM> mi::math::operator/ (const Vector_struct<T, DIM> &lhs, const Vector_struct<U, DIM> &rhs)
 Divides rhs elementwise by lhs and returns the new result. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::operator- (const Vector_struct<T, DIM> &v)
 Negates the vector v elementwise and returns the new result. More...
 
template<typename T , Size DIM>
Vector<T, DIM> & mi::math::operator+= (Vector<T, DIM> &lhs, const Vector<T, DIM> &rhs)
 Adds rhs elementwise to lhs and returns the modified lhs. More...
 
template<typename T , Size DIM>
Vector<T, DIM> & mi::math::operator-= (Vector<T, DIM> &lhs, const Vector<T, DIM> &rhs)
 Subtracts rhs elementwise from lhs and returns the modified lhs. More...
 
template<typename T , Size DIM>
Vector<T, DIM> & mi::math::operator*= (Vector<T, DIM> &lhs, const Vector<T, DIM> &rhs)
 Multiplies rhs elementwise with lhs and returns the modified lhs. More...
 
template<typename T , Size DIM>
Vector<T, DIM> & mi::math::operator%= (Vector<T, DIM> &lhs, const Vector<T, DIM> &rhs)
 Computes lhs modulo rhs elementwise and returns the modified lhs. More...
 
template<typename T , typename U , Size DIM>
Vector<T, DIM> & mi::math::operator/= (Vector<T, DIM> &lhs, const Vector<U, DIM> &rhs)
 Divides lhs elementwise by rhs and returns the modified lhs. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::operator+ (const Vector<T, DIM> &lhs, const Vector<T, DIM> &rhs)
 Adds lhs and rhs elementwise and returns the new result. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::operator- (const Vector<T, DIM> &lhs, const Vector<T, DIM> &rhs)
 Subtracts rhs elementwise from lhs and returns the new result. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::operator* (const Vector<T, DIM> &lhs, const Vector<T, DIM> &rhs)
 Multiplies rhs elementwise with lhs and returns the new result. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::operator% (const Vector<T, DIM> &lhs, const Vector<T, DIM> &rhs)
 Computes lhs modulo rhs elementwise and returns the new result. More...
 
template<typename T , typename U , Size DIM>
Vector<T, DIM> mi::math::operator/ (const Vector<T, DIM> &lhs, const Vector<U, DIM> &rhs)
 Divides rhs elementwise by lhs and returns the new result. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::operator- (const Vector<T, DIM> &v)
 Negates the vector v elementwise and returns the new result. More...
 
template<typename T , typename TT , Size DIM>
Vector<T, DIM> & mi::math::operator*= (Vector<T, DIM> &v, TT s)
 Multiplies the vector v elementwise with the scalar s and returns the modified vector v. More...
 
template<typename T , typename TT , Size DIM>
Vector<T, DIM> & mi::math::operator%= (Vector<T, DIM> &v, TT s)
 Computes v modulo s elementwise and returns the modified vector v. More...
 
template<typename T , typename TT , Size DIM>
Vector<T, DIM> & mi::math::operator/= (Vector<T, DIM> &v, TT s)
 Divides the vector v elementwise by the scalar s and returns the modified vector v. More...
 
template<typename T , typename TT , Size DIM>
Vector<T, DIM> mi::math::operator* (const Vector_struct<T, DIM> &v, TT s)
 Multiplies the vector v elementwise with the scalar s and returns the new result. More...
 
template<typename T , typename TT , Size DIM>
Vector<T, DIM> mi::math::operator* (TT s, const Vector_struct<T, DIM> &v)
 Multiplies the vector v elementwise with the scalar s and returns the new result. More...
 
template<typename T , typename TT , Size DIM>
Vector<T, DIM> mi::math::operator% (const Vector_struct<T, DIM> &v, TT s)
 Computes v modulo s elementwise and returns the new result. More...
 
template<typename T , typename TT , Size DIM>
Vector<T, DIM> mi::math::operator/ (const Vector_struct<T, DIM> &v, TT s)
 Divides the vector v elementwise by the scalar s and returns the new result. More...
 
template<typename T , Size DIM>
Vector<T, DIM> & mi::math::operator++ (Vector<T, DIM> &vec)
 Pre-increments all elements of vec and returns the result. Modifies vec. More...
 
template<typename T , Size DIM>
Vector<T, DIM> & mi::math::operator-- (Vector<T, DIM> &vec)
 Pre-decrements all elements of vec and returns the result. Modifies vec. More...
 
template<Size DIM>
Vector<bool, DIM> mi::math::operator&& (const Vector<bool, DIM> &lhs, const Vector<bool, DIM> &rhs)
 Returns the elementwise logical and of two boolean vectors. More...
 
template<Size DIM>
Vector<bool, DIM> mi::math::operator&& (bool lhs, const Vector<bool, DIM> &rhs)
 Returns the elementwise logical and of a bool and a boolean vector. More...
 
template<Size DIM>
Vector<bool, DIM> mi::math::operator&& (const Vector<bool, DIM> &lhs, bool rhs)
 Returns the elementwise logical and of a boolean vector and a bool. More...
 
template<Size DIM>
Vector<bool, DIM> mi::math::operator|| (const Vector<bool, DIM> &lhs, const Vector<bool, DIM> &rhs)
 Returns the elementwise logical or of two boolean vectors. More...
 
template<Size DIM>
Vector<bool, DIM> mi::math::operator|| (bool lhs, const Vector<bool, DIM> &rhs)
 Returns the elementwise logical or of a bool and a boolean vector. More...
 
template<Size DIM>
Vector<bool, DIM> mi::math::operator|| (const Vector<bool, DIM> &lhs, bool rhs)
 Returns the elementwise logical or of a boolean vector and a bool. More...
 
template<Size DIM>
Vector<bool, DIM> mi::math::operator^ (const Vector<bool, DIM> &lhs, const Vector<bool, DIM> &rhs)
 Returns the elementwise logical xor of two boolean vectors. More...
 
template<Size DIM>
Vector<bool, DIM> mi::math::operator^ (bool lhs, const Vector<bool, DIM> &rhs)
 Returns the elementwise logical xor of a bool and a boolean vector. More...
 
template<Size DIM>
Vector<bool, DIM> mi::math::operator^ (const Vector<bool, DIM> &lhs, bool rhs)
 Returns the elementwise logical xor of a boolean vector and a bool. More...
 
template<Size DIM>
Vector<bool, DIM> mi::math::operator! (const Vector<bool, DIM> &vec)
 Returns the elementwise logical not of a boolean vector. More...
 
template<typename T , Size DIM>
Vector<bool, DIM> mi::math::elementwise_is_equal (const Vector<T, DIM> &lhs, const Vector<T, DIM> &rhs)
 Returns the boolean vector result of an elementwise equality comparison. More...
 
template<typename T , Size DIM>
Vector<bool, DIM> mi::math::elementwise_is_not_equal (const Vector<T, DIM> &lhs, const Vector<T, DIM> &rhs)
 Returns the boolean vector result of an elementwise inequality comparison. More...
 
template<typename T , Size DIM>
Vector<bool, DIM> mi::math::elementwise_is_less_than (const Vector<T, DIM> &lhs, const Vector<T, DIM> &rhs)
 Returns the boolean vector result of an elementwise less-than comparison. More...
 
template<typename T , Size DIM>
Vector<bool, DIM> mi::math::elementwise_is_less_than_or_equal (const Vector<T, DIM> &lhs, const Vector<T, DIM> &rhs)
 Returns the boolean vector result of an elementwise less-than-or-equal comparison. More...
 
template<typename T , Size DIM>
Vector<bool, DIM> mi::math::elementwise_is_greater_than (const Vector<T, DIM> &lhs, const Vector<T, DIM> &rhs)
 Returns the boolean vector result of an elementwise greater-than comparison. More...
 
template<typename T , Size DIM>
Vector<bool, DIM> mi::math::elementwise_is_greater_than_or_equal (const Vector<T, DIM> &lhs, const Vector<T, DIM> &rhs)
 Returns the boolean vector result of an elementwise greater-than-or-equal comparison. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::abs (const Vector_struct<T, DIM> &v)
 Returns a vector with the elementwise absolute values of the vector v. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::acos (const Vector_struct<T, DIM> &v)
 Returns a vector with the elementwise arc cosine of the vector v. More...
 
template<typename T , Size DIM>
bool mi::math::all (const Vector_struct<T, DIM> &v)
 Returns true if all of all elements of v returns true. More...
 
template<typename T , Size DIM>
bool mi::math::any (const Vector_struct<T, DIM> &v)
 Returns true if any of any element of v returns true. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::asin (const Vector_struct<T, DIM> &v)
 Returns a vector with the elementwise arc sine of the vector v. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::atan (const Vector_struct<T, DIM> &v)
 Returns a vector with the elementwise arc tangent of the vector v. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::atan2 (const Vector_struct<T, DIM> &v, const Vector_struct<T, DIM> &w)
 Returns a vector with the elementwise arc tangent of the vector v / w. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::ceil (const Vector_struct<T, DIM> &v)
 Returns a vector with the elementwise smallest integral value that is not less than the element in vector v. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::clamp (const Vector_struct<T, DIM> &v, const Vector_struct<T, DIM> &low, const Vector_struct<T, DIM> &high)
 Returns the vector v elementwise clamped to the range [low, high]. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::clamp (const Vector_struct<T, DIM> &v, const Vector_struct<T, DIM> &low, T high)
 Returns the vector v elementwise clamped to the range [low, high]. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::clamp (const Vector_struct<T, DIM> &v, T low, const Vector_struct<T, DIM> &high)
 Returns the vector v elementwise clamped to the range [low, high]. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::clamp (const Vector_struct<T, DIM> &v, T low, T high)
 Returns the vector v elementwise clamped to the range [low, high]. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::cos (const Vector_struct<T, DIM> &v)
 Returns a vector with the elementwise cosine of the vector v. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::degrees (const Vector_struct<T, DIM> &v)
 Converts elementwise radians in v to degrees. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::elementwise_max (const Vector_struct<T, DIM> &lhs, const Vector_struct<T, DIM> &rhs)
 Returns elementwise maximum of two vectors. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::elementwise_min (const Vector_struct<T, DIM> &lhs, const Vector_struct<T, DIM> &rhs)
 Returns elementwise minimum of two vectors. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::exp (const Vector_struct<T, DIM> &v)
 Returns a vector with elementwise e to the power of the element in the vector v. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::exp2 (const Vector_struct<T, DIM> &v)
 Returns a vector with elementwise 2 to the power of the element in the vector v. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::floor (const Vector_struct<T, DIM> &v)
 Returns a vector with the elementwise largest integral value that is not greater than the element in vector v. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::fmod (const Vector_struct<T, DIM> &a, const Vector_struct<T, DIM> &b)
 Returns elementwise a modulo b, in other words, the remainder of a/b. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::fmod (const Vector_struct<T, DIM> &a, T b)
 Returns elementwise a modulo b, in other words, the remainder of a/b. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::frac (const Vector_struct<T, DIM> &v)
 Returns a vector with the elementwise positive fractional part of the vector v. More...
 
template<typename T , Size DIM>
bool mi::math::is_approx_equal (const Vector_struct<T, DIM> &left, const Vector_struct<T, DIM> &right, T e)
 Compares the two given values elementwise for equality within the given epsilon. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::lerp (const Vector_struct<T, DIM> &v1, const Vector_struct<T, DIM> &v2, const Vector_struct<T, DIM> &t)
 Returns the elementwise linear interpolation between v1 and v2, i.e., it returns (1-t) * v1 + t * v2. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::lerp (const Vector_struct<T, DIM> &v1, const Vector_struct<T, DIM> &v2, T t)
 Returns the linear interpolation between v1 and v2, i.e., it returns (1-t) * v1 + t * v2. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::log (const Vector_struct<T, DIM> &v)
 Returns a vector with the elementwise natural logarithm of the vector v. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::log2 (const Vector_struct<T, DIM> &v)
 Returns a vector with the elementwise base 2 logarithm of the vector v. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::log10 (const Vector_struct<T, DIM> &v)
 Returns a vector with the elementwise base 10 logarithm of the vector v. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::modf (const Vector_struct<T, DIM> &v, Vector<T, DIM> &i)
 Returns the elementwise fractional part of v and stores the elementwise integral part of v in i. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::pow (const Vector_struct<T, DIM> &a, const Vector_struct<T, DIM> &b)
 Returns the vector a elementwise to the power of b. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::pow (const Vector_struct<T, DIM> &a, T b)
 Returns the vector a elementwise to the power of b. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::radians (const Vector_struct<T, DIM> &v)
 Converts elementwise degrees in v to radians. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::round (const Vector_struct<T, DIM> &v)
 Returns a vector with the elements of vector v rounded to nearest integers. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::rsqrt (const Vector_struct<T, DIM> &v)
 Returns the reciprocal of the square root of each element of v. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::saturate (const Vector_struct<T, DIM> &v)
 Returns the vector v clamped elementwise to the range [0,1]. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::sign (const Vector_struct<T, DIM> &v)
 Returns the elementwise sign of vector v. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::sin (const Vector_struct<T, DIM> &v)
 Returns a vector with the elementwise sine of the vector v. More...
 
template<typename T , Size DIM>
void mi::math::sincos (const Vector_struct<T, DIM> &a, Vector<T, DIM> &s, Vector<T, DIM> &c)
 Computes elementwise the sine s and cosine c of angles a simultaneously. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::smoothstep (const Vector_struct<T, DIM> &a, const Vector_struct<T, DIM> &b, const Vector_struct<T, DIM> &v)
 Returns 0 if v is less than a and 1 if v is greater than b in an elementwise fashion. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::smoothstep (const Vector_struct<T, DIM> &a, const Vector_struct<T, DIM> &b, T x)
 Returns 0 if x is less than a and 1 if x is greater than b in an elementwise fashion. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::sqrt (const Vector_struct<T, DIM> &v)
 Returns the square root of each element of v. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::step (const Vector_struct<T, DIM> &a, const Vector_struct<T, DIM> &v)
 Returns elementwise 0 if v is less than a and 1 otherwise. More...
 
template<typename T , Size DIM>
Vector<T, DIM> mi::math::tan (const Vector_struct<T, DIM> &v)
 Returns a vector with the elementwise tangent of the vector v. More...
 
template<typename T>
mi::math::cross (const Vector_struct<T, 2> &lhs, const Vector_struct<T, 2> &rhs)
 Returns the two-times-two determinant result for the two vectors lhs and rhs. More...
 
template<typename T>
Vector<T, 3> mi::math::cross (const Vector_struct<T, 3> &lhs, const Vector_struct<T, 3> &rhs)
 Returns the three-dimensional cross product result for the two vectors lhs and rhs. More...
 
template<typename T>
void mi::math::make_basis (const Vector<T, 3> &n, Vector<T, 3> *u, Vector<T, 3> *v)
 Computes a basis of 3D space with one given vector. More...
 
template<typename T>
void mi::math::make_basis (const Vector<T, 3> &n, const Vector<T, 3> &u, const Vector<T, 3> &v, Vector<T, 3> *t, Vector<T, 3> *b)
 Computes a basis of 3D space with one given vector, plane, and direction. More...
 
template<typename T2 , Size DIM2, typename T1 , Size DIM1>
Vector<T2, DIM2> mi::math::convert_vector (const Vector<T1, DIM1> &v, const T2 &fill=T2(0))
 Converts the vector v of type Vector<T1, DIM1> to a vector of type Vector<T2, DIM2>. More...
 

Detailed Description

Math vector class template of fixed dimension with arithmetic operators and generic functions.

See Math Vector Class.