DGtal  0.9.4beta
Public Types | Public Member Functions | Static Public Attributes | Private Attributes
DGtal::SimpleMatrix< TComponent, TM, TN > Class Template Reference

#include <DGtal/math/linalg/SimpleMatrix.h>

Inheritance diagram for DGtal::SimpleMatrix< TComponent, TM, TN >:
[legend]
Collaboration diagram for DGtal::SimpleMatrix< TComponent, TM, TN >:
[legend]

Public Types

typedef TComponent Component
 
typedef PointVector< N, ComponentRowVector
 
typedef PointVector< M, ComponentColumnVector
 
typedef SimpleMatrix< Component, TM, TN > Self
 
typedef Dimension Index
 
typedef Component Scalar
 

Public Member Functions

 BOOST_CONCEPT_ASSERT ((concepts::CEuclideanRing< TComponent >))
 
 BOOST_STATIC_ASSERT (TM > 0)
 
 BOOST_STATIC_ASSERT (TM > 0)
 
 SimpleMatrix ()
 
 SimpleMatrix (std::initializer_list< TComponent > values)
 
 SimpleMatrix (const Self &other)
 
void clear ()
 
void constant (const Component &aScalar)
 
void identity ()
 
void setIdentity ()
 
RowVector row (const DGtal::Dimension i) const
 
Index rows () const
 
ColumnVector column (const DGtal::Dimension j) const
 
Index cols () const
 
void setComponent (const DGtal::Dimension i, const DGtal::Dimension j, const Component &aValue)
 
Component operator() (const DGtal::Dimension i, const DGtal::Dimension j) const
 
Componentoperator() (const DGtal::Dimension i, const DGtal::Dimension j)
 
bool operator== (const Self &aMatrix) const
 
template<typename TComponentOther >
Selfoperator= (const SimpleMatrix< TComponentOther, M, N > &aMatrix)
 
Self operator+ (const Self &aMatrix) const
 
Selfoperator+= (const Self &aMatrix)
 
Self operator- (const Self &aMatrix) const
 
Selfoperator-= (const Self &aMatrix)
 
Self operator* (const Component &aScalar) const
 
Selfoperator*= (const Component &aScalar)
 
Self operator/ (const Component &aScalar) const
 
Selfoperator/= (const Component &aScalar)
 
SimpleMatrix< Component, TM, TM > operator* (const SimpleMatrix< Component, N, M > &aMatrix) const
 
ColumnVector operator* (const RowVector &aVector) const
 
SimpleMatrix< Component, TN, TM > transpose () const
 
Component cofactor (const DGtal::Dimension i, const DGtal::Dimension j) const
 
Self cofactor () const
 
Component minorDeterminant (const DGtal::Dimension i, const DGtal::Dimension j) const
 
Component determinant () const
 
SimpleMatrix< Component, TM, TN > inverse () const
 
 ~SimpleMatrix ()
 
void selfDisplay (std::ostream &out) const
 
bool isValid () const
 

Static Public Attributes

static const DGtal::Dimension M = TM
 
static const DGtal::Dimension N = TN
 

Private Attributes

std::array< Component, M *NmyValues
 
std::array< Component, M *NmyCofactorCoefs
 

Detailed Description

template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
class DGtal::SimpleMatrix< TComponent, TM, TN >

Aim: implements basic MxN Matrix services (M,N>=1).

Description of template class 'SimpleMatrix'

This class defines simple matrix with static size. Computations are performed in the euclidean ring associated with the type TComponent.

Matrix coefficient indices are in the range [0,M-1] and [0,N-1].

This class also defines types for row and column vectors as specialized PointVector types.

Class inspired by Anis Benyoub (INSA-Lyon).

Template Parameters
TComponentany model of CEuclideanRing
TMnumber of rows of the matrix
TNnumber of columns of the matrix
Examples:
examples/tutorial-examples/polyhedralizer.cpp, and tutorial-examples/polyhedralizer.cpp.

Definition at line 75 of file SimpleMatrix.h.

Member Typedef Documentation

template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
typedef PointVector<M,Component> DGtal::SimpleMatrix< TComponent, TM, TN >::ColumnVector

Definition at line 84 of file SimpleMatrix.h.

template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
typedef TComponent DGtal::SimpleMatrix< TComponent, TM, TN >::Component

Definition at line 79 of file SimpleMatrix.h.

template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
typedef Dimension DGtal::SimpleMatrix< TComponent, TM, TN >::Index

Types needed by CLinearAlgebraContainer.

Definition at line 89 of file SimpleMatrix.h.

template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
typedef PointVector<N,Component> DGtal::SimpleMatrix< TComponent, TM, TN >::RowVector

Definition at line 83 of file SimpleMatrix.h.

template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
typedef Component DGtal::SimpleMatrix< TComponent, TM, TN >::Scalar

Definition at line 90 of file SimpleMatrix.h.

template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
typedef SimpleMatrix<Component,TM,TN> DGtal::SimpleMatrix< TComponent, TM, TN >::Self

Definition at line 86 of file SimpleMatrix.h.

Constructor & Destructor Documentation

template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
DGtal::SimpleMatrix< TComponent, TM, TN >::SimpleMatrix ( )

Create a static mxn matrix.

SimpleMatrix values are all set to the zero value associated to Component type.

template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
DGtal::SimpleMatrix< TComponent, TM, TN >::SimpleMatrix ( std::initializer_list< TComponent >  values)

Constructor from initializer list.

This matrix values are given row by row (top to bottom) from left to right. {a,b,c,d} = [[a b] [c d]]

Parameters
valuesthe initializer list.
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
DGtal::SimpleMatrix< TComponent, TM, TN >::SimpleMatrix ( const Self other)

Copy constructor.

Parameters
otherthe object to clone. Forbidden by default.
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
DGtal::SimpleMatrix< TComponent, TM, TN >::~SimpleMatrix ( )

Destructor.

Member Function Documentation

template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
DGtal::SimpleMatrix< TComponent, TM, TN >::BOOST_CONCEPT_ASSERT ( (concepts::CEuclideanRing< TComponent >)  )
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
DGtal::SimpleMatrix< TComponent, TM, TN >::BOOST_STATIC_ASSERT ( TM  ,
 
)
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
DGtal::SimpleMatrix< TComponent, TM, TN >::BOOST_STATIC_ASSERT ( TM  ,
 
)
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
void DGtal::SimpleMatrix< TComponent, TM, TN >::clear ( )
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
Component DGtal::SimpleMatrix< TComponent, TM, TN >::cofactor ( const DGtal::Dimension  i,
const DGtal::Dimension  j 
) const

Cofactor of the matrix at position (i,j).

Precondition
the matrix is a square one.
Returns
the cofactor at (i,j).
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
Self DGtal::SimpleMatrix< TComponent, TM, TN >::cofactor ( ) const

Cofactor matrix computation.

Precondition
the matrix is a square one.
Returns
the cofactor matrix.
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
Index DGtal::SimpleMatrix< TComponent, TM, TN >::cols ( ) const
inline

Get number of columns.

Definition at line 173 of file SimpleMatrix.h.

173 { return N; }
static const DGtal::Dimension N
Definition: SimpleMatrix.h:81
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
ColumnVector DGtal::SimpleMatrix< TComponent, TM, TN >::column ( const DGtal::Dimension  j) const
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
void DGtal::SimpleMatrix< TComponent, TM, TN >::constant ( const Component aScalar)
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
Component DGtal::SimpleMatrix< TComponent, TM, TN >::determinant ( ) const

Returns the determinant of square matrix. Slow method for large matrices.

Precondition
this must be NxN

Specialized methods exist for 2x2 and 3x3 matrices.

Returns
the determinant.
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
void DGtal::SimpleMatrix< TComponent, TM, TN >::identity ( )
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
SimpleMatrix<Component,TM,TN> DGtal::SimpleMatrix< TComponent, TM, TN >::inverse ( ) const

Compute the inverse of the matrix.

Precondition
the matrix is a square one.
Returns
the inverse matrix.

Referenced by DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::SphericalHoughNormalVectorEstimator().

template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
bool DGtal::SimpleMatrix< TComponent, TM, TN >::isValid ( ) const

Checks the validity/consistency of the object.

Returns
'true' if the object is valid, 'false' otherwise.
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
Component DGtal::SimpleMatrix< TComponent, TM, TN >::minorDeterminant ( const DGtal::Dimension  i,
const DGtal::Dimension  j 
) const

Return the minor determinant (i,j) of the current matrix

Specialized methods exist for 2x2 and 3x3 matrices.

Precondition
the matrix is a square one.
Parameters
irow index
jcolumn index
Returns
the minor (i,j)
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
Component DGtal::SimpleMatrix< TComponent, TM, TN >::operator() ( const DGtal::Dimension  i,
const DGtal::Dimension  j 
) const

Get a value at position (i,j).

Parameters
irow index
jcolumn index
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
Component& DGtal::SimpleMatrix< TComponent, TM, TN >::operator() ( const DGtal::Dimension  i,
const DGtal::Dimension  j 
)

Get a reference to the value at position (i,j).

Parameters
irow index
jcolumn index
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
Self DGtal::SimpleMatrix< TComponent, TM, TN >::operator* ( const Component aScalar) const

Product between the matrix 'this' and a scalar

Parameters
aScalarthe scalar coefficient
Returns
the resulting matrix
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
SimpleMatrix<Component,TM,TM> DGtal::SimpleMatrix< TComponent, TM, TN >::operator* ( const SimpleMatrix< Component, N, M > &  aMatrix) const

Product between the matrix 'this' and aMatrix.

Note
the product is O(N^3) for NxN matrices.
Parameters
aMatrixthe NxM matrix to multiply
Returns
the product MxM matrix
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
ColumnVector DGtal::SimpleMatrix< TComponent, TM, TN >::operator* ( const RowVector aVector) const

Product between the matrix and a Column vector.

Note
the product is O(N^3) for NxN matrices.
Parameters
aVectorthe vector to multiply
Returns
the product MxM matrix
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
Self& DGtal::SimpleMatrix< TComponent, TM, TN >::operator*= ( const Component aScalar)

Product between the matrix 'this' and a scalar

Parameters
aScalarthe scalar coefficient
Returns
the resulting a reference to the matrix
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
Self DGtal::SimpleMatrix< TComponent, TM, TN >::operator+ ( const Self aMatrix) const

Addition between the matrix 'this' and aMatrix.

Parameters
aMatrixthe matrix to add to self.
Returns
the summed matrix
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
Self& DGtal::SimpleMatrix< TComponent, TM, TN >::operator+= ( const Self aMatrix)

Addition and assignment between the matrix 'this' and aMatrix.

Parameters
aMatrixthe matrix to add to self.
Returns
a reference to the result
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
Self DGtal::SimpleMatrix< TComponent, TM, TN >::operator- ( const Self aMatrix) const

Substract between the matrix 'this' and aMatrix.

Parameters
aMatrixthe matrix to substract to self.
Returns
the difference matrix
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
Self& DGtal::SimpleMatrix< TComponent, TM, TN >::operator-= ( const Self aMatrix)

Substract and assignment between the matrix 'this' and aMatrix.

Parameters
aMatrixthe matrix to substract to self.
Returns
a reference to the result
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
Self DGtal::SimpleMatrix< TComponent, TM, TN >::operator/ ( const Component aScalar) const

Division of a matrix by a scalar.

Parameters
aScalarthe scalar value
Returns
the resulting matrix
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
Self& DGtal::SimpleMatrix< TComponent, TM, TN >::operator/= ( const Component aScalar)

Division of a matrix by a scalar.

Parameters
aScalarthe scalar value
Returns
a reference to the updated matrix
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
template<typename TComponentOther >
Self& DGtal::SimpleMatrix< TComponent, TM, TN >::operator= ( const SimpleMatrix< TComponentOther, M, N > &  aMatrix)

Assignment operator from another matrix. Note: a static_cast from TComponentOther to Component is performed.

Template Parameters
TComponentOtheranother Component type.
Parameters
aMatrixthe matrix to copy.
Returns
reference on the matrix
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
bool DGtal::SimpleMatrix< TComponent, TM, TN >::operator== ( const Self aMatrix) const

SimpleMatrix comparison.

Parameters
aMatrixanother matrix.
Returns
true if aMatrix equals this
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
RowVector DGtal::SimpleMatrix< TComponent, TM, TN >::row ( const DGtal::Dimension  i) const

Get row vector.

Parameters
ithe row index
Returns
the i-th row
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
Index DGtal::SimpleMatrix< TComponent, TM, TN >::rows ( ) const
inline

Get number of rows.

Definition at line 159 of file SimpleMatrix.h.

159 { return M; }
static const DGtal::Dimension M
Definition: SimpleMatrix.h:80
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
void DGtal::SimpleMatrix< TComponent, TM, TN >::selfDisplay ( std::ostream &  out) const

Writes/Displays the object on an output stream.

Parameters
outthe output stream where the object is written.
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
void DGtal::SimpleMatrix< TComponent, TM, TN >::setComponent ( const DGtal::Dimension  i,
const DGtal::Dimension  j,
const Component aValue 
)

Set a value at position (i,j).

Precondition
(i,j) must be in the range [0,M-1]x[0,N-1]
Parameters
irow index
jcolumn index
aValuea component

Referenced by DGtal::functors::TensorVotingFeatureExtraction< TSurfel, TEmbedder >::pushSurfel(), and DGtal::functors::SphericalHoughNormalVectorEstimator< TSurfel, TEmbedder >::randomRotation().

template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
void DGtal::SimpleMatrix< TComponent, TM, TN >::setIdentity ( )
inline

Definition at line 145 of file SimpleMatrix.h.

145 { identity(); }
template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
SimpleMatrix<Component,TN,TM> DGtal::SimpleMatrix< TComponent, TM, TN >::transpose ( ) const

Transpose the matrix.

Returns
the transposted NxM matrix

Field Documentation

template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
const DGtal::Dimension DGtal::SimpleMatrix< TComponent, TM, TN >::M = TM
static

Definition at line 80 of file SimpleMatrix.h.

Referenced by DGtal::SimpleMatrix< double, 3, 3 >::rows().

template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
std::array< Component, M*N> DGtal::SimpleMatrix< TComponent, TM, TN >::myCofactorCoefs
private

Static computation of cofactor coefficients

Todo:
should be static

Definition at line 419 of file SimpleMatrix.h.

template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
std::array< Component, M*N> DGtal::SimpleMatrix< TComponent, TM, TN >::myValues
private

Matrix values containers.

Definition at line 415 of file SimpleMatrix.h.

template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
const DGtal::Dimension DGtal::SimpleMatrix< TComponent, TM, TN >::N = TN
static

Definition at line 81 of file SimpleMatrix.h.

Referenced by DGtal::SimpleMatrix< double, 3, 3 >::cols().


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