gtm::TVector< T > Class Template Reference

#include <vector.h>

List of all members.

Public Member Functions

 ~TVector ()
 Destructor.
void SetN (uint N)
 Size change.
T & operator() (uint i)
 Reference operator.
T * GetAnsiRef ()
 ANSI (C/C++ array) reference.
uint GetN ()
 Vector's cardinality.
int GetType ()
 Vector's type (ROW_VECTOR/COL_VECTOR).
GetNorm ()
 Mathematical norm (L2).
void Normalize ()
 Normalizes the vector.
Dot (const TVector< T > &r)
 Dot product.



T * _vector
 Vector's internal state.
uint _N
 Cardinality.
int _type
 Type (ROW_VECTOR/COL_VECTOR).
bool _myMemory
 Have I created _vector?
 TVector (uint N=3, T data=(T) 0, int type=0x02)
 Default constructor.
 TVector (const TVector< T > &r)
 Copy constructor.
 TVector (T *block, uint N, bool copy=true, int type=0x02)
 Use this to treat an ANSI array as a TVector.
TVector< T > & operator= (const TVector< T > &r)
 Vector assignation.
TVector< T > & operator= (TMatrix< T > &r)
 Matrix assignation (defined in class TMatrix).
TVector< T > & operator= (T *r)
 ANSI assignation (r size must be, at least, N).
TVector< T > & operator= (T r)
 Scalar assignation.
bool operator== (const TVector< T > &r)
 Equality.
bool operator!= (const TVector< T > &r)
 Inequality.
TVector< T > operator+ (const TVector< T > &r)
 Addition.
TVector< T > operator- (const TVector< T > &r)
 Substraction.
TVector< T > operator* (const TVector< T > &r)
 Cross product.
TMatrix< T > operator* (TMatrix< T > &r)
 Matrix product (defined in class TMatrix).
TVector< T > operator* (T r)
 Scalar product.
TVector< T > & operator+= (const TVector< T > &r)
 Addition.
TVector< T > & operator-= (const TVector< T > &r)
 Substraction.
TVector< T > & operator*= (const TVector< T > &r)
 Cross product.
TVector< T > & operator*= (T r)
 Scalar product.
TVector< T > operator- ()
 Unary operators.
TVector< T > operator! ()
 Normalized vector.
TVector< T > operator~ ()
 Transposed vector.

Detailed Description

template<class T>
class gtm::TVector< T >

TVector class.

This class defines a C++ template to use mathematical vectors in a N space.

See also:
TMatrix

Definition at line 48 of file vector.h.


Constructor & Destructor Documentation

template<class T >
gtm::TVector< T >::TVector ( uint  N = 3,
data = ( T )0,
int  type = 0x02 
) [inline]

Default constructor.

Contructors.

Parameters:
N Cardinality.
data Initial data.
type Vector type (ROW_VECTOR/COL_VECTOR).
r Right object (vector or matrix).
block ANSI array.
copy Make a copy of given array?

Definition at line 211 of file vector.h.

References gtm::TVector< T >::_myMemory, gtm::TVector< T >::_N, gtm::TVector< T >::_type, and gtm::TVector< T >::_vector.

00212     {
00213         _N        = N;
00214         _type     = type;
00215         _vector   = VectorAllocateMemory< T >( _N );
00216         _myMemory = true;
00217         VectorAssignScalar< T >( _vector, data, _N );
00218 
00219     }

template<class T >
gtm::TVector< T >::TVector ( const TVector< T > &  r  )  [inline]

Copy constructor.

Definition at line 223 of file vector.h.

References gtm::TVector< T >::_myMemory, gtm::TVector< T >::_N, gtm::TVector< T >::_type, and gtm::TVector< T >::_vector.

00224     {
00225         _N        = r._N;
00226         _type     = r._type;
00227         _myMemory = true;
00228         _vector   = VectorCopyMemory< T >( r._vector, _N );
00229 
00230     }

template<class T >
gtm::TVector< T >::TVector ( T *  block,
uint  N,
bool  copy = true,
int  type = 0x02 
) [inline]

Use this to treat an ANSI array as a TVector.

Definition at line 234 of file vector.h.

References gtm::TVector< T >::_myMemory, gtm::TVector< T >::_N, gtm::TVector< T >::_type, and gtm::TVector< T >::_vector.

00235     {
00236         _N        = N;
00237         _type     = type;
00238         _myMemory = copy;
00239         _vector   = ( copy )? VectorCopyMemory< T >( block, _N ): block;
00240 
00241     }

template<class T>
gtm::TVector< T >::~TVector (  )  [inline]

Destructor.

Definition at line 71 of file vector.h.

References gtm::TVector< T >::_myMemory, and gtm::TVector< T >::_vector.

00071                     {
00072             if( _myMemory ) VectorFreeMemory< T >( _vector );
00073         };


Member Function Documentation

template<class T>
T gtm::TVector< T >::Dot ( const TVector< T > &  r  )  [inline]

Dot product.

Definition at line 135 of file vector.h.

References gtm::TVector< T >::_N, gtm::TVector< T >::_vector, and GTM_MIN.

00135                                        {
00136             return( VectorDotProduct< T >( _vector, r._vector, GTM_MIN( _N, r._N ) ) );
00137         };

template<class T>
T* gtm::TVector< T >::GetAnsiRef (  )  [inline]
template<class T>
uint gtm::TVector< T >::GetN (  )  [inline]

Vector's cardinality.

Definition at line 119 of file vector.h.

References gtm::TVector< T >::_N.

Referenced by gtm::TMatrix< T >::operator=().

00119                      {
00120             return( _N );
00121         };

Here is the caller graph for this function:

template<class T>
T gtm::TVector< T >::GetNorm (  )  [inline]

Mathematical norm (L2).

Definition at line 127 of file vector.h.

References gtm::TVector< T >::_N, and gtm::TVector< T >::_vector.

00127                      {
00128             return( VectorNorm< T >( _vector, _N ) );
00129         };

template<class T>
int gtm::TVector< T >::GetType (  )  [inline]

Vector's type (ROW_VECTOR/COL_VECTOR).

Definition at line 123 of file vector.h.

References gtm::TVector< T >::_type.

Referenced by gtm::TMatrix< T >::operator=().

00123                        {
00124             return( _type );
00125         };

Here is the caller graph for this function:

template<class T>
void gtm::TVector< T >::Normalize (  )  [inline]

Normalizes the vector.

Definition at line 131 of file vector.h.

References gtm::TVector< T >::_N, and gtm::TVector< T >::_vector.

Referenced by UtilVtk3DGeometriSelection::GetPointAndNormalIntersection(), and vtk3DSurfaceSTLWidget::GetPointAndNormalIntersection().

00131                           {
00132             VectorNormalize< T >( _vector, _vector, _N );
00133         };

Here is the caller graph for this function:

template<class T >
TVector< T > gtm::TVector< T >::operator! (  )  [inline]

Normalized vector.

Definition at line 358 of file vector.h.

References gtm::TVector< T >::_N, and gtm::TVector< T >::_vector.

00359     {
00360         TVector< T > ret( _N );
00361   
00362         VectorNormalize< T >( ret._vector, _vector, _N );
00363         return( ret );
00364   
00365     }

template<class T >
bool gtm::TVector< T >::operator!= ( const TVector< T > &  r  )  [inline]

Inequality.

Definition at line 286 of file vector.h.

References gtm::TVector< T >::_N, and gtm::TVector< T >::_vector.

00287     {
00288         uint i;
00289         bool ret;
00290 
00291         for(
00292             i = 0, ret = ( _N != r._N );
00293             i < _N && !ret;
00294             ret |= ( _vector[ i ] != r._vector[ i ] ), i++
00295             );
00296         return( ret );
00297 
00298     }

template<class T>
T& gtm::TVector< T >::operator() ( uint  i  )  [inline]

Reference operator.

Definition at line 111 of file vector.h.

References gtm::TVector< T >::_vector.

00111                                 {
00112             return( _vector[ i ] );
00113         };

template<class T >
TVector< T > gtm::TVector< T >::operator* ( r  )  [inline]

Scalar product.

Definition at line 335 of file vector.h.

References gtm::TVector< T >::_N, and gtm::TVector< T >::_vector.

00336     {
00337         TVector< T > ret( _N );
00338   
00339         VectorScalarProduct< T >( ret._vector, _vector, r, _N );
00340         return( ret );
00341   
00342     }

template<class T >
TMatrix< T > gtm::TVector< T >::operator* ( TMatrix< T > &  r  )  [inline]

Matrix product (defined in class TMatrix).

Definition at line 205 of file matrix.h.

00206     {
00207         TMatrix< T > m = *this;
00208         return( m * r );
00209 
00210     }

template<class T >
TVector< T > gtm::TVector< T >::operator* ( const TVector< T > &  r  )  [inline]

Cross product.

Definition at line 324 of file vector.h.

References gtm::TVector< T >::_N, gtm::TVector< T >::_vector, and GTM_MIN.

00325     {
00326         TVector< T > ret( GTM_MIN( _N, r._N ) );
00327   
00328         VectorCrossProduct< T >( ret._vector, _vector, r._vector );
00329         return( ret );
00330   
00331     }

template<class T>
TVector< T >& gtm::TVector< T >::operator*= ( r  )  [inline]

Scalar product.

Definition at line 177 of file vector.h.

00177                                         {
00178             *this = *this * r;
00179             return( *this );
00180         };

template<class T>
TVector< T >& gtm::TVector< T >::operator*= ( const TVector< T > &  r  )  [inline]

Cross product.

Definition at line 172 of file vector.h.

00172                                                           {
00173             *this = *this * r;
00174             return( *this );
00175         };

template<class T >
TVector< T > gtm::TVector< T >::operator+ ( const TVector< T > &  r  )  [inline]

Addition.

Binary operators.

Parameters:
r Right object (vector, matrix or scalar).

Definition at line 302 of file vector.h.

References gtm::TVector< T >::_N, gtm::TVector< T >::_vector, and GTM_MIN.

00303     {
00304         TVector< T > ret( GTM_MIN( _N, r._N ) );
00305   
00306         VectorAdd< T >( ret._vector, _vector, r._vector, GTM_MIN( _N, r._N ) );
00307         return( ret );
00308   
00309     }

template<class T>
TVector< T >& gtm::TVector< T >::operator+= ( const TVector< T > &  r  )  [inline]

Addition.

Self-assignation binary operators.

Parameters:
r Right object (vector, matrix or scalar).

Definition at line 162 of file vector.h.

00162                                                           {
00163             *this = *this + r;
00164             return( *this );
00165         };

template<class T >
TVector< T > gtm::TVector< T >::operator- (  )  [inline]

Unary operators.

Additive inverse.

Definition at line 346 of file vector.h.

References gtm::TVector< T >::_N, and gtm::TVector< T >::_vector.

00347     {
00348         TVector< T > ret( _N );
00349         uint i;
00350   
00351         for( i = 0; i < _N; ret._vector[ i ] = ( T )0 - _vector[ i ], i++ );
00352         return( ret );
00353   
00354     }

template<class T >
TVector< T > gtm::TVector< T >::operator- ( const TVector< T > &  r  )  [inline]

Substraction.

Definition at line 313 of file vector.h.

References gtm::TVector< T >::_N, gtm::TVector< T >::_vector, and GTM_MIN.

00314     {
00315         TVector< T > ret( GTM_MIN( _N, r._N ) );
00316   
00317         VectorSubtract< T >( ret._vector, _vector, r._vector, GTM_MIN( _N, r._N ) );
00318         return( ret );
00319   
00320     }

template<class T>
TVector< T >& gtm::TVector< T >::operator-= ( const TVector< T > &  r  )  [inline]

Substraction.

Definition at line 167 of file vector.h.

00167                                                           {
00168             *this = *this - r;
00169             return( *this );
00170         };

template<class T>
TVector< T >& gtm::TVector< T >::operator= ( r  )  [inline]

Scalar assignation.

Definition at line 93 of file vector.h.

References gtm::TVector< T >::_N, and gtm::TVector< T >::_vector.

00093                                        {
00094             VectorAssignScalar< T >( _vector, r, _N );
00095             return( *this );
00096         };

template<class T>
TVector< T >& gtm::TVector< T >::operator= ( T *  r  )  [inline]

ANSI assignation (r size must be, at least, N).

Definition at line 88 of file vector.h.

References gtm::TVector< T >::_N, and gtm::TVector< T >::_vector.

00088                                         {
00089             VectorAssignMemory< T >( _vector, r, _N );
00090             return( *this );
00091         };

template<class T >
TVector< T > & gtm::TVector< T >::operator= ( TMatrix< T > &  r  )  [inline]

Matrix assignation (defined in class TMatrix).

Definition at line 190 of file matrix.h.

References gtm::TVector< T >::_N, gtm::TVector< T >::_type, gtm::TVector< T >::_vector, COL_VECTOR, gtm::TMatrix< T >::GetM(), gtm::TMatrix< T >::GetN(), GTM_MIN, min, and ROW_VECTOR.

00191     {
00192         uint i, j, k, min;
00193 
00194         // This min calc. avoids to reserve temporary memory, so, be careful.
00195         min = GTM_MIN( r.GetN( ) * r.GetM( ), _N );
00196         _type = ( r.GetN( ) == 1 )? COL_VECTOR: ROW_VECTOR;
00197         for( i = 0, k = 0; i < r.GetN( ) && k < min; i++ )
00198             for( j = 0; j < r.GetM( ) && k < min; _vector[ k++ ] = r( i, j ), j++ );
00199         return( *this );
00200 
00201     }

Here is the call graph for this function:

template<class T >
TVector< T > & gtm::TVector< T >::operator= ( const TVector< T > &  r  )  [inline]

Vector assignation.

Assignation operators.

Parameters:
r Right object (vector or matrix).

Definition at line 257 of file vector.h.

References gtm::TVector< T >::_N, gtm::TVector< T >::_type, gtm::TVector< T >::_vector, and GTM_MIN.

00258     {
00259         /*
00260          * Only assigns the minimum cardinality (WARNING WITH NON-LOCAL MEMORY).
00261          */
00262         _type = r._type;
00263         VectorAssignMemory< T >( _vector, r._vector, GTM_MIN( _N, r._N ) );
00264         return( *this );
00265 
00266     }

template<class T >
bool gtm::TVector< T >::operator== ( const TVector< T > &  r  )  [inline]

Equality.

Comparation operators.

Parameters:
r Right object.

Definition at line 270 of file vector.h.

References gtm::TVector< T >::_N, and gtm::TVector< T >::_vector.

00271     {
00272         uint i;
00273         bool ret;
00274 
00275         for(
00276             i = 0, ret = ( _N == r._N );
00277             i < _N && ret;
00278             ret &= ( _vector[ i ] == r._vector[ i ] ), i++
00279             );
00280         return( ret );
00281 
00282     }

template<class T >
TVector< T > gtm::TVector< T >::operator~ (  )  [inline]

Transposed vector.

Definition at line 369 of file vector.h.

References gtm::TVector< T >::_type, COL_VECTOR, and ROW_VECTOR.

00370     {
00371         TVector< T > ret = *this;
00372   
00373         ret._type = ( _type == COL_VECTOR )? ROW_VECTOR: COL_VECTOR;
00374         return( ret );
00375   
00376     }

template<class T >
void gtm::TVector< T >::SetN ( uint  N  )  [inline]

Size change.

Definition at line 245 of file vector.h.

References gtm::TVector< T >::_myMemory, gtm::TVector< T >::_N, and gtm::TVector< T >::_vector.

00246     {
00247         if( _myMemory ) VectorFreeMemory< T >( _vector );
00248         _N        = N;
00249         _vector   = VectorAllocateMemory< T >( _N );
00250         _myMemory = true;
00251         VectorAssignScalar< T >( _vector, ( T )0, _N );
00252 
00253     }


Member Data Documentation

template<class T>
bool gtm::TVector< T >::_myMemory [private]

Have I created _vector?

Definition at line 204 of file vector.h.

Referenced by gtm::TVector< T >::SetN(), gtm::TVector< T >::TVector(), and gtm::TVector< T >::~TVector().

template<class T>
uint gtm::TVector< T >::_N [private]
template<class T>
int gtm::TVector< T >::_type [private]

Type (ROW_VECTOR/COL_VECTOR).

Definition at line 202 of file vector.h.

Referenced by gtm::TVector< T >::GetType(), gtm::TVector< T >::operator=(), gtm::TVector< T >::operator~(), and gtm::TVector< T >::TVector().

template<class T>
T* gtm::TVector< T >::_vector [private]

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

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1