Geogram Version 1.8.5
A programming library of geometric algorithms
Loading...
Searching...
No Matches
GEO::Matrix< DIM, FT > Class Template Reference

A matrix type. More...

#include <geogram/basic/matrix.h>

Public Types

typedef Matrix< DIM, FT > matrix_type
 
typedef FT value_type
 

Public Member Functions

 Matrix ()
 Default constructor.
 
 Matrix (const FT *vals)
 Constructs a matrix from an array of values.
 
index_t dimension () const
 Gets the matrix dimension.
 
void load_zero ()
 Clears the matrix.
 
void load_identity ()
 Sets the matrix to identity.
 
bool is_identity () const
 Tests whether a matrix is the identity matrix.
 
FT & operator() (index_t i, index_t j)
 Gets a modifiable element.
 
const FT & operator() (index_t i, index_t j) const
 Gets a non-modifiable element.
 
matrix_typeoperator+= (const matrix_type &m)
 Adds a matrix in place.
 
matrix_typeoperator-= (const matrix_type &m)
 Subtracts a matrix in place.
 
matrix_typeoperator*= (FT val)
 Multiplies by a scalar in place.
 
matrix_typeoperator/= (FT val)
 Divides by a scalar in place.
 
matrix_type operator+ (const matrix_type &m) const
 Adds 2 matrices.
 
matrix_type operator- (const matrix_type &m) const
 Subtracts 2 matrices.
 
matrix_type operator* (FT val) const
 Multiplies a matrix by a scalar.
 
matrix_type operator/ (FT val) const
 Divides a matrix by a scalar.
 
matrix_type operator* (const matrix_type &m) const
 Multiplies 2 matrices.
 
matrix_type inverse () const
 Computes the inverse matrix.
 
bool compute_inverse (matrix_type &result) const
 Computes the inverse matrix.
 
matrix_type transpose () const
 Computes the transposed matrix.
 
const FT * data () const
 Gets non-modifiable matrix data.
 
FT * data ()
 Gets modifiable matrix data.
 
void get_lower_triangle (FT *store) const
 Gets the lower triangle of the matrix.
 

Static Public Attributes

static const index_t dim = DIM
 

Related Symbols

(Note that these are not member symbols.)

template<index_t DIM, class FT >
std::ostream & operator<< (std::ostream &output, const Matrix< DIM, FT > &m)
 Writes a matrix to a stream.
 
template<index_t DIM, class FT >
std::istream & operator>> (std::istream &input, Matrix< DIM, FT > &m)
 Reads a matrix from a stream.
 
template<index_t DIM, class FT >
void mult (const Matrix< DIM, FT > &M, const FT *x, FT *y)
 Multiplies a matrix by a vector.
 

Detailed Description

template<index_t DIM, class FT>
class GEO::Matrix< DIM, FT >

A matrix type.

Matrix implements a square matrix of dimension DIM. containing coefficients of type T. Type T is expected to be a numeric type. Matrix provides the classical matrix operations.

Template Parameters
FTtype of the matrix elements
DIMdimension of the matrix

Definition at line 65 of file matrix.h.

Member Typedef Documentation

◆ matrix_type

template<index_t DIM, class FT >
typedef Matrix<DIM, FT> GEO::Matrix< DIM, FT >::matrix_type

This matrix type

Definition at line 68 of file matrix.h.

◆ value_type

template<index_t DIM, class FT >
typedef FT GEO::Matrix< DIM, FT >::value_type

The type of the values

Definition at line 71 of file matrix.h.

Constructor & Destructor Documentation

◆ Matrix() [1/2]

template<index_t DIM, class FT >
GEO::Matrix< DIM, FT >::Matrix ( )
inline

Default constructor.

This initializes the matrix to the identity matrix

See also
load_identity()

Definition at line 81 of file matrix.h.

◆ Matrix() [2/2]

template<index_t DIM, class FT >
GEO::Matrix< DIM, FT >::Matrix ( const FT *  vals)
inlineexplicit

Constructs a matrix from an array of values.

Parameters
[in]valsa const pointer to the DIM*DIM values, coefficients of the same rows are consecutive in memory, i is the slowly varying index and j the quickly varying one.

Definition at line 91 of file matrix.h.

Member Function Documentation

◆ compute_inverse()

template<index_t DIM, class FT >
bool GEO::Matrix< DIM, FT >::compute_inverse ( matrix_type result) const
inline

Computes the inverse matrix.

Computes matrix M such that (this * M) = identity

Parameters
[out]resultthe inverse matrix
Returns
true if the matrix is inversible
Return values
falseotherwise

Definition at line 330 of file matrix.h.

◆ data() [1/2]

template<index_t DIM, class FT >
FT * GEO::Matrix< DIM, FT >::data ( )
inline

Gets modifiable matrix data.

For interfacing with Fortran, OpenGL etc...

Returns
a pointer to the first element of the matrix

Definition at line 411 of file matrix.h.

◆ data() [2/2]

template<index_t DIM, class FT >
const FT * GEO::Matrix< DIM, FT >::data ( ) const
inline

Gets non-modifiable matrix data.

For interfacing with Fortran, OpenGL etc...

Returns
a const pointer to the first element of the matrix

Definition at line 401 of file matrix.h.

◆ dimension()

template<index_t DIM, class FT >
index_t GEO::Matrix< DIM, FT >::dimension ( ) const
inline

Gets the matrix dimension.

Returns
the value of DIM

Definition at line 104 of file matrix.h.

◆ get_lower_triangle()

template<index_t DIM, class FT >
void GEO::Matrix< DIM, FT >::get_lower_triangle ( FT *  store) const
inline

Gets the lower triangle of the matrix.

Gets all the coefficients of the matrix under the diagonal (included) to array store, Array store must be large enough to contain (DIM * (DIM+1))/2 values.

Parameters
[in]storean array of at least (DIM * (DIM+1))/2 values

Definition at line 422 of file matrix.h.

◆ inverse()

template<index_t DIM, class FT >
matrix_type GEO::Matrix< DIM, FT >::inverse ( ) const
inline

Computes the inverse matrix.

Computes matrix M such that (this * M) = identity

Returns
the inverse matrix

Definition at line 315 of file matrix.h.

◆ is_identity()

template<index_t DIM, class FT >
bool GEO::Matrix< DIM, FT >::is_identity ( ) const
inline

Tests whether a matrix is the identity matrix.

Return values
trueif the matrix is the identity matrix
falseotherwise

Definition at line 138 of file matrix.h.

◆ load_identity()

template<index_t DIM, class FT >
void GEO::Matrix< DIM, FT >::load_identity ( )
inline

Sets the matrix to identity.

This sets all coefficients of this matrix to be equal to DIM x DIM identity matrix.

Definition at line 125 of file matrix.h.

◆ load_zero()

template<index_t DIM, class FT >
void GEO::Matrix< DIM, FT >::load_zero ( )
inline

Clears the matrix.

This resets all values to 0 (zero)

Definition at line 112 of file matrix.h.

◆ operator()() [1/2]

template<index_t DIM, class FT >
FT & GEO::Matrix< DIM, FT >::operator() ( index_t  i,
index_t  j 
)
inline

Gets a modifiable element.

Gets element at row i and column j in the matrix. If indices are out of range, the function calls abort().

Parameters
[in]irow index of the element
[in]jcolumn index of the element
Returns
a reference to the element at coordinates (i, j).

Definition at line 158 of file matrix.h.

◆ operator()() [2/2]

template<index_t DIM, class FT >
const FT & GEO::Matrix< DIM, FT >::operator() ( index_t  i,
index_t  j 
) const
inline

Gets a non-modifiable element.

Gets element at row i and column j in the matrix. If indices are out of range, the function calls abort().

Parameters
[in]irow index of the element
[in]jcolumn index of the element
Returns
a const reference to the element at coordinates (i, j).

Definition at line 172 of file matrix.h.

◆ operator*() [1/2]

template<index_t DIM, class FT >
matrix_type GEO::Matrix< DIM, FT >::operator* ( const matrix_type m) const
inline

Multiplies 2 matrices.

Builds a matrix by multiplying this matrix by matrix m.

Parameters
[in]manother matrix
Returns
the matrix (this * m)

Definition at line 297 of file matrix.h.

◆ operator*() [2/2]

template<index_t DIM, class FT >
matrix_type GEO::Matrix< DIM, FT >::operator* ( FT  val) const
inline

Multiplies a matrix by a scalar.

Builds a matrix by multiplying all the coefficients of this matrix by scalar value val.

Parameters
[in]vala scalar value of the same type than matrix elements
Returns
the resulting matrix

Definition at line 271 of file matrix.h.

◆ operator*=()

template<index_t DIM, class FT >
matrix_type & GEO::Matrix< DIM, FT >::operator*= ( FT  val)
inline

Multiplies by a scalar in place.

This multiplies all the coefficients of this matrix by the value val.

Parameters
[in]vala scalar value of the same type than matrix elements
Returns
a reference to this matrix

Definition at line 215 of file matrix.h.

◆ operator+()

template<index_t DIM, class FT >
matrix_type GEO::Matrix< DIM, FT >::operator+ ( const matrix_type m) const
inline

Adds 2 matrices.

Builds a matrix by adding matrix m to this matrix.

Parameters
[in]manother matrix
Returns
the matrix (this + m)

Definition at line 246 of file matrix.h.

◆ operator+=()

template<index_t DIM, class FT >
matrix_type & GEO::Matrix< DIM, FT >::operator+= ( const matrix_type m)
inline

Adds a matrix in place.

This adds matrix m to this matrix in place.

Parameters
[in]ma matrix of the same dimension
Returns
a reference to this matrix

Definition at line 184 of file matrix.h.

◆ operator-()

template<index_t DIM, class FT >
matrix_type GEO::Matrix< DIM, FT >::operator- ( const matrix_type m) const
inline

Subtracts 2 matrices.

Builds a matrix by subtracting matrix m to this matrix.

Parameters
[in]manother matrix
Returns
the matrix (this + m)

Definition at line 258 of file matrix.h.

◆ operator-=()

template<index_t DIM, class FT >
matrix_type & GEO::Matrix< DIM, FT >::operator-= ( const matrix_type m)
inline

Subtracts a matrix in place.

This subtracts matrix m from this matrix in place.

Parameters
[in]ma matrix of the same dimension
Returns
a reference to this matrix

Definition at line 199 of file matrix.h.

◆ operator/()

template<index_t DIM, class FT >
matrix_type GEO::Matrix< DIM, FT >::operator/ ( FT  val) const
inline

Divides a matrix by a scalar.

Builds a matrix by dividing all the coefficients of this matrix by scalar value val.

Parameters
[in]vala scalar value of the same type than matrix elements
Returns
the resulting matrix

Definition at line 284 of file matrix.h.

◆ operator/=()

template<index_t DIM, class FT >
matrix_type & GEO::Matrix< DIM, FT >::operator/= ( FT  val)
inline

Divides by a scalar in place.

This divides all the coefficients of this matrix by the value val.

Parameters
[in]vala scalar value of the same type than matrix elements
Returns
a reference to this matrix

Definition at line 231 of file matrix.h.

◆ transpose()

template<index_t DIM, class FT >
matrix_type GEO::Matrix< DIM, FT >::transpose ( ) const
inline

Computes the transposed matrix.

Returns
the transposed matrix

Definition at line 385 of file matrix.h.

Friends And Related Symbol Documentation

◆ mult()

template<index_t DIM, class FT >
void mult ( const Matrix< DIM, FT > &  M,
const FT *  x,
FT *  y 
)
related

Multiplies a matrix by a vector.

Multiplies matrix M by vector x and stores the result in vector y. Vectors x and y are given as arrays of elements and must at least contain DIM elements, otherwise the result is undefined.

Parameters
[in]Ma DIM x DIM matrix
[in]xthe input vector
[in]ythe result of the multiplication
Template Parameters
FTthe type of the matrix elements
DIMthe dimension of the matrix

Definition at line 496 of file matrix.h.

◆ operator<<()

template<index_t DIM, class FT >
std::ostream & operator<< ( std::ostream &  output,
const Matrix< DIM, FT > &  m 
)
related

Writes a matrix to a stream.

This writes the coefficients of matrix m separated by a space character to the output stream output.

Parameters
[in]outputthe output stream
[in]mthe matrix to write
Returns
a reference to the output stream output

Definition at line 446 of file matrix.h.

◆ operator>>()

template<index_t DIM, class FT >
std::istream & operator>> ( std::istream &  input,
Matrix< DIM, FT > &  m 
)
related

Reads a matrix from a stream.

This reads DIM * DIM coefficients from the input stream input and stores them in matrix m

Parameters
[in]inputthe input stream
[out]mthe matrix to read
Returns
a reference to the input stream input

Definition at line 469 of file matrix.h.

Member Data Documentation

◆ dim

template<index_t DIM, class FT >
const index_t GEO::Matrix< DIM, FT >::dim = DIM
static

The dimension of the matrix

Definition at line 74 of file matrix.h.


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