kn::Vector< T > Class Template Reference

Generic vector class (genereic for size and type). More...

#include <Vector.hpp>

Collaboration diagram for kn::Vector< T >:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 Vector ()
 default constructor
 Vector (const size_t &size)
 constructor with a specific size and template type
 Vector (const Vector< T > &v)
 Copy Constructor.
 Vector (Vector< T > *v)
 Copy Constructor.
 Vector (const size_t &dataSize, const T *a)
 Constructor from a data array.
 Vector (const size_t &dataSize, const T &d)
 Constructor from a constant : duplicate this constant on all the vector entries.
virtual ~Vector (void)
 Destructor.
T & at (const unsigned int &i)
 Access to an element of the Vector.
const T & at (const unsigned int &i) const
 Access to an element of the Vector.
void resize (const int &size)
 Resize and reset this vector.
void resizeAndCopy (const Vector< T > &v)
 Resize this vector and copy the v into it Copy v data int this vector.
bool operator== (const Vector< T > &v) const
 test if the vector is equal to another one
bool operator!= (const Vector< T > &v) const
 test if the vector differs from another one
Vector< T > & operator= (const Vector< T > &v)
 copy the value of the argument vector to this vector
Vector< T > & operator= (const T &value)
 Fill the vector with a value.
Vector< T > operator+ (const Vector< T > &v) const
 adds two vectors
Vector< T > operator- (const Vector< T > &v) const
 subtracts two vectors
Vector< T > operator/ (const T &d) const
 Divides the Vector by a value.
operator* (const Vector< T > &v) const
 dot product
dot (const Vector< T > &v) const
 dot product
Vector< T > operator* (const T &d) const
 Multiplies the Vector with a value.
Vector< T > operator- (void) const
 Compute opposite of the Vector.
Vector< T > & operator+= (const Vector< T > &v)
 Adds the Vector with a Vector.
Vector< T > & operator-= (const Vector< T > &v)
 Subtracts the Vector with a Vector.
Vector< T > & operator/= (const T &d)
 Divides the Vector with a value All values of the Vector are divided by d.
Vector< T > & operator*= (const T &d)
 Multiplies the Vector with a value.
T & operator[] (const unsigned int &i)
 Access to an element of the Vector.
const T & operator[] (const unsigned int &i) const
 Access to an element of the Vector.
T & operator() (const unsigned int &i)
 Access to an element of the Vector.
const T & operator() (const unsigned int &i) const
 Access to an element of the Vector.
Vector< T > operator^ (const Vector< T > &v) const
 cross product between 2 vectors of size 3
Vector< T > cross (const Vector< T > &v) const
 cross product between 2 vectors of size 3
size_t size (void) const
 Returns the size of the vector (number of elements).
void fill (const T &d)
 Sets the value d on every entry of the vector.
void setZero (void)
 Reset the vector entries to zero.
void roundZero (const double &d=1.0e-14)
 Sets the small values ( |x| < d) to 0.
void setSubVector (const unsigned int &index, const Vector< T > &v)
 Copies the content of a vector v inside this vector The data from the vector v is duplicated inside this vector from the position "index".
void setSubVector (const unsigned int &index1, const unsigned int &index2, const unsigned int &size, const Vector< T > &v)
 Copies the content of a vector v inside this vector The data from the vector v is duplicated inside this vector from the position "index".
Vector< T > getSubVector (const unsigned int &index, const int &size) const
 Returns a sub Vector of the vector.
virtual T * begin (void) const
 Returns the beginning of the vector data.
virtual T * end (void) const
 Returns the end of the vector data.
double getNorm (void) const
 Returns the norm of the vector.
Vector< T > & normalize (void)
 Normalize the vector Divide each elements of this vector its norm.
Vector< T > getNormalized (void) const
 Normalize a copy of the vector.
void swap (const unsigned int &index1, const unsigned int &index2)
 Swaps two elements of this vector.
Vector< T > getHomogeneous (const T &d=T(1.0)) const
 Returns the homogeneous form of the vector by adding a component.
Vector< T > getUnhomogeneous (const T &zeroValue=T(1.0e-13)) const
 Returns the unhomogeneous form of the vector by removing a component.
void setHomogeneousNormalForm (const T &zeroValue=T(1.0e-13)) const
 set the last vector component to 1 (if non-zero).

Protected Member Functions

void allocate (const size_t &d)
 Check and allocate the memory to build the vector of size d.
void desallocate (void)
 Check and allocate the memory to build the vector of size d.

Protected Attributes

size_t sizeVector
 Vector size.
T * begin_
 Pointer on the beginning of the data.
T * end_
 Pointer on the end of the data.
T * data
 Array containing the vector data.


Detailed Description

template<class T>
class kn::Vector< T >

Generic vector class (genereic for size and type).

Definition at line 62 of file Vector.hpp.


Constructor & Destructor Documentation

template<class T >
kn::Vector< T >::Vector (  )  [inline]

default constructor

Definition at line 500 of file Vector.hpp.

template<class T >
kn::Vector< T >::Vector ( const size_t size  )  [inline, explicit]

constructor with a specific size and template type

Parameters:
size of the vector

Definition at line 505 of file Vector.hpp.

template<class T>
kn::Vector< T >::Vector ( const Vector< T > &  v  )  [inline]

Copy Constructor.

Parameters:
v Source vector

Definition at line 511 of file Vector.hpp.

template<class T>
kn::Vector< T >::Vector ( Vector< T > *  v  )  [inline]

Copy Constructor.

Parameters:
v Source vector

Definition at line 519 of file Vector.hpp.

template<class T>
kn::Vector< T >::Vector ( const size_t dataSize,
const T *  a 
) [inline]

Constructor from a data array.

Parameters:
dataSize of the vector
a Source data array
Exceptions:
MathException dataArray is null

Definition at line 528 of file Vector.hpp.

template<class T>
kn::Vector< T >::Vector ( const size_t dataSize,
const T &  d 
) [inline]

Constructor from a constant : duplicate this constant on all the vector entries.

Parameters:
dataSize of the vector
d Element to duplicate

Definition at line 539 of file Vector.hpp.

template<class T>
virtual kn::Vector< T >::~Vector ( void   )  [inline, virtual]

Destructor.

Definition at line 159 of file Vector.hpp.


Member Function Documentation

template<class T >
void kn::Vector< T >::allocate ( const size_t d  )  [inline, protected]

Check and allocate the memory to build the vector of size d.

Definition at line 561 of file Vector.hpp.

template<class T >
const T & kn::Vector< T >::at ( const unsigned int &  i  )  const [inline]

Access to an element of the Vector.

Parameters:
i the number of the element
Returns:
a reference on the queried variable
Exceptions:
MathException i is out of bounds

Definition at line 577 of file Vector.hpp.

template<class T >
T & kn::Vector< T >::at ( const unsigned int &  i  )  [inline]

Access to an element of the Vector.

Parameters:
i the number of the element
Returns:
a reference on the queried variable
Exceptions:
MathException i is out of bounds

Definition at line 571 of file Vector.hpp.

template<class T>
virtual T* kn::Vector< T >::begin ( void   )  const [inline, virtual]

Returns the beginning of the vector data.

Returns:
a pointer on the vector data array

Definition at line 435 of file Vector.hpp.

template<class T>
Vector<T> kn::Vector< T >::cross ( const Vector< T > &  v  )  const [inline]

cross product between 2 vectors of size 3

Parameters:
v vector of size 3
Returns:
the Vector computed for the cross product ot this and v
Exceptions:
MathException cross product only with vectors of size 3

Definition at line 361 of file Vector.hpp.

template<class T>
void kn::Vector< T >::desallocate ( void   )  [inline, protected]

Check and allocate the memory to build the vector of size d.

Definition at line 146 of file Vector.hpp.

template<class T>
T kn::Vector< T >::dot ( const Vector< T > &  v  )  const [inline]

dot product

Parameters:
v the Vector used for the dot product
Returns:
a copy of the Vector
Exceptions:
MathException incompatible vector size

Definition at line 266 of file Vector.hpp.

template<class T>
virtual T* kn::Vector< T >::end ( void   )  const [inline, virtual]

Returns the end of the vector data.

Returns:
a pointer on the end of the vector data array

Definition at line 444 of file Vector.hpp.

template<class T>
void kn::Vector< T >::fill ( const T &  d  )  [inline]

Sets the value d on every entry of the vector.

Reimplemented in kn::Vector2< T >, kn::Vector3< T >, and kn::Vector4< T >.

Definition at line 382 of file Vector.hpp.

template<class T>
Vector< T > kn::Vector< T >::getHomogeneous ( const T &  d = T(1.0)  )  const [inline]

Returns the homogeneous form of the vector by adding a component.

The default value is 1.0 (a finite vector) but could be set as '0' (ideal point) or something else.

Parameters:
d : value to set on the additional component

Definition at line 771 of file Vector.hpp.

template<class T >
double kn::Vector< T >::getNorm ( void   )  const [inline]

Returns the norm of the vector.

Returns:
vector norm

Definition at line 745 of file Vector.hpp.

template<class T >
Vector< T > kn::Vector< T >::getNormalized ( void   )  const [inline]

Normalize a copy of the vector.

Reimplemented in kn::Vector2< T >, kn::Vector3< T >, and kn::Vector4< T >.

Definition at line 763 of file Vector.hpp.

template<class T >
Vector< T > kn::Vector< T >::getSubVector ( const unsigned int &  index,
const int &  size 
) const [inline]

Returns a sub Vector of the vector.

Parameters:
index : position where the sub Vector starts
size : size of the sub Vector
Exceptions:
MathException size too big
MathException index out of bounds

Definition at line 735 of file Vector.hpp.

template<class T>
Vector< T > kn::Vector< T >::getUnhomogeneous ( const T &  zeroValue = T(1.0e-13)  )  const [inline]

Returns the unhomogeneous form of the vector by removing a component.

All the component of the vector are devided by the last component, exept if this component is zero.

Parameters:
zeroValue : limit to consider a number equal to zero

Definition at line 782 of file Vector.hpp.

template<class T >
Vector< T > & kn::Vector< T >::normalize ( void   )  [inline]

Normalize the vector Divide each elements of this vector its norm.

Reimplemented in kn::Vector2< T >, kn::Vector3< T >, and kn::Vector4< T >.

Definition at line 754 of file Vector.hpp.

template<class T>
bool kn::Vector< T >::operator!= ( const Vector< T > &  v  )  const [inline]

test if the vector differs from another one

Parameters:
v the vector to test
Returns:
true if the vectors are different, false otherwise

Definition at line 207 of file Vector.hpp.

template<class T >
const T & kn::Vector< T >::operator() ( const unsigned int &  i  )  const [inline]

Access to an element of the Vector.

Parameters:
i the number of the element
Returns:
a reference on the queried variable

Definition at line 688 of file Vector.hpp.

template<class T >
T & kn::Vector< T >::operator() ( const unsigned int &  i  )  [inline]

Access to an element of the Vector.

Parameters:
i the number of the element
Returns:
a reference on the queried variable

Definition at line 683 of file Vector.hpp.

template<class T>
Vector<T> kn::Vector< T >::operator* ( const T &  d  )  const [inline]

Multiplies the Vector with a value.

Parameters:
d the value multiplied with this Vector
Returns:
a copy of the Vector

Reimplemented in kn::Vector2< T >, kn::Vector3< T >, and kn::Vector4< T >.

Definition at line 275 of file Vector.hpp.

template<class T>
T kn::Vector< T >::operator* ( const Vector< T > &  v  )  const [inline]

dot product

Parameters:
v the Vector used for the dot product
Returns:
a copy of the Vector
Exceptions:
MathException incompatible vector size

Definition at line 634 of file Vector.hpp.

template<class T>
Vector< T > & kn::Vector< T >::operator*= ( const T &  d  )  [inline]

Multiplies the Vector with a value.

Parameters:
d the value multiplied with this Vector
Returns:
the Vector

Reimplemented in kn::Vector2< T >, kn::Vector3< T >, and kn::Vector4< T >.

Definition at line 667 of file Vector.hpp.

template<class T>
Vector< T > kn::Vector< T >::operator+ ( const Vector< T > &  v  )  const [inline]

adds two vectors

Parameters:
v the vector to be added
Returns:
a copy of the vector
Exceptions:
MathException incompatible vector size

Definition at line 611 of file Vector.hpp.

template<class T>
Vector< T > & kn::Vector< T >::operator+= ( const Vector< T > &  v  )  [inline]

Adds the Vector with a Vector.

Parameters:
v the Vector to be added
Returns:
the Vector
Exceptions:
MathException incompatible vector size

Todo:
: à tester serieusement

Definition at line 641 of file Vector.hpp.

template<class T>
Vector<T> kn::Vector< T >::operator- ( void   )  const [inline]

Compute opposite of the Vector.

Returns:
a copy of the Vector

Reimplemented in kn::Vector2< T >, kn::Vector3< T >, and kn::Vector4< T >.

Definition at line 283 of file Vector.hpp.

template<class T>
Vector< T > kn::Vector< T >::operator- ( const Vector< T > &  v  )  const [inline]

subtracts two vectors

Parameters:
v the vector to be substracted
Returns:
a copy of the vector

Definition at line 623 of file Vector.hpp.

template<class T>
Vector< T > & kn::Vector< T >::operator-= ( const Vector< T > &  v  )  [inline]

Subtracts the Vector with a Vector.

Parameters:
v the Vector to be subtracted
Returns:
the Vector
Exceptions:
MathException incompatible vector size

Todo:
: à tester serieusement

Definition at line 651 of file Vector.hpp.

template<class T>
Vector<T> kn::Vector< T >::operator/ ( const T &  d  )  const [inline]

Divides the Vector by a value.

Parameters:
d the value dividing this Vector
Returns:
a copy of the Vector
Exceptions:
MathException d is null

Reimplemented in kn::Vector2< T >, kn::Vector3< T >, and kn::Vector4< T >.

Definition at line 248 of file Vector.hpp.

template<class T>
Vector< T > & kn::Vector< T >::operator/= ( const T &  d  )  [inline]

Divides the Vector with a value All values of the Vector are divided by d.

Parameters:
d the value divided with this Vector
Returns:
the Vector
Exceptions:
MathException d is null

Reimplemented in kn::Vector2< T >, kn::Vector3< T >, and kn::Vector4< T >.

Definition at line 660 of file Vector.hpp.

template<class T>
Vector< T > & kn::Vector< T >::operator= ( const T &  value  )  [inline]

Fill the vector with a value.

Parameters:
value Value to set the vector with
Returns:
the vector

Definition at line 604 of file Vector.hpp.

template<class T>
Vector< T > & kn::Vector< T >::operator= ( const Vector< T > &  v  )  [inline]

copy the value of the argument vector to this vector

Parameters:
v the source vector
Returns:
the vector reference
Exceptions:
MathException the incompatible vector size

Definition at line 591 of file Vector.hpp.

template<class T>
bool kn::Vector< T >::operator== ( const Vector< T > &  v  )  const [inline]

test if the vector is equal to another one

Parameters:
v the vector to test
Returns:
true if the vectors values are equal, false otherwise

Definition at line 583 of file Vector.hpp.

template<class T >
const T & kn::Vector< T >::operator[] ( const unsigned int &  i  )  const [inline]

Access to an element of the Vector.

Parameters:
i the number of the element
Returns:
a reference on the queried variable

Definition at line 678 of file Vector.hpp.

template<class T >
T & kn::Vector< T >::operator[] ( const unsigned int &  i  )  [inline]

Access to an element of the Vector.

Parameters:
i the number of the element
Returns:
a reference on the queried variable

Definition at line 673 of file Vector.hpp.

template<class T>
Vector< T > kn::Vector< T >::operator^ ( const Vector< T > &  v  )  const [inline]

cross product between 2 vectors of size 3

Parameters:
v vector of size 3
Returns:
the Vector computed for the cross product ot this and v
Exceptions:
MathException cross product only with vectors of size 3

Definition at line 693 of file Vector.hpp.

template<class T >
void kn::Vector< T >::resize ( const int &  size  )  [inline]

Resize and reset this vector.

Parameters:
size new size for the vector

Definition at line 546 of file Vector.hpp.

template<class T>
void kn::Vector< T >::resizeAndCopy ( const Vector< T > &  v  )  [inline]

Resize this vector and copy the v into it Copy v data int this vector.

Parameters:
v vector to be copied

Definition at line 553 of file Vector.hpp.

template<class T >
void kn::Vector< T >::roundZero ( const double &  d = 1.0e-14  )  [inline]

Sets the small values ( |x| < d) to 0.

Parameters:
d the limit around which values are set to 0

Definition at line 708 of file Vector.hpp.

template<class T>
void kn::Vector< T >::setHomogeneousNormalForm ( const T &  zeroValue = T(1.0e-13)  )  const [inline]

set the last vector component to 1 (if non-zero).

Divide all the components of the vector by the last component if non-zero.

Parameters:
zeroValue : limit to consider a number equal to zero

Definition at line 799 of file Vector.hpp.

template<class T>
void kn::Vector< T >::setSubVector ( const unsigned int &  index1,
const unsigned int &  index2,
const unsigned int &  size,
const Vector< T > &  v 
) [inline]

Copies the content of a vector v inside this vector The data from the vector v is duplicated inside this vector from the position "index".

Parameters:
index1 : position where the copy starts
index2 : position where we start to copy in v
size : number of element to copy
v : the vector to be (partially) duplicated
Exceptions:
MathException size too big
MathException index1 out of bounds
MathException index2 out of bounds

Definition at line 726 of file Vector.hpp.

template<class T>
void kn::Vector< T >::setSubVector ( const unsigned int &  index,
const Vector< T > &  v 
) [inline]

Copies the content of a vector v inside this vector The data from the vector v is duplicated inside this vector from the position "index".

Parameters:
index : position where the copy starts
v : the vector to be duplicated
Exceptions:
MathException v size too big
MathException index out of bounds

Definition at line 719 of file Vector.hpp.

template<class T>
void kn::Vector< T >::setZero ( void   )  [inline]

Reset the vector entries to zero.

Reimplemented in kn::Vector2< T >, kn::Vector3< T >, and kn::Vector4< T >.

Definition at line 389 of file Vector.hpp.

template<class T>
size_t kn::Vector< T >::size ( void   )  const [inline]

Returns the size of the vector (number of elements).

Returns:
vector size

Reimplemented in kn::Vector2< T >, kn::Vector3< T >, and kn::Vector4< T >.

Definition at line 375 of file Vector.hpp.

template<class T >
void kn::Vector< T >::swap ( const unsigned int &  index1,
const unsigned int &  index2 
) [inline]

Swaps two elements of this vector.

Parameters:
index1 1st element
index2 2nd element
Exceptions:
MathException index1 or index2 are out of bounds

Definition at line 809 of file Vector.hpp.


Member Data Documentation

template<class T>
T* kn::Vector< T >::begin_ [protected]

Pointer on the beginning of the data.

Definition at line 76 of file Vector.hpp.

template<class T>
T* kn::Vector< T >::data [protected]

Array containing the vector data.

Definition at line 86 of file Vector.hpp.

template<class T>
T* kn::Vector< T >::end_ [protected]

Pointer on the end of the data.

Definition at line 81 of file Vector.hpp.

template<class T>
size_t kn::Vector< T >::sizeVector [protected]

Vector size.

Definition at line 71 of file Vector.hpp.


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

Generated on Thu Nov 12 16:06:35 2009 for OpenKN-math by  doxygen 1.5.8