gtm::TMatrix< T > Class Template Reference

#include <matrix.h>

List of all members.

Public Member Functions

 ~TMatrix ()
 Destructor.
T & operator() (uint i, uint j)
 Reference operator.
uint GetN ()
 Columns.
uint GetM ()
 Rows.
T ** GetAnsiRef ()
 Returns the ANSI (C/C++) reference.
Det ()
 Determinant.
void LoadIdentity ()
 Loads identity.



T ** _matrix
 Matrix' internal state.
uint _N
 Columns.
uint _M
 Rows.
 TMatrix (uint N=3, uint M=3, T data=(T) 0)
 Default constructor.
 TMatrix (const TMatrix< T > &r)
 Copy constructor.
 TMatrix (T **block, uint N, uint M)
 ANSI casting constructor.
TMatrix< T > & operator= (const TMatrix< T > &r)
 Natural assignation.
TMatrix< T > & operator= (TVector< T > &r)
 Vector assignation.
TMatrix< T > & operator= (T r)
 Scalar assignation.
bool operator== (const TMatrix< T > &r)
 Equality.
bool operator!= (const TMatrix< T > &r)
 Inequality.
TMatrix< T > operator+ (const TMatrix< T > &r)
 Addition.
TMatrix< T > operator- (const TMatrix< T > &r)
 Substraction.
TMatrix< T > operator* (const TMatrix< T > &r)
 Product.
TMatrix< T > operator* (TVector< T > &r)
 Product (vector).
TMatrix< T > operator* (T r)
 Scalar product.
TMatrix< T > & operator+= (const TMatrix< T > &r)
 Addition.
TMatrix< T > & operator-= (const TMatrix< T > &r)
 Substraction.
TMatrix< T > & operator*= (const TMatrix< T > &r)
 Product.
TMatrix< T > & operator*= (TVector< T > &r)
 Product (vector).
TMatrix< T > & operator*= (T r)
 Scalar product.
TMatrix< T > operator- ()
 Additive inverse.
TMatrix< T > operator! ()
 Matrix inverse.
TMatrix< T > operator~ ()
 Matrix transpose.

Detailed Description

template<class T>
class gtm::TMatrix< T >

TMatrix class.

This class defines a C++ template to use mathematical matrices of NxM.

See also:
TVector

Definition at line 39 of file matrix.h.


Constructor & Destructor Documentation

template<class T >
gtm::TMatrix< T >::TMatrix ( uint  N = 3,
uint  M = 3,
data = ( T )0 
) [inline]

Default constructor.

Constructors.

Parameters:
N Columns.
M Rows.
data Initial data.
r Copy object (matrix or vector).
block Memory block.

Definition at line 214 of file matrix.h.

References gtm::TMatrix< T >::_M, gtm::TMatrix< T >::_matrix, and gtm::TMatrix< T >::_N.

00215     {
00216         _N = N;
00217         _M = M;
00218         _matrix = MatrixAllocateMemory< T >( _N, _M );
00219         MatrixAssignScalar< T >( _matrix, data, _N, _M );
00220 
00221     }

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

Copy constructor.

Definition at line 225 of file matrix.h.

References gtm::TMatrix< T >::_M, gtm::TMatrix< T >::_matrix, and gtm::TMatrix< T >::_N.

00226     {
00227         _N = r._N;
00228         _M = r._M;
00229         _matrix = MatrixCopyMemory< T >( r._matrix, _N, _M );
00230 
00231     }

template<class T >
gtm::TMatrix< T >::TMatrix ( T **  block,
uint  N,
uint  M 
) [inline]

ANSI casting constructor.

Definition at line 235 of file matrix.h.

References gtm::TMatrix< T >::_M, gtm::TMatrix< T >::_matrix, and gtm::TMatrix< T >::_N.

00236     {
00237         _N = N;
00238         _M = M;
00239         _matrix = MatrixCopyMemory< T >( block, N, M );
00240 
00241     }

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

Destructor.

Definition at line 61 of file matrix.h.

References gtm::TMatrix< T >::_matrix, and gtm::TMatrix< T >::_N.

00061                     {
00062             MatrixFreeMemory< T >( _matrix, _N );
00063         };


Member Function Documentation

template<class T>
T gtm::TMatrix< T >::Det (  )  [inline]

Determinant.

Definition at line 106 of file matrix.h.

References gtm::TMatrix< T >::_matrix, and gtm::TMatrix< T >::_N.

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

00106                  {
00107             return( MatrixDeterminant< T >( _matrix, _N ) );
00108         };

Here is the caller graph for this function:

template<class T>
T** gtm::TMatrix< T >::GetAnsiRef (  )  [inline]

Returns the ANSI (C/C++) reference.

Definition at line 102 of file matrix.h.

References gtm::TMatrix< T >::_matrix.

00102                           {
00103             return( _matrix );
00104         };

template<class T>
uint gtm::TMatrix< T >::GetM (  )  [inline]

Rows.

Definition at line 98 of file matrix.h.

References gtm::TMatrix< T >::_M.

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

00098                      {
00099             return( _M );
00100         };

Here is the caller graph for this function:

template<class T>
uint gtm::TMatrix< T >::GetN (  )  [inline]

Columns.

Definition at line 94 of file matrix.h.

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

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

00094                      {
00095             return( _N );
00096         };

Here is the caller graph for this function:

template<class T>
void gtm::TMatrix< T >::LoadIdentity (  )  [inline]

Loads identity.

Definition at line 110 of file matrix.h.

References gtm::TMatrix< T >::_M, gtm::TMatrix< T >::_matrix, gtm::TMatrix< T >::_N, and GTM_MIN.

00110                              {
00111             MatrixLoadIdentity< T >( _matrix, GTM_MIN( _N, _M ) );
00112         };

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

Matrix inverse.

Definition at line 406 of file matrix.h.

References gtm::TMatrix< T >::_matrix, and gtm::TMatrix< T >::_N.

00407     {
00408         TMatrix< T > ret( _N, _N );
00409 
00410         if( _N <= 4 ) MatrixInverseAdjoint< T >( ret._matrix, _matrix, _N );
00411         else          MatrixInverseGauss< T >( ret._matrix, _matrix, _N );
00412         return( ret );
00413 
00414     }

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

Inequality.

Definition at line 307 of file matrix.h.

References gtm::TMatrix< T >::_M, gtm::TMatrix< T >::_matrix, and gtm::TMatrix< T >::_N.

00308     {
00309         uint i, j;
00310         bool ret;
00311 
00312         for(
00313             i = 0, ret = ( _N != r._N || _M != r._M );
00314             i < _N && !ret;
00315             i++
00316             ) for(
00317                 j = 0;
00318                 j < _M && !ret;
00319                 ret |= ( _matrix[ i ][ j ] != r._matrix[ i ][ j ] ), j++
00320                 );
00321         return( ret );
00322 
00323     }

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

Reference operator.

Definition at line 90 of file matrix.h.

References gtm::TMatrix< T >::_matrix.

00090                                         {
00091             return( _matrix[ i ][ j ] );
00092         };

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

Scalar product.

Definition at line 372 of file matrix.h.

References gtm::TMatrix< T >::_M, gtm::TMatrix< T >::_matrix, and gtm::TMatrix< T >::_N.

00373     {
00374         TMatrix< T > ret( _N, _M );
00375 
00376         MatrixScalarProduct< T >( ret._matrix, _matrix, r, _N, _M );
00377         return( ret );
00378 
00379     }

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

Product (vector).

Definition at line 383 of file matrix.h.

00384     {
00385         TMatrix< T > m;
00386         m = r;
00387         return( *this * m );
00388 
00389     }

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

Product.

Definition at line 361 of file matrix.h.

References gtm::TMatrix< T >::_M, gtm::TMatrix< T >::_matrix, and gtm::TMatrix< T >::_N.

00362     {
00363         TMatrix< T > ret( r._N, _M );
00364 
00365         MatrixProduct< T >( ret._matrix, _matrix, r._matrix, _N, _M, r._N );
00366         return( ret );
00367 
00368     }

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

Scalar product.

Definition at line 157 of file matrix.h.

00157                                         {
00158             *this = *this * r;
00159             return( *this );
00160         };

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

Product (vector).

Definition at line 152 of file matrix.h.

00152                                                     {
00153             *this = *this * r;
00154             return( *this );
00155         };

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

Product.

Definition at line 147 of file matrix.h.

00147                                                           {
00148             *this = *this * r;
00149             return( *this );
00150         };

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

Addition.

Binary operators.

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

Definition at line 327 of file matrix.h.

References gtm::TMatrix< T >::_M, gtm::TMatrix< T >::_matrix, gtm::TMatrix< T >::_N, and GTM_MIN.

00328     {
00329         TMatrix< T > ret( _N, _M );
00330 
00331         MatrixAdd< T >(
00332             ret._matrix,
00333             _matrix,
00334             r._matrix,
00335             GTM_MIN( _N, r._N ),
00336             GTM_MIN( _M, r._M )
00337             );
00338         return( ret );
00339 
00340     }

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

Addition.

Self-assignation binary operators.

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

Definition at line 137 of file matrix.h.

00137                                                           {
00138             *this = *this + r;
00139             return( *this );
00140         };

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

Additive inverse.

Unary operators.

Definition at line 393 of file matrix.h.

References gtm::TMatrix< T >::_M, gtm::TMatrix< T >::_matrix, and gtm::TMatrix< T >::_N.

00394     {
00395         TMatrix< T > ret( _N, _M );
00396         uint i, j;
00397   
00398         for( i = 0; i < _N; i++ )
00399             for( j = 0; j < _M; ret._matrix[ i ][ j ] = ( T )0 - _matrix[ i ][ j ], j++ );
00400         return( ret );
00401   
00402     }

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

Substraction.

Definition at line 344 of file matrix.h.

References gtm::TMatrix< T >::_M, gtm::TMatrix< T >::_matrix, gtm::TMatrix< T >::_N, and GTM_MIN.

00345     {
00346         TMatrix< T > ret( _N, _M );
00347   
00348         MatrixSubtract< T >(
00349             ret._matrix,
00350             _matrix,
00351             r._matrix,
00352             GTM_MIN( _N, r._N ),
00353             GTM_MIN( _M, r._M )
00354             );
00355         return( ret );
00356 
00357     }

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

Substraction.

Definition at line 142 of file matrix.h.

00142                                                           {
00143             *this = *this - r;
00144             return( *this );
00145         };

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

Scalar assignation.

Definition at line 278 of file matrix.h.

References gtm::TMatrix< T >::_M, gtm::TMatrix< T >::_matrix, and gtm::TMatrix< T >::_N.

00279     {
00280         MatrixAssignScalar< T >( _matrix, r, _N, _M );
00281         return( *this );
00282 
00283     }

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

Vector assignation.

Definition at line 261 of file matrix.h.

References gtm::TMatrix< T >::_M, gtm::TMatrix< T >::_matrix, gtm::TMatrix< T >::_N, COL_VECTOR, gtm::TVector< T >::GetN(), and gtm::TVector< T >::GetType().

00262     {
00263         uint i;
00264         uint n = r.GetN( );
00265         bool column = ( r.GetType( ) == COL_VECTOR );
00266 
00267         MatrixFreeMemory< T >( _matrix, _N );
00268         _N = ( column )? 1: n;
00269         _M = ( column )? n: 1;
00270         _matrix = MatrixAllocateMemory< T >( _N, _M );
00271         for( i = 0; i < n; _matrix[ ( column )? 0: i ][ ( column )? i: 0 ] = r( i ), i++ );
00272         return( *this );
00273   
00274     }

Here is the call graph for this function:

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

Natural assignation.

Assignation operators.

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

Definition at line 245 of file matrix.h.

References gtm::TMatrix< T >::_M, gtm::TMatrix< T >::_matrix, and gtm::TMatrix< T >::_N.

00246     {
00247         if( _N != r._N || _M != r._M ) {
00248 
00249             MatrixFreeMemory< T >( _matrix, _N );
00250             _N = r._N;
00251             _M = r._M;
00252             _matrix = MatrixCopyMemory< T >( r._matrix, _N, _M );
00253 
00254         } else MatrixAssignMemory< T >( _matrix, r._matrix, _N, _M );
00255         return( *this );
00256   
00257     }

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

Equality.

Comparation operators.

Parameters:
Right matrix.

Definition at line 287 of file matrix.h.

References gtm::TMatrix< T >::_M, gtm::TMatrix< T >::_matrix, and gtm::TMatrix< T >::_N.

00288     {
00289         uint i, j;
00290         bool ret;
00291 
00292         for(
00293             i = 0, ret = ( _N == r._N && _M == r._M );
00294             i < _N && ret;
00295             i++
00296             ) for(
00297                 j = 0;
00298                 j < _M && ret;
00299                 ret &= ( _matrix[ i ][ j ] == r._matrix[ i ][ j ] ), j++
00300                 );
00301         return( ret );
00302 
00303     }

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

Matrix transpose.

Definition at line 418 of file matrix.h.

References gtm::TMatrix< T >::_M, gtm::TMatrix< T >::_matrix, and gtm::TMatrix< T >::_N.

00419     {
00420         TMatrix< T > ret( _M, _N );
00421 
00422         MatrixTranspose< T >( ret._matrix, _matrix, _N, _M );
00423         return( ret );
00424 
00425     }


Member Data Documentation

template<class T>
uint gtm::TMatrix< T >::_M [private]
template<class T>
T** gtm::TMatrix< T >::_matrix [private]
template<class T>
uint gtm::TMatrix< T >::_N [private]

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

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1