MorphoGraphX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Friends | Related Functions | List of all members
mgx::util::Vector< dim, T > Class Template Reference

Namespace containing all the utility classes. More...

#include <vector.h>

Public Types

typedef T value_type
 
typedef T & reference_type
 
typedef const T & const_reference_type
 
typedef T * pointer_type
 
typedef const T * const_pointer_type
 
typedef T * iterator
 
typedef const T * const_iterator
 

Public Member Functions

CU_HOST_DEVICE Vector (const Vector &vec)
 Copy another vector.
 
template<class T1 >
CU_HOST_DEVICE Vector (const Vector< dim, T1 > &vec)
 Copy another vector with different number of elements.
 
template<size_t d1, class T1 >
CU_HOST_DEVICE Vector (const Vector< d1, T1 > &vec)
 Copy another vector with different number of elements.
 
template<class Vec >
CU_HOST_DEVICE Vector (const Vec &el)
 Initialize a vector from any object behaving like an array. More...
 
CU_HOST_DEVICE Vector (const T &x=T())
 Initialize a vector with all values to x.
 
CU_HOST_DEVICE Vector (const T &x, const T &y)
 Initialize a 2D vector.
 
CU_HOST_DEVICE Vector (const T &x, const T &y, const T &z)
 Initialize a 3D vector.
 
CU_HOST_DEVICE Vector (const T &x, const T &y, const T &z, const T &t)
 Initialize a 4D vector.
 
CU_HOST_DEVICE Vector (const T &x, const T &y, const T &z, const T &a, const T &b)
 Initialize a 5D vector.
 
CU_HOST_DEVICE Vector (const T &x, const T &y, const T &z, const T &a, const T &b, const T &c)
 Initialize a 6D vector.
 
CU_HOST_DEVICE Vector (const T &x, const T &y, const T &z, const T &a, const T &b, const T &c, const T &d)
 Initialize a 7D vector.
 
CU_HOST_DEVICE Vector (const T &a, const T &b, const T &c, const T &d, const T &e, const T &f, const T &g, const T &h, const T &i, const T &j, const T &k, const T &l)
 Initialize a 12D vector.
 
CU_HOST_DEVICE T * data ()
 Returns a raw pointer on the data.
 
CU_HOST_DEVICE iterator begin ()
 STL-iteration begin.
 
CU_HOST_DEVICE const_iterator begin () const
 Stl-iteration constant begin.
 
CU_HOST_DEVICE iterator end ()
 STL-iteration end.
 
CU_HOST_DEVICE const_iterator end () const
 Stl-iteration constant end.
 
CU_HOST_DEVICE const T * c_data () const
 Returns a constant raw pointer on the data.
 
CU_HOST_DEVICE Vector operator- (void) const
 Vector negation.
 
CU_HOST_DEVICE Vector operator+ (const Vector &vec) const
 Vector addition.
 
CU_HOST_DEVICE Vector operator- (const Vector &vec) const
 Vector subtraction.
 
CU_HOST_DEVICE Vector mult (const Vector &vec) const
 Element-wise multiplcation.
 
CU_HOST_DEVICE Vector operator* (const T &scalar) const
 Multiplication by a scalar.
 
CU_HOST_DEVICE Vector operator/ (const T &scalar) const
 Division by a scalar.
 
CU_HOST_DEVICE Vector operator/ (const Vector &vec) const
 Element-wise division.
 
CU_HOST_DEVICE Vectoroperator/= (const Vector &vec)
 In-place element-wise division by a scalar.
 
CU_HOST_DEVICE T operator* (const Vector &vec) const
 Dot product.
 
CU_HOST_DEVICE Vectoroperator= (const Vector &vec)
 Vector copy.
 
CU_HOST_DEVICE Vectoroperator+= (const Vector &vec)
 In-place vector addition.
 
CU_HOST_DEVICE Vectoroperator+= (const T &val)
 In-place constant addition.
 
CU_HOST_DEVICE Vectoroperator-= (const Vector &vec)
 In-place vector subtraction.
 
CU_HOST_DEVICE Vectoroperator-= (const T &val)
 In-place value subtraction.
 
CU_HOST_DEVICE Vectoroperator*= (const T &scalar)
 In-place multiplication by a scalar.
 
template<typename T1 >
CU_HOST_DEVICE Vectoroperator*= (const T1 &scalar)
 In-place multiplication by a scalar.
 
CU_HOST_DEVICE Vectoroperator/= (const T &scalar)
 In-place division by a scalar.
 
template<typename T1 >
CU_HOST_DEVICE Vectoroperator/= (const T1 &scalar)
 In-place division by a scalar.
 
CU_HOST_DEVICE bool operator== (const Vector &vec) const
 Element-wise equality.
 
CU_HOST_DEVICE bool operator!= (const Vector &vec) const
 Element-wise inequality.
 
CU_HOST_DEVICE T & operator[] (size_t idx)
 Access to the element idx.
 
CU_HOST_DEVICE const T & operator[] (size_t idx) const
 Access to the element idx.
 
CU_HOST_DEVICE T norm () const
 Euclidean norm of the vector.
 
CU_HOST_DEVICE T normsq () const
 Square of the Euclidean norm of the vector.
 
CU_HOST_DEVICE Vectornormalize (void)
 Normalize the vector.
 
CU_HOST_DEVICE Vector normalized (void) const
 Returns a normalized version of the vector.
 
bool iszero (void)
 
Vectorzero (void)
 
CU_HOST_DEVICE void set (const T &x)
 Set the values of a 1-D vector.
 
CU_HOST_DEVICE void set (const T &x, const T &y)
 Set the values of a 2-D vector.
 
CU_HOST_DEVICE void set (const T &x, const T &y, const T &z)
 Set the values of a 3-D vector.
 
CU_HOST_DEVICE void set (const T &x, const T &y, const T &z, const T &t)
 Set the values of a 4-D vector.
 
CU_HOST_DEVICE Vectoroperator= (const T &value)
 Set all the elements to value.
 
CU_HOST_DEVICE Vector cross (const Vector &other) const
 Compute the cross product as this x other.
 
CU_HOST_DEVICE void x (const T &v)
 Short access to the first element.
 
CU_HOST_DEVICE void y (const T &v)
 Short access to the second element.
 
CU_HOST_DEVICE void z (const T &v)
 Short access to the third element.
 
CU_HOST_DEVICE void t (const T &v)
 Short access to the fourth element.
 
CU_HOST_DEVICE T & x ()
 Short access to the first element.
 
CU_HOST_DEVICE T & y ()
 Short access to the second element.
 
CU_HOST_DEVICE T & z ()
 Short access to the third element.
 
CU_HOST_DEVICE T & t ()
 Short access to the fourth element.
 
CU_HOST_DEVICE const T & x () const
 Short access to the first element.
 
CU_HOST_DEVICE const T & y () const
 Short access to the second element.
 
CU_HOST_DEVICE const T & z () const
 Short access to the third element.
 
CU_HOST_DEVICE const T & t () const
 Short access to the fourth element.
 
CU_HOST_DEVICE void i (const T &v)
 Short access to the first element.
 
CU_HOST_DEVICE void j (const T &v)
 Short access to the second element.
 
CU_HOST_DEVICE void k (const T &v)
 Short access to the third element.
 
CU_HOST_DEVICE void l (const T &v)
 Short access to the fourth element.
 
CU_HOST_DEVICE T & i ()
 Short access to the first element.
 
CU_HOST_DEVICE T & j ()
 Short access to the second element.
 
CU_HOST_DEVICE T & k ()
 Short access to the third element.
 
CU_HOST_DEVICE T & l ()
 Short access to the fourth element.
 
CU_HOST_DEVICE const T & i () const
 Short access to the first element.
 
CU_HOST_DEVICE const T & j () const
 Short access to the second element.
 
CU_HOST_DEVICE const T & k () const
 Short access to the third element.
 
CU_HOST_DEVICE const T & l () const
 Short access to the fourth element.
 
CU_HOST_DEVICE Vector< 2, T > projectXY (void)
 Extract the two first elements of the vector.
 
CU_HOST_DEVICE bool operator< (const Vector &other) const
 Comparison operator. More...
 
CU_HOST_DEVICE bool operator<= (const Vector &other) const
 Comparison operator. More...
 
CU_HOST_DEVICE bool operator> (const Vector &other) const
 Comparison operator. More...
 
CU_HOST_DEVICE bool operator>= (const Vector &other) const
 Comparison operator. More...
 

Static Public Member Functions

static CU_HOST_DEVICE size_t size ()
 Returns the size of the vector (i.e. More...
 

Protected Attributes

elems [dim]
 

Friends

CU_HOST_DEVICE friend Vector operator* (const T &scalar, const Vector &vec)
 Multiplication by a scalar.
 
std::ostream & operator<< (std::ostream &out, const Vector &vec)
 
std::istream & operator>> (std::istream &in, Vector &vec)
 
QTextStreamoperator<< (QTextStream &out, const Vector &vec)
 
QTextStreamoperator>> (QTextStream &in, Vector &vec)
 

Related Functions

(Note that these are not member functions.)

template<class T >
CU_HOST_DEVICE T operator% (const Vector< 2, T > &v1, const Vector< 2, T > &v2)
 Cross product v1 x v2.
 
template<class T >
CU_HOST_DEVICE T operator^ (const Vector< 2, T > &v1, const Vector< 2, T > &v2)
 Cross product v1 x v2 (French notation)
 
template<class T >
CU_HOST_DEVICE T operator^ (const Vector< 1, T > &, const Vector< 1, T > &)
 Cross product v1 x v2 (French notation)
 
template<class T >
CU_HOST_DEVICE Vector< 3, T > operator% (const Vector< 3, T > &v1, const Vector< 3, T > &v2)
 Cross product v1 x v2.
 
template<class T >
CU_HOST_DEVICE Vector< 3, T > operator^ (const Vector< 3, T > &v1, const Vector< 3, T > &v2)
 Cross product v1 x v2 (French notation)
 
template<class T >
CU_HOST_DEVICE float angle (const Vector< 2, T > &v)
 Angle of the vector with (0,1)
 
template<class T >
CU_HOST_DEVICE float angle (const Vector< 3, T > &v1, const Vector< 3, T > &v2)
 Non-oriented angle between v1 and v2.
 
template<class T >
CU_HOST_DEVICE float angle (const Vector< 2, T > &v1, const Vector< 2, T > &v2)
 Oriented angle between v1 and v2.
 
template<class T >
CU_HOST_DEVICE float angle (const Vector< 1, T > &v1, const Vector< 1, T > &v2)
 Oriented angle between v1 and v2.
 
template<class T >
CU_HOST_DEVICE float angle (const Vector< 3, T > &v1, const Vector< 3, T > &v2, const Vector< 3, T > &ref)
 Oriented angle between v1 and v2 with ref to orient the space.
 
CU_HOST_DEVICE float normalized (float)
 Euclidean square norm of a real. More...
 
CU_HOST_DEVICE float normsq (float s)
 Euclidean square norm of a real. More...
 
CU_HOST_DEVICE float norm (float s)
 Euclidean norm of a real. More...
 
template<size_t dim, typename T >
CU_HOST_DEVICE T norm (const Vector< dim, T > &v)
 Function-version of the norm. More...
 
template<size_t dim, typename T >
CU_HOST_DEVICE T normsq (const Vector< dim, T > &v)
 Function-version of the square norm. More...
 
template<size_t dim, typename T >
CU_HOST_DEVICE Vector< dim, T > normalized (const Vector< dim, T > &v)
 Function-version of the square norm. More...
 
template<size_t dim, typename T >
CU_HOST_DEVICE Vector< dim, T > fabs (const Vector< dim, T > &v)
 Return the vector whose component is the absolute value of the input vector.
 
template<size_t dim, typename T >
CU_HOST_DEVICE Vector< dim, T > max (const Vector< dim, T > &v1, const Vector< dim, T > &v2)
 Return the vector whose component is the max of the two input vectors components.
 
template<size_t dim, typename T >
CU_HOST_DEVICE Vector< dim, T > min (const Vector< dim, T > &v1, const Vector< dim, T > &v2)
 Return the vector whose component is the min of the two input vectors components.
 
template<size_t dim, typename T >
CU_HOST_DEVICE Vector< dim, T > trim (const Vector< dim, T > &v, const Vector< dim, T > &minv, const Vector< dim, T > &maxv)
 Return the vector with components clipped to min and max vectors.
 
template<size_t dim, typename T >
CU_HOST_DEVICE Vector< dim, T > multiply (const Vector< dim, T > &v1, const Vector< dim, T > &v2)
 Return the vector whose component is the product of the two input vectors components.
 
template<size_t dim, typename T >
CU_HOST_DEVICE Vector< dim, T > divide (const Vector< dim, T > &v1, const Vector< dim, T > &v2)
 Return the vector whose components are clipped to min/max components. More...
 
template<typename T >
CU_HOST_DEVICE Vector< 3, T > orthogonal (const Vector< 3, T > &v)
 Find a vector orthogonal to v.
 
template<size_t dim, typename T , typename T1 >
CU_HOST_DEVICE Vector< dim, T > map (T(*fct)(T1), const Vector< dim, T1 > &v)
 Map a function to all elements of a vector.
 
template<size_t dim, typename T >
CU_HOST_DEVICE Vector< dim, T > map (const T &(*fct)(const T &, const T &), const Vector< dim, T > &v1, const Vector< dim, T > &v2)
 Map a function to all elements of a vector.
 
template<size_t dim, typename T >
CU_HOST_DEVICE Vector< dim, T > map (T(*fct)(const T &, const T &), const Vector< dim, T > &v1, const Vector< dim, T > &v2)
 Map a function to all elements of a vector.
 
template<size_t dim, typename T >
CU_HOST_DEVICE Vector< dim, T > map (T(*fct)(T, T), const Vector< dim, T > &v1, const Vector< dim, T > &v2)
 Map a function to all elements of a vector.
 
template<size_t dim, typename T , typename T1 , typename T2 >
CU_HOST_DEVICE Vector< dim, T > map (const T &(*fct)(const T1 &, const T2 &), const Vector< dim, T1 > &v1, const Vector< dim, T2 > &v2)
 Map a function to all elements of a vector.
 
template<size_t dim, typename T , typename T1 , typename T2 >
CU_HOST_DEVICE Vector< dim, T > map (T(*fct)(const T1 &, const T2 &), const Vector< dim, T1 > &v1, const Vector< dim, T2 > &v2)
 Map a function to all elements of a vector.
 
template<size_t dim, typename T , typename T1 , typename T2 >
CU_HOST_DEVICE Vector< dim, T > map (T(*fct)(T1, T2), const Vector< dim, T1 > &v1, const Vector< dim, T2 > &v2)
 Map a function to all elements of a vector.
 
template<size_t dim, typename T >
CU_HOST_DEVICE Vector< dim, T > operator+ (const Vector< dim, T > &v, const T &value)
 Add a value to all elements of a vector.
 
template<size_t dim, typename T >
CU_HOST_DEVICE Vector< dim, T > operator+ (const T &value, const Vector< dim, T > &v)
 Add a value to all elements of a vector.
 
template<size_t dim, typename T >
CU_HOST_DEVICE Vector< dim, T > operator- (const Vector< dim, T > &v, const T &value)
 Substact a value to all elements of a vector.
 
template<size_t dim, typename T >
CU_HOST_DEVICE Vector< dim, T > operator- (const T &value, const Vector< dim, T > &v)
 Equivalent to substracting a vector with all component the same to another one.
 
template<size_t dim, typename T >
CU_HOST_DEVICE Vector< dim+1, T > homogeneous (const Vector< dim, T > &v)
 Create a homogeneous coordinate vector from a cartesian one. More...
 
template<size_t dim, typename T >
CU_HOST_DEVICE Vector< dim-1, T > cartesian (const Vector< dim, T > &v)
 Extract the cartesion coordinates from a homogeneous vector. More...
 

Detailed Description

template<size_t dim, class T = float>
class mgx::util::Vector< dim, T >

Namespace containing all the utility classes.

Vector class supporting all classic classic vector operations.

Note
The addition and subtraction with a scalar is possible and is equivalent to adding/subtracting a vector filled with the scalar.

Constructor & Destructor Documentation

template<size_t dim, class T = float>
template<class Vec >
CU_HOST_DEVICE mgx::util::Vector< dim, T >::Vector ( const Vec el)
inlineexplicit

Initialize a vector from any object behaving like an array.

The only constraints are:

  • the type has to be convertible to T
  • the vector needs a [] operator
  • the size of the vector has to be at least dim

Member Function Documentation

template<size_t dim, class T = float>
CU_HOST_DEVICE bool mgx::util::Vector< dim, T >::operator< ( const Vector< dim, T > &  other) const
inline

Comparison operator.

Compare the axis in order.

template<size_t dim, class T = float>
CU_HOST_DEVICE bool mgx::util::Vector< dim, T >::operator<= ( const Vector< dim, T > &  other) const
inline

Comparison operator.

Compare the axis in order.

template<size_t dim, class T = float>
CU_HOST_DEVICE bool mgx::util::Vector< dim, T >::operator> ( const Vector< dim, T > &  other) const
inline

Comparison operator.

Compare the axis in order.

RSS: This is dangerous if min() is defined differently than std::min

template<size_t dim, class T = float>
CU_HOST_DEVICE bool mgx::util::Vector< dim, T >::operator>= ( const Vector< dim, T > &  other) const
inline

Comparison operator.

Compare the axis in order. RSS: This is dangerous if min() is defined differently than std::min

template<size_t dim, class T = float>
static CU_HOST_DEVICE size_t mgx::util::Vector< dim, T >::size ( )
inlinestatic

Returns the size of the vector (i.e.

the number of elements)

Friends And Related Function Documentation

template<size_t dim, typename T >
CU_HOST_DEVICE Vector< dim-1, T > cartesian ( const Vector< dim, T > &  v)
related

Extract the cartesion coordinates from a homogeneous vector.

Warning
The homogenous coordinate shouldn't be zero or there will be a division by 0!
template<size_t dim, typename T >
CU_HOST_DEVICE Vector< dim, T > divide ( const Vector< dim, T > &  v1,
const Vector< dim, T > &  v2 
)
related

Return the vector whose components are clipped to min/max components.

Return the vector whose component is the ratio of the two input vectors components.

template<size_t dim, typename T >
CU_HOST_DEVICE Vector< dim+1, T > homogeneous ( const Vector< dim, T > &  v)
related

Create a homogeneous coordinate vector from a cartesian one.

This adds one dimension, and set it to 1.

template<size_t dim, class T = float>
CU_HOST_DEVICE float norm ( float  s)
related

Euclidean norm of a real.

Just the absolute value of that real

template<size_t dim, typename T >
CU_HOST_DEVICE T norm ( const Vector< dim, T > &  v)
related

Function-version of the norm.

See Also
Vector::norm()
template<size_t dim, class T = float>
CU_HOST_DEVICE float normalized ( float  )
related

Euclidean square norm of a real.

Just the square of the real

template<size_t dim, typename T >
CU_HOST_DEVICE Vector< dim, T > normalized ( const Vector< dim, T > &  v)
related

Function-version of the square norm.

See Also
Vector::normsq()
template<size_t dim, class T = float>
CU_HOST_DEVICE float normsq ( float  s)
related

Euclidean square norm of a real.

Just the square of the real

template<size_t dim, typename T >
CU_HOST_DEVICE T normsq ( const Vector< dim, T > &  v)
related

Function-version of the square norm.

See Also
Vector::normsq()

The documentation for this class was generated from the following file: