util::Vector< dim, T > Class Template Reference

Vector class supporting all classic classic vector operations. More...

#include <util/vector.h>

Inheritance diagram for util::Vector< dim, T >:
Inheritance graph
[legend]

List of all members.

Public Types

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

Public Member Functions

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

Static Public Member Functions

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

Protected Attributes

elems [dim]

Friends

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

Related Functions

(Note that these are not member functions.)



template<class T >
double 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.
template<class T >
double angle (const Vector< 1, T > &v1, const Vector< 1, T > &v2)
 Oriented angle between v1 and v2.
template<class T >
double angle (const Vector< 2, T > &v1, const Vector< 2, T > &v2)
 Oriented angle between v1 and v2.
template<class T >
double angle (const Vector< 3, T > &v1, const Vector< 3, T > &v2)
 Non-oriented angle between v1 and v2.
template<class T >
double angle (const Vector< 2, T > &v)
 Angle of the vector with (0,1).
template<size_t dim, typename T >
Vector< dim, T > divide (const Vector< dim, T > &v1, const Vector< dim, T > &v2)
 Return the vector whose component is the ratio of the two input vectors components.
template<size_t dim, typename T , typename T1 , typename T2 >
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 , typename T1 , typename T2 >
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 >
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 >
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 >
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 >
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 , typename T1 >
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 >
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 >
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 >
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 >
norm (const Vector< dim, T > &v)
 Function-version of the norm.
double norm (double s)
 Euclidian norm of a real.
template<size_t dim, typename T >
Vector< dim, T > normalized (const Vector< dim, T > &v)
 Function-version of the square norm.
double normalized (double)
 Euclidian square norm of a real.
template<size_t dim, typename T >
normsq (const Vector< dim, T > &v)
 Function-version of the square norm.
double normsq (double s)
 Euclidian square norm of a real.
template<class T >
Vector< 3, T > operator% (const Vector< 3, T > &v1, const Vector< 3, T > &v2)
 Cross product v1 x v2.
template<class T >
operator% (const Vector< 2, T > &v1, const Vector< 2, T > &v2)
 Cross product v1 x v2.
template<size_t dim, typename T >
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 >
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 >
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 >
Vector< dim, T > operator- (const Vector< dim, T > &v, const T &value)
 Substact a value to all elements of a vector.
template<class T >
Vector< 3, T > operator^ (const Vector< 3, T > &v1, const Vector< 3, T > &v2)
 Cross product v1 x v2 (French notation).
template<class T >
operator^ (const Vector< 1, T > &v1, const Vector< 1, T > &v2)
 Cross product v1 x v2 (French notation).
template<class T >
operator^ (const Vector< 2, T > &v1, const Vector< 2, T > &v2)
 Cross product v1 x v2 (French notation).
template<typename T >
util::Vector< 3, T > orthogonal (const util::Vector< 3, T > &v)
 Find a vector orthogonal to v.

Detailed Description

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

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.

Definition at line 32 of file vector.h.


Constructor & Destructor Documentation

template<size_t dim, class T = double>
util::Vector< dim, T >::Vector ( const Vector< dim, T > &  vec  )  [inline]

Copy another vector.

Definition at line 49 of file vector.h.

00050     {
00051       for(size_t i = 0 ; i < dim ; i++)
00052         elems[i] = vec[i];
00053     }

template<size_t dim, class T = double>
template<size_t d1, class T1 >
util::Vector< dim, T >::Vector ( const Vector< d1, T1 > &  vec  )  [inline, explicit]

Copy another vector with different number of elements.

Definition at line 64 of file vector.h.

00065     {
00066       if(d1 < dim)
00067       {
00068         for(size_t i = 0 ; i < d1 ; ++i)
00069           elems[i] = vec[i];
00070         for(size_t i = d1 ; i < dim ; ++i)
00071           elems[i] = 0;
00072       }
00073       else
00074       {
00075         for(size_t i = 0 ; i < dim ; ++i)
00076           elems[i] = vec[i];
00077       }
00078     }

template<size_t dim, class T = double>
template<class Vec >
util::Vector< dim, T >::Vector ( const Vec el  )  [inline, explicit]

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

Definition at line 89 of file vector.h.

00090     {
00091       for(size_t i = 0 ; i < dim ; i++)
00092         elems[i] = el[i];
00093     }

template<size_t dim, class T = double>
util::Vector< dim, T >::Vector ( const T &  x = T()  )  [inline]

Initialize a vector with all values to x.

x default to a default-constructed object.

Definition at line 100 of file vector.h.

00101     {
00102       for( size_t i = 0 ; i < dim ; ++i )
00103         elems[ i ] = x;
00104     }

template<size_t dim, class T = double>
util::Vector< dim, T >::Vector ( const T &  x,
const T &  y 
) [inline, explicit]

Initialize a 2D vector.

Definition at line 109 of file vector.h.

00110     {
00111       STATIC_ASSERT( dim == 2, "Constructor with 2 arguments can be used only for 2D vectors" );
00112       elems[ 0 ] = x;
00113       elems[ 1 ] = y;
00114     }

template<size_t dim, class T = double>
util::Vector< dim, T >::Vector ( const T &  x,
const T &  y,
const T &  z 
) [inline, explicit]

Initialize a 3D vector.

Definition at line 119 of file vector.h.

00120     {
00121       STATIC_ASSERT( dim == 3, "Constructor with 3 arguments can be used only for 3D vectors" );
00122       elems[ 0 ] = x;
00123       elems[ 1 ] = y;
00124       elems[ 2 ] = z;
00125     }

template<size_t dim, class T = double>
util::Vector< dim, T >::Vector ( const T &  x,
const T &  y,
const T &  z,
const T &  t 
) [inline, explicit]

Initialize a 4D vector.

Definition at line 130 of file vector.h.

00131     {
00132       STATIC_ASSERT( dim == 4, "Constructor with 3 arguments can be used only for 3D vectors" );
00133       elems[ 0 ] = x;
00134       elems[ 1 ] = y;
00135       elems[ 2 ] = z;
00136       elems[ 3 ] = t;
00137     }


Member Function Documentation

template<size_t dim, class T = double>
const_iterator util::Vector< dim, T >::begin (  )  const [inline]

Stl-iteration constant begin.

Definition at line 156 of file vector.h.

00156 { return elems; }

template<size_t dim, class T = double>
iterator util::Vector< dim, T >::begin (  )  [inline]

STL-iteration begin.

Definition at line 152 of file vector.h.

00152 { return elems; }

template<size_t dim, class T = double>
const T* util::Vector< dim, T >::c_data (  )  const [inline]
template<size_t dim, class T = double>
Vector util::Vector< dim, T >::cross ( const Vector< dim, T > &  other  )  const [inline]

Compute the cross product as this x other.

Definition at line 498 of file vector.h.

00499     {
00500       STATIC_ASSERT( dim == 3, "Cross product is only defined for 3D vectors." );
00501       return ( *this ) ^ other;
00502     }

template<size_t dim, class T = double>
T* util::Vector< dim, T >::data (  )  [inline]

Returns a raw pointer on the data.

Definition at line 147 of file vector.h.

Referenced by util::Matrix< nb_vars, nb_vars, double >::data().

00147 { return elems; }

template<size_t dim, class T = double>
const_iterator util::Vector< dim, T >::end (  )  const [inline]

Stl-iteration constant end.

Definition at line 165 of file vector.h.

00165 { return elems+dim; }

template<size_t dim, class T = double>
iterator util::Vector< dim, T >::end (  )  [inline]

STL-iteration end.

Definition at line 161 of file vector.h.

00161 { return elems+dim; }

template<size_t dim, class T = double>
const T& util::Vector< dim, T >::i (  )  const [inline]

Short access to the first element.

Definition at line 588 of file vector.h.

00588 { STATIC_ASSERT( dim > 0, "Accessing i requires at least a 1D vector." ); return elems[0]; }

template<size_t dim, class T = double>
T& util::Vector< dim, T >::i (  )  [inline]
template<size_t dim, class T = double>
void util::Vector< dim, T >::i ( const T &  v  )  [inline]

Short access to the first element.

Definition at line 556 of file vector.h.

00556 { STATIC_ASSERT( dim > 0, "Accessing i requires at least a 1D vector." ); elems[0] = v; }

template<size_t dim, class T = double>
const T& util::Vector< dim, T >::j (  )  const [inline]

Short access to the second element.

Definition at line 592 of file vector.h.

00592 { STATIC_ASSERT( dim > 1, "Accessing j requires at least a 2D vector." ); return elems[1]; }

template<size_t dim, class T = double>
T& util::Vector< dim, T >::j (  )  [inline]

Short access to the second element.

Definition at line 576 of file vector.h.

00576 { STATIC_ASSERT( dim > 1, "Accessing j requires at least a 2D vector." ); return elems[1]; }

template<size_t dim, class T = double>
void util::Vector< dim, T >::j ( const T &  v  )  [inline]

Short access to the second element.

Definition at line 560 of file vector.h.

00560 { STATIC_ASSERT( dim > 1, "Accessing j requires at least a 2D vector." ); elems[1] = v; }

template<size_t dim, class T = double>
const T& util::Vector< dim, T >::k (  )  const [inline]

Short access to the third element.

Definition at line 596 of file vector.h.

00596 { STATIC_ASSERT( dim > 2, "Accessing k requires at least a 3D vector." ); return elems[2]; }

template<size_t dim, class T = double>
T& util::Vector< dim, T >::k (  )  [inline]

Short access to the third element.

Definition at line 580 of file vector.h.

00580 { STATIC_ASSERT( dim > 2, "Accessing k requires at least a 3D vector." ); return elems[2]; }

template<size_t dim, class T = double>
void util::Vector< dim, T >::k ( const T &  v  )  [inline]

Short access to the third element.

Definition at line 564 of file vector.h.

00564 { STATIC_ASSERT( dim > 2, "Accessing k requires at least a 3D vector." ); elems[2] = v; }

template<size_t dim, class T = double>
const T& util::Vector< dim, T >::l (  )  const [inline]

Short access to the fourth element.

Definition at line 600 of file vector.h.

00600 { STATIC_ASSERT( dim > 3, "Accessing l requires at least a 4D vector." ); return elems[3]; }

template<size_t dim, class T = double>
T& util::Vector< dim, T >::l (  )  [inline]

Short access to the fourth element.

Definition at line 584 of file vector.h.

00584 { STATIC_ASSERT( dim > 3, "Accessing l requires at least a 4D vector." ); return elems[3]; }

template<size_t dim, class T = double>
void util::Vector< dim, T >::l ( const T &  v  )  [inline]

Short access to the fourth element.

Definition at line 568 of file vector.h.

00568 { STATIC_ASSERT( dim > 3, "Accessing l requires at least a 4D vector." ); elems[3] = v; }

template<size_t dim, class T = double>
Vector util::Vector< dim, T >::mult ( const Vector< dim, T > &  vec  )  const [inline]

Element-wise multiplcation.

Definition at line 207 of file vector.h.

00208     {
00209       Vector ans;
00210       for(size_t i = 0 ; i < dim ; i++)
00211         ans[i] = elems[i] * vec.elems[i];
00212       return ans;
00213     }

template<size_t dim, class T = double>
T util::Vector< dim, T >::norm (  )  const [inline]

Euclidean norm of the vector.

Definition at line 391 of file vector.h.

Referenced by util::Vector< dim, T >::norm(), and util::Vector< nCols, double >::normalize().

00392     {
00393       return std::sqrt(normsq());
00394     }

template<size_t dim, class T = double>
Vector& util::Vector< dim, T >::normalize ( void   )  [inline]

Normalize the vector.

Definition at line 411 of file vector.h.

Referenced by util::Vector< nCols, double >::normalized(), complex_factory::objreader(), cell_system::CellSystem< TissueClass, RealModel >::step_cellsystem_division(), and util::Contour::tangent().

00412     {
00413       T sz = norm();
00414       return ((*this) /= sz);
00415     }

template<size_t dim, class T = double>
Vector util::Vector< dim, T >::normalized ( void   )  const [inline]

Returns a normalized version of the vector.

Definition at line 420 of file vector.h.

Referenced by util::Vector< dim, T >::normalized().

00421     {
00422       Vector ans(*this);
00423       return ans.normalize();
00424     }

template<size_t dim, class T = double>
T util::Vector< dim, T >::normsq (  )  const [inline]

Square of the Euclidean norm of the vector.

Definition at line 399 of file vector.h.

Referenced by geometry::Quaternion::inverse(), util::Vector< nCols, double >::norm(), and util::Vector< dim, T >::normsq().

00400     {
00401       T ans = 0;
00402       for(size_t i = 0 ; i < dim ; i++)
00403         ans += elems[i] * elems[i];
00404 
00405       return ans;
00406     }

template<size_t dim, class T = double>
bool util::Vector< dim, T >::operator!= ( const Vector< dim, T > &  vec  )  const [inline]

Element-wise inequality.

Definition at line 367 of file vector.h.

00368     {
00369       return (!((*this) == vec));
00370     }

template<size_t dim, class T = double>
T util::Vector< dim, T >::operator* ( const Vector< dim, T > &  vec  )  const [inline]

Dot product.

Definition at line 270 of file vector.h.

00271     {
00272       T ans = 0;
00273       for(size_t i = 0 ; i < dim ; i++)
00274         ans += elems[i] * vec.elems[i];
00275 
00276       return ans;
00277     }

template<size_t dim, class T = double>
Vector util::Vector< dim, T >::operator* ( const T &  scalar  )  const [inline]

Multiplication by a scalar.

Definition at line 218 of file vector.h.

00219     {
00220       Vector ans(*this);
00221       ans *= scalar;
00222       return ans;
00223     }

template<size_t dim, class T = double>
template<typename T1 >
Vector& util::Vector< dim, T >::operator*= ( const T1 &  scalar  )  [inline]

In-place multiplication by a scalar.

Definition at line 324 of file vector.h.

00325     {
00326       for(size_t i = 0 ; i < dim ; i++)
00327         elems[i] = (T)(elems[i]*scalar);
00328       return *this;
00329     }

template<size_t dim, class T = double>
Vector& util::Vector< dim, T >::operator*= ( const T &  scalar  )  [inline]

In-place multiplication by a scalar.

Reimplemented in util::Point< T >.

Definition at line 313 of file vector.h.

00314     {
00315       for(size_t i = 0 ; i < dim ; i++)
00316         elems[i] *= scalar;
00317       return *this;
00318     }

template<size_t dim, class T = double>
Vector util::Vector< dim, T >::operator+ ( const Vector< dim, T > &  vec  )  const [inline]

Vector addition.

Definition at line 187 of file vector.h.

00188     {
00189       Vector ans(*this);
00190       ans += vec;
00191       return ans;
00192     }

template<size_t dim, class T = double>
Vector& util::Vector< dim, T >::operator+= ( const Vector< dim, T > &  vec  )  [inline]

In-place vector addition.

Definition at line 293 of file vector.h.

00294     {
00295       for(size_t i = 0 ; i < dim ; i++)
00296         elems[i] += vec.elems[i];
00297       return *this;
00298     }

template<size_t dim, class T = double>
Vector util::Vector< dim, T >::operator- ( const Vector< dim, T > &  vec  )  const [inline]

Vector subtraction.

Definition at line 197 of file vector.h.

00198     {
00199       Vector ans(*this);
00200       ans -= vec;
00201       return ans;
00202     }

template<size_t dim, class T = double>
Vector util::Vector< dim, T >::operator- ( void   )  const [inline]

Vector negation.

Reimplemented in util::Point< T >.

Definition at line 175 of file vector.h.

00176     {
00177       Vector ans;
00178       for(size_t i = 0 ; i < dim ; i++)
00179         ans[i] = -elems[i];
00180 
00181       return ans;
00182     }

template<size_t dim, class T = double>
Vector& util::Vector< dim, T >::operator-= ( const Vector< dim, T > &  vec  )  [inline]

In-place vector subtraction.

Definition at line 303 of file vector.h.

00304     {
00305       for(size_t i = 0 ; i < dim ; i++)
00306         elems[i] -= vec.elems[i];
00307       return *this;
00308     }

template<size_t dim, class T = double>
Vector util::Vector< dim, T >::operator/ ( const Vector< dim, T > &  vec  )  const [inline]

Element-wise division.

Definition at line 238 of file vector.h.

00239     {
00240       Vector ans = *this;
00241       ans /= vec;
00242       return ans;
00243     }

template<size_t dim, class T = double>
Vector util::Vector< dim, T >::operator/ ( const T &  scalar  )  const [inline]

Division by a scalar.

Reimplemented in util::Point< T >.

Definition at line 228 of file vector.h.

00229     {
00230       Vector ans(*this);
00231       ans /= scalar;
00232       return ans;
00233     }

template<size_t dim, class T = double>
template<typename T1 >
Vector& util::Vector< dim, T >::operator/= ( const T1 &  scalar  )  [inline]

In-place division by a scalar.

Definition at line 345 of file vector.h.

00346     {
00347       for(size_t i = 0 ; i < dim ; ++i)
00348         elems[i] = (T)(elems[i] / scalar);
00349       return *this;
00350     }

template<size_t dim, class T = double>
Vector& util::Vector< dim, T >::operator/= ( const T &  scalar  )  [inline]

In-place division by a scalar.

Reimplemented in util::Point< T >.

Definition at line 334 of file vector.h.

00335     {
00336       for(size_t i = 0 ; i < dim ; ++i)
00337         elems[i] /= scalar;
00338       return *this;
00339     }

template<size_t dim, class T = double>
Vector& util::Vector< dim, T >::operator/= ( const Vector< dim, T > &  vec  )  [inline]

In-place element-wise division by a scalar.

Definition at line 248 of file vector.h.

00249     {
00250       for(size_t i = 0 ; i < dim ; ++i)
00251         elems[i] /= vec.elems[i];
00252       return *this;
00253     }

template<size_t dim, class T = double>
bool util::Vector< dim, T >::operator< ( const Vector< dim, T > &  other  )  const [inline]

Comparison operator.

Compare the axis in order.

Definition at line 616 of file vector.h.

00617     {
00618       for(size_t i = 0 ; i < dim ; ++i)
00619       {
00620         if(elems[i] < other.elems[i]) return true;
00621         if(elems[i] > other.elems[i]) return false;
00622       }
00623       return false;
00624     }

template<size_t dim, class T = double>
bool util::Vector< dim, T >::operator<= ( const Vector< dim, T > &  other  )  const [inline]

Comparison operator.

Compare the axis in order.

Definition at line 631 of file vector.h.

00632     {
00633       for(size_t i = 0 ; i < dim ; ++i)
00634       {
00635         if(elems[i] < other.elems[i]) return true;
00636         if(elems[i] > other.elems[i]) return false;
00637       }
00638       return true;
00639     }

template<size_t dim, class T = double>
Vector& util::Vector< dim, T >::operator= ( const T &  value  )  [inline]

Set all the elements to value.

Reimplemented in util::Color< T >, and util::Color< GLfloat >.

Definition at line 486 of file vector.h.

00487     {
00488       for( size_t i = 0 ; i < dim ; ++i )
00489       {
00490         elems[ i ] = value;
00491       }
00492       return *this;
00493     }

template<size_t dim, class T = double>
Vector& util::Vector< dim, T >::operator= ( const Vector< dim, T > &  vec  )  [inline]

Vector copy.

Definition at line 282 of file vector.h.

00283     {
00284       for(size_t i = 0 ; i < dim ; i++)
00285         elems[i] = vec.elems[i];
00286 
00287       return (*this);
00288     }

template<size_t dim, class T = double>
bool util::Vector< dim, T >::operator== ( const Vector< dim, T > &  vec  )  const [inline]

Element-wise equality.

Definition at line 355 of file vector.h.

00356     {
00357       for(size_t i = 0 ; i < dim ; i++)
00358         if(elems[i] != vec.elems[i])
00359           return false;
00360 
00361       return true;
00362     }

template<size_t dim, class T = double>
bool util::Vector< dim, T >::operator> ( const Vector< dim, T > &  other  )  const [inline]

Comparison operator.

Compare the axis in order.

Definition at line 646 of file vector.h.

00647     {
00648       for(size_t i = 0 ; i < dim ; ++i)
00649       {
00650         if(elems[i] > other.elems[i]) return true;
00651         if(elems[i] < other.elems[i]) return false;
00652       }
00653       return false;
00654     }

template<size_t dim, class T = double>
bool util::Vector< dim, T >::operator>= ( const Vector< dim, T > &  other  )  const [inline]

Comparison operator.

Compare the axis in order.

Definition at line 661 of file vector.h.

00662     {
00663       for(size_t i = 0 ; i < dim ; ++i)
00664       {
00665         if(elems[i] > other.elems[i]) return true;
00666         if(elems[i] < other.elems[i]) return false;
00667       }
00668       return true;
00669     }

template<size_t dim, class T = double>
T util::Vector< dim, T >::operator[] ( size_t  idx  )  const [inline]

Access to the element idx.

Definition at line 383 of file vector.h.

00384     {
00385       return elems[idx];
00386     }

template<size_t dim, class T = double>
T& util::Vector< dim, T >::operator[] ( size_t  idx  )  [inline]

Access to the element idx.

Definition at line 375 of file vector.h.

00376     {
00377       return elems[idx];
00378     }

template<size_t dim, class T = double>
Vector<2,T> util::Vector< dim, T >::projectXY ( void   )  [inline]

Extract the two first elements of the vector.

Definition at line 605 of file vector.h.

00606     {
00607       STATIC_ASSERT( dim>1, "2D projection requires at least a 2D vector." );
00608       return Vector<2,T>(elems[0],elems[1]);
00609     }

template<size_t dim, class T = double>
void util::Vector< dim, T >::set ( const T &  x,
const T &  y,
const T &  z,
const T &  t 
) [inline]

Set the values of a 4-D vector.

Definition at line 474 of file vector.h.

00475     {
00476       STATIC_ASSERT( dim == 4, "Set method with 4 arguments can be used only for 4D vectors." );
00477       elems[ 0 ] = x;
00478       elems[ 1 ] = y;
00479       elems[ 2 ] = z;
00480       elems[ 3 ] = t;
00481     }

template<size_t dim, class T = double>
void util::Vector< dim, T >::set ( const T &  x,
const T &  y,
const T &  z 
) [inline]

Set the values of a 3-D vector.

Definition at line 463 of file vector.h.

00464     {
00465       STATIC_ASSERT( dim == 3, "Set method with 3 arguments can be used only for 3D vectors." );
00466       elems[ 0 ] = x;
00467       elems[ 1 ] = y;
00468       elems[ 2 ] = z;
00469     }

template<size_t dim, class T = double>
void util::Vector< dim, T >::set ( const T &  x,
const T &  y 
) [inline]

Set the values of a 2-D vector.

Definition at line 453 of file vector.h.

00454     {
00455       STATIC_ASSERT( dim == 2, "Set method with 2 arguments can be used only for 2D vectors." );
00456       elems[ 0 ] = x;
00457       elems[ 1 ] = y;
00458     }

template<size_t dim, class T = double>
void util::Vector< dim, T >::set ( const T &  x  )  [inline]

Set the values of a 1-D vector.

Definition at line 444 of file vector.h.

00445     {
00446       STATIC_ASSERT( dim == 1, "Set method with 1 argument can be used only for 1D vectors." );
00447       elems[ 0 ] = x;
00448     }

template<size_t dim, class T = double>
static size_t util::Vector< dim, T >::size (  )  [inline, static]

Returns the size of the vector (i.e.

the number of elements)

Definition at line 142 of file vector.h.

Referenced by complex_factory::objreader().

00142 { return dim; }

template<size_t dim, class T = double>
const T& util::Vector< dim, T >::t (  )  const [inline]

Short access to the fourth element.

Definition at line 551 of file vector.h.

00551 { STATIC_ASSERT( dim > 3, "Accessing t requires at least a 4D vector." ); return elems[3]; }

template<size_t dim, class T = double>
T& util::Vector< dim, T >::t (  )  [inline]

Short access to the fourth element.

Definition at line 535 of file vector.h.

Referenced by util::Vector< nCols, double >::set().

00535 { STATIC_ASSERT( dim > 3, "Accessing t requires at least a 4D vector." ); return elems[3]; }

template<size_t dim, class T = double>
void util::Vector< dim, T >::t ( const T &  v  )  [inline]

Short access to the fourth element.

Definition at line 519 of file vector.h.

Referenced by util::Matrix< nb_vars, nb_vars, double >::rotation().

00519 { STATIC_ASSERT( dim > 3, "Accessing t requires at least a 4D vector." ); elems[3] = v; }

template<size_t dim, class T = double>
const T& util::Vector< dim, T >::x (  )  const [inline]

Short access to the first element.

Definition at line 539 of file vector.h.

00539 { STATIC_ASSERT( dim > 0, "Accessing x requires at least a 1D vector." ); return elems[0]; }

template<size_t dim, class T = double>
T& util::Vector< dim, T >::x (  )  [inline]

Short access to the first element.

Definition at line 523 of file vector.h.

Referenced by geometry::Quaternion::conjugate(), geometry::Quaternion::inverse(), util::Vector< nCols, double >::set(), and util::Vector< nCols, double >::Vector().

00523 { STATIC_ASSERT( dim > 0, "Accessing x requires at least a 1D vector." ); return elems[0]; }

template<size_t dim, class T = double>
void util::Vector< dim, T >::x ( const T &  v  )  [inline]
template<size_t dim, class T = double>
const T& util::Vector< dim, T >::y (  )  const [inline]

Short access to the second element.

Definition at line 543 of file vector.h.

00543 { STATIC_ASSERT( dim > 1, "Accessing y requires at least a 2D vector." ); return elems[1]; }

template<size_t dim, class T = double>
T& util::Vector< dim, T >::y (  )  [inline]

Short access to the second element.

Definition at line 527 of file vector.h.

Referenced by geometry::Quaternion::conjugate(), geometry::Quaternion::inverse(), and util::Vector< nCols, double >::set().

00527 { STATIC_ASSERT( dim > 1, "Accessing y requires at least a 2D vector." ); return elems[1]; }

template<size_t dim, class T = double>
void util::Vector< dim, T >::y ( const T &  v  )  [inline]
template<size_t dim, class T = double>
const T& util::Vector< dim, T >::z (  )  const [inline]

Short access to the third element.

Definition at line 547 of file vector.h.

00547 { STATIC_ASSERT( dim > 2, "Accessing z requires at least a 3D vector." ); return elems[2]; }

template<size_t dim, class T = double>
T& util::Vector< dim, T >::z (  )  [inline]

Short access to the third element.

Definition at line 531 of file vector.h.

Referenced by geometry::Quaternion::conjugate(), geometry::Quaternion::inverse(), and util::Vector< nCols, double >::set().

00531 { STATIC_ASSERT( dim > 2, "Accessing z requires at least a 3D vector." ); return elems[2]; }

template<size_t dim, class T = double>
void util::Vector< dim, T >::z ( const T &  v  )  [inline]

Short access to the third element.

Definition at line 515 of file vector.h.

Referenced by tissue_model::TissueModel< RealModel, TissueClass >::draw(), complex_factory::objreader(), util::Vector< dim, T >::orthogonal(), and util::Matrix< nb_vars, nb_vars, double >::rotation().

00515 { STATIC_ASSERT( dim > 2, "Accessing z requires at least a 3D vector." ); elems[2] = v; }


Friends And Related Function Documentation

template<class T >
double angle ( const Vector< 3, T > &  v1,
const Vector< 3, T > &  v2,
const Vector< 3, T > &  ref 
) [related]

Oriented angle between v1 and v2 with ref to orient the space.

Definition at line 825 of file vector.h.

00826   {
00827     double x = v1*v2;
00828     Vector<3,T> n = v1^v2;
00829     double y = norm( n );
00830     if( n*ref < 0 )
00831       return atan2( -y, x );
00832     else
00833       return atan2( y, x );
00834   }

template<class T >
double angle ( const Vector< 1, T > &  v1,
const Vector< 1, T > &  v2 
) [related]

Oriented angle between v1 and v2.

Definition at line 814 of file vector.h.

00815   {
00816     return ( v1*v2 < 0 )? -1 : 1;
00817   }

template<class T >
double angle ( const Vector< 2, T > &  v1,
const Vector< 2, T > &  v2 
) [related]

Oriented angle between v1 and v2.

Definition at line 801 of file vector.h.

00802   {
00803     double x = v1*v2;
00804     double y = v1^v2;
00805     return atan2( y, x );
00806   }

template<class T >
double angle ( const Vector< 3, T > &  v1,
const Vector< 3, T > &  v2 
) [related]

Non-oriented angle between v1 and v2.

Definition at line 788 of file vector.h.

00789   {
00790     double x = v1*v2;
00791     double y = norm( v1^v2 );
00792     return atan2( y, x );
00793   }

template<class T >
double angle ( const Vector< 2, T > &  v  )  [related]

Angle of the vector with (0,1).

Definition at line 777 of file vector.h.

References util::Vector< dim, T >::x(), and util::Vector< dim, T >::y().

00778   {
00779     return atan2( v.y(), v.x() );
00780   }

template<size_t dim, typename T >
Vector< dim, T > divide ( const Vector< dim, T > &  v1,
const Vector< dim, T > &  v2 
) [related]

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

Definition at line 966 of file vector.h.

00967   {
00968     Vector<dim,T> result;
00969     for(size_t i = 0 ; i < dim ; ++i)
00970     {
00971       result[i] = v1[i] / v2[i];
00972     }
00973     return result;
00974   }

template<size_t dim, typename T , typename T1 , typename T2 >
Vector< dim, T > map ( T(*)(T1, T2)  fct,
const Vector< dim, T1 > &  v1,
const Vector< dim, T2 > &  v2 
) [related]

Map a function to all elements of a vector.

Definition at line 1176 of file vector.h.

01177   {
01178     Vector<dim,T> result;
01179     for(size_t i = 0 ; i < dim ; ++i)
01180     {
01181       result[i] = (*fct)(v1[i], v2[i]);
01182     }
01183     return result;
01184   }

template<size_t dim, typename T , typename T1 , typename T2 >
Vector< dim, T > map ( T(*)(const T1 &, const T2 &)  fct,
const Vector< dim, T1 > &  v1,
const Vector< dim, T2 > &  v2 
) [related]

Map a function to all elements of a vector.

Definition at line 1160 of file vector.h.

01161   {
01162     Vector<dim,T> result;
01163     for(size_t i = 0 ; i < dim ; ++i)
01164     {
01165       result[i] = (*fct)(v1[i], v2[i]);
01166     }
01167     return result;
01168   }

template<size_t dim, typename T , typename T1 , typename T2 >
Vector< dim, T > map ( const T &(*)(const T1 &, const T2 &)  fct,
const Vector< dim, T1 > &  v1,
const Vector< dim, T2 > &  v2 
) [related]

Map a function to all elements of a vector.

Definition at line 1144 of file vector.h.

01145   {
01146     Vector<dim,T> result;
01147     for(size_t i = 0 ; i < dim ; ++i)
01148     {
01149       result[i] = (*fct)(v1[i], v2[i]);
01150     }
01151     return result;
01152   }

template<size_t dim, typename T >
Vector< dim, T > map ( T(*)(T, T)  fct,
const Vector< dim, T > &  v1,
const Vector< dim, T > &  v2 
) [related]

Map a function to all elements of a vector.

Definition at line 1128 of file vector.h.

01129   {
01130     Vector<dim,T> result;
01131     for(size_t i = 0 ; i < dim ; ++i)
01132     {
01133       result[i] = (*fct)(v1[i], v2[i]);
01134     }
01135     return result;
01136   }

template<size_t dim, typename T >
Vector< dim, T > map ( T(*)(const T &, const T &)  fct,
const Vector< dim, T > &  v1,
const Vector< dim, T > &  v2 
) [related]

Map a function to all elements of a vector.

Definition at line 1112 of file vector.h.

01113   {
01114     Vector<dim,T> result;
01115     for(size_t i = 0 ; i < dim ; ++i)
01116     {
01117       result[i] = (*fct)(v1[i], v2[i]);
01118     }
01119     return result;
01120   }

template<size_t dim, typename T >
Vector< dim, T > map ( const T &(*)(const T &, const T &)  fct,
const Vector< dim, T > &  v1,
const Vector< dim, T > &  v2 
) [related]

Map a function to all elements of a vector.

Definition at line 1096 of file vector.h.

01097   {
01098     Vector<dim,T> result;
01099     for(size_t i = 0 ; i < dim ; ++i)
01100     {
01101       result[i] = (*fct)(v1[i], v2[i]);
01102     }
01103     return result;
01104   }

template<size_t dim, typename T , typename T1 >
Vector< dim, T > map ( T(*)(T1)  fct,
const Vector< dim, T1 > &  v 
) [related]

Map a function to all elements of a vector.

Definition at line 1080 of file vector.h.

01081   {
01082     Vector<dim,T> result;
01083     for(size_t i = 0 ; i < dim ; ++i)
01084     {
01085       result[i] = (*fct)(v[i]);
01086     }
01087     return result;
01088   }

template<size_t dim, typename T >
Vector< dim, T > max ( const Vector< dim, T > &  v1,
const Vector< dim, T > &  v2 
) [related]

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

Definition at line 915 of file vector.h.

00916   {
00917     Vector<dim,T> result;
00918     for(size_t i = 0 ; i < dim ; ++i)
00919     {
00920       result[i] = std::max(v1[i], v2[i]);
00921     }
00922     return result;
00923   }

template<size_t dim, typename T >
Vector< dim, T > min ( const Vector< dim, T > &  v1,
const Vector< dim, T > &  v2 
) [related]

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

Definition at line 932 of file vector.h.

00933   {
00934     Vector<dim,T> result;
00935     for(size_t i = 0 ; i < dim ; ++i)
00936     {
00937       result[i] = std::min(v1[i], v2[i]);
00938     }
00939     return result;
00940   }

template<size_t dim, typename T >
Vector< dim, T > multiply ( const Vector< dim, T > &  v1,
const Vector< dim, T > &  v2 
) [related]

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

Definition at line 949 of file vector.h.

00950   {
00951     Vector<dim,T> result;
00952     for(size_t i = 0 ; i < dim ; ++i)
00953     {
00954       result[i] = v1[i] * v2[i];
00955     }
00956     return result;
00957   }

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

Function-version of the norm.

See also:
Vector::norm()

Definition at line 879 of file vector.h.

References util::Vector< dim, T >::norm().

00880   {
00881     return v.norm();
00882   }

template<size_t dim, class T = double>
double norm ( double  s  )  [related]

Euclidian norm of a real.

Just the absolute value of that real

Definition at line 867 of file vector.h.

00868   {
00869     return (s<0)?-s:s;
00870   }

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

Function-version of the square norm.

See also:
Vector::normsq()

Definition at line 903 of file vector.h.

References util::Vector< dim, T >::normalized().

00904   {
00905     return v.normalized();
00906   }

template<size_t dim, class T = double>
double normalized ( double   )  [related]

Euclidian square norm of a real.

Just the square of the real

Definition at line 843 of file vector.h.

00844   {
00845     return 1;
00846   }

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

Function-version of the square norm.

See also:
Vector::normsq()

Definition at line 891 of file vector.h.

References util::Vector< dim, T >::normsq().

00892   {
00893     return v.normsq();
00894   }

template<size_t dim, class T = double>
double normsq ( double  s  )  [related]

Euclidian square norm of a real.

Just the square of the real

Definition at line 855 of file vector.h.

00856   {
00857     return s*s;
00858   }

template<class T >
Vector< 3, T > operator% ( const Vector< 3, T > &  v1,
const Vector< 3, T > &  v2 
) [related]

Cross product v1 x v2.

Definition at line 751 of file vector.h.

00752   {
00753     return v1^v2;
00754   }

template<class T >
T operator% ( const Vector< 2, T > &  v1,
const Vector< 2, T > &  v2 
) [related]

Cross product v1 x v2.

Definition at line 717 of file vector.h.

00718   {
00719     return v1^v2;
00720   }

template<size_t dim, class T = double>
Vector operator* ( const T &  scalar,
const Vector< dim, T > &  vec 
) [friend]

Multiplication by a scalar.

Definition at line 258 of file vector.h.

00259     {
00260       Vector ans;
00261       for(size_t i = 0 ; i < dim ; i++)
00262         ans[i] = scalar * vec.elems[i];
00263 
00264       return ans;
00265     }

template<size_t dim, typename T >
Vector< dim, T > operator+ ( const T &  value,
const Vector< dim, T > &  v 
) [related]

Add a value to all elements of a vector.

Definition at line 1206 of file vector.h.

01207   {
01208     Vector<dim,T> res;
01209     for(size_t i = 0 ; i < dim ; ++i)
01210       res[i] = v[i] + value;
01211     return res;
01212   }

template<size_t dim, typename T >
Vector< dim, T > operator+ ( const Vector< dim, T > &  v,
const T &  value 
) [related]

Add a value to all elements of a vector.

Definition at line 1192 of file vector.h.

01193   {
01194     Vector<dim,T> res;
01195     for(size_t i = 0 ; i < dim ; ++i)
01196       res[i] = v[i] + value;
01197     return res;
01198   }

template<size_t dim, typename T >
Vector< dim, T > operator- ( const T &  value,
const Vector< dim, T > &  v 
) [related]

Equivalent to substracting a vector with all component the same to another one.

Definition at line 1235 of file vector.h.

01236   {
01237     Vector<dim,T> res;
01238     for(size_t i = 0 ; i < dim ; ++i)
01239       res[i] = value - v[i];
01240     return res;
01241   }

template<size_t dim, typename T >
Vector< dim, T > operator- ( const Vector< dim, T > &  v,
const T &  value 
) [related]

Substact a value to all elements of a vector.

Definition at line 1220 of file vector.h.

01221   {
01222     Vector<dim,T> res;
01223     for(size_t i = 0 ; i < dim ; ++i)
01224       res[i] = v[i] - value;
01225     return res;
01226   }

template<class T >
Vector< 3, T > operator^ ( const Vector< 3, T > &  v1,
const Vector< 3, T > &  v2 
) [related]

Cross product v1 x v2 (French notation).

Definition at line 762 of file vector.h.

00763   {
00764     Vector<3,T> ans;
00765     ans[0] = v1[1]*v2[2] - v1[2]*v2[1];
00766     ans[1] = v1[2]*v2[0] - v1[0]*v2[2];
00767     ans[2] = v1[0]*v2[1] - v1[1]*v2[0];
00768     return ans;
00769   }

template<class T >
T operator^ ( const Vector< 1, T > &  v1,
const Vector< 1, T > &  v2 
) [related]

Cross product v1 x v2 (French notation).

Definition at line 740 of file vector.h.

00741   {
00742     return 0;
00743   }

template<class T >
T operator^ ( const Vector< 2, T > &  v1,
const Vector< 2, T > &  v2 
) [related]

Cross product v1 x v2 (French notation).

Definition at line 728 of file vector.h.

00729   {
00730     return ((v1[0] * v2[1]) -
00731             (v1[1] * v2[0]));
00732   }

template<typename T >
util::Vector< 3, T > orthogonal ( const util::Vector< 3, T > &  v  )  [related]

Find a vector orthogonal to v.

Definition at line 982 of file vector.h.

References util::Vector< dim, T >::x(), util::Vector< dim, T >::y(), and util::Vector< dim, T >::z().

00983   {
00984     const double ratio = 1-1e-8;
00985     if ((std::abs(v.y()) >= ratio*std::abs(v.x())) && (std::abs(v.z()) >= ratio*std::abs(v.x())))
00986       return util::Vector<3,T>(0, -v.z(), v.y());
00987     else
00988       if ((std::abs(v.x()) >= ratio*std::abs(v.y())) && (std::abs(v.z()) >= ratio*std::abs(v.y())))
00989         return util::Vector<3,T>(-v.z(), 0, v.x());
00990       else
00991         return util::Vector<3,T>(-v.y(), v.x(), 0);
00992   }


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Fri May 31 15:38:37 2013 for VVE by  doxygen 1.6.3