Iray SDK API nvidia_logo_transpbg.gif Up
mi::math::Vector<T, DIM> Class Template Reference

Fixed-size math vector class template with generic operations. More...

#include <vector.h>

Inheritance diagram for mi::math::Vector<T, DIM>:

Public Types

typedef Vector_struct<T, DIM> Pod_type
 POD class corresponding to this vector. More...
 
typedef Vector_struct<T, DIM> storage_type
 Storage class used by this vector. More...
 
typedef T value_type
 Element type. More...
 
typedef Size size_type
 Size type, unsigned. More...
 
typedef Difference difference_type
 Difference type, signed. More...
 
typedef T * pointer
 Mutable pointer to element. More...
 
typedef const T * const_pointer
 Const pointer to element. More...
 
typedef T & reference
 Mutable reference to element. More...
 
typedef const T & const_reference
 Const reference to element. More...
 

Public Member Functions

T * begin ()
 Returns the pointer to the first vector element. More...
 
const T * begin () const
 Returns the pointer to the first vector element. More...
 
T * end ()
 Returns the past-the-end pointer. More...
 
const T * end () const
 Returns the past-the-end pointer. More...
 
 Vector ()
 The default constructor leaves the vector elements uninitialized. More...
 
 Vector (const Vector<T, DIM> &vec)=default
 Default copy constructor. More...
 
 Vector (const Vector_struct<T, DIM> &vec)
 Constructor from underlying storage type. More...
 
 Vector (T v)
 Constructor initializes all vector elements to the value v. More...
 
template<typename Iterator>
 Vector (From_iterator_tag, Iterator p)
 Constructor requires the mi::math::FROM_ITERATOR tag as first argument and initializes the vector elements with the first DIM elements from the sequence starting at the iterator p. More...
 
template<typename T2>
 Vector (T2 const (&array)[DIM])
 Constructor initializes the vector elements from an array of dimension DIM. More...
 
template<typename T2>
 Vector (const Vector<T2, DIM> &other)
 Template constructor that allows explicit conversions from other vectors with assignment compatible element value type. More...
 
template<typename T2>
 Vector (const Vector_struct<T2, DIM> &other)
 Template constructor that allows explicit conversions from underlying storage type with assignment compatible element value type. More...
 
 Vector (T v1, T v2)
 Dedicated constructor, for dimension 2 only, that initializes the vector elements from the two elements (v1,v2). More...
 
 Vector (T v1, T v2, T v3)
 Dedicated constructor, for dimension 3 only, that initializes the vector elements from the three elements (v1,v2,v3). More...
 
 Vector (T v1, const Vector<T, 2> &v2)
 Dedicated constructor, for dimension 3 only, that initializes the vector elements from the three elements (v1,v2.x,v2.y). More...
 
 Vector (const Vector<T, 2> &v1, T v2)
 Dedicated constructor, for dimension 3 only, that initializes the vector elements from the three elements (v1.x,v1.y,v2). More...
 
 Vector (T v1, T v2, T v3, T v4)
 Dedicated constructor, for dimension 4 only, that initializes the vector elements from the four elements (v1,v2,v3,v4). More...
 
 Vector (T v1, T v2, const Vector<T, 2> &v3)
 Dedicated constructor, for dimension 4 only, that initializes the vector elements from the four elements (v1,v2,v3.x,v3.y). More...
 
 Vector (T v1, const Vector<T, 2> &v2, T v3)
 Dedicated constructor, for dimension 4 only, that initializes the vector elements from the four elements (v1,v2.x,v2.y,v3). More...
 
 Vector (const Vector<T, 2> &v1, T v2, T v3)
 Dedicated constructor, for dimension 4 only, that initializes the vector elements from the four elements (v1.x,v1.y,v2,v3). More...
 
 Vector (const Vector<T, 2> &v1, const Vector<T, 2> &v2)
 Dedicated constructor, for dimension 4 only, that initializes the vector elements from the four elements (v1.x,v1.y,v2.x,v2.y). More...
 
 Vector (T v1, const Vector<T, 3> &v2)
 Dedicated constructor, for dimension 4 only, that initializes the vector elements from the four elements (v1,v2.x,v2.y,v2.z). More...
 
 Vector (const Vector<T, 3> &v1, T v2)
 Dedicated constructor, for dimension 4 only, that initializes the vector elements from the four elements (v1.x,v1.y,v1.z,v2). More...
 
 Vector (const Color_struct &color)
 Dedicated constructor, for dimension 4 only, that initializes the vector elements from a color interpreted as a vector (r,g,b,a). More...
 
Vectoroperator= (const Vector &other)=default
 Assignment. More...
 
Vectoroperator= (T s)
 Assignment from a scalar, setting all elements to s. More...
 
Vectoroperator= (const Color_struct &color)
 Assignment, for dimension 4 only, that assigns color interpreted as a vector (r,g,b,a) to this vector. More...
 
T & operator[] (Size i)
 Accesses the i-th vector element. More...
 
const T & operator[] (Size i) const
 Accesses the i-th vector element. More...
 
const T & get (Size i) const
 Returns the i-th vector element. More...
 
void set (Size i, T value)
 Sets the i-th vector element to value. More...
 
bool normalize ()
 Normalizes this vector to unit length. More...
 
bool operator== (Vector<T, DIM> rhs) const
 Returns true if lhs is elementwise equal to rhs. More...
 
bool operator!= (Vector<T, DIM> rhs) const
 Returns true if lhs is elementwise not equal to rhs. More...
 
bool operator< (Vector<T, DIM> rhs) const
 Returns true if lhs is lexicographically less than rhs. More...
 
bool operator<= (Vector<T, DIM> rhs) const
 Returns true if lhs is lexicographically less than or equal to rhs. More...
 
bool operator> (Vector<T, DIM> rhs) const
 Returns true if lhs is lexicographically greater than rhs. More...
 
bool operator>= (Vector<T, DIM> rhs) const
 Returns true if lhs is lexicographically greater than or equal to rhs. More...
 

Static Public Member Functions

static Size size ()
 Constant size of the vector. More...
 
static Size max_size ()
 Constant maximum size of the vector. More...
 

Static Public Attributes

static const Size DIMENSION = DIM
 Constant dimension of the vector. More...
 
static const Size SIZE = DIM
 Constant size of the vector. More...
 

Additional Inherited Members

- Public Attributes inherited from mi::math::Vector_struct<T, DIM>
elements [DIM]
 coordinates. More...
 

Detailed Description

template<class T, Size DIM>
class mi::math::Vector<T, DIM>

Fixed-size math vector class template with generic operations.

This class template provides array-like storage for DIM many values of an arithmetic type T. Several functions and arithmetic operators support the work with vectors.

An instantiation of the vector class template is a model of the STL container concept. It provides random access to its elements and corresponding random access iterators.

The template parameters have the following requirements:

  • T: an arithmetic type supporting + - * / == != < > <= >= sqrt() .
  • DIM: a value > 0 of type mi::Size that defines the fixed dimension of the vector.

Depending on the dimension DIM, the mi::math::Vector class template offers element access through the conventional data members named x, y, z, and w. Assuming a vector vec of suitable dimension, the following expressions are valid

  • vec.x; equivalent to vec[0] and available if 1 <= DIM <= 4.
  • vec.y; equivalent to vec[1] and available if 2 <= DIM <= 4.
  • vec.z; equivalent to vec[2] and available if 3 <= DIM <= 4.
  • vec.w; equivalent to vec[3] and available if 4 <= DIM <= 4.

These data members allow users to access elements, as illustrated in the following example:

vec.x = 4.0;
Fixed-size math vector class template with generic operations.
Definition: vector.h:286
See also
For the free functions and operators available for vectors and vector-like classes see Math Vector Class.
The underlying POD type mi::math::Vector_struct.
Include File:
#include <mi/math/vector.h>