CCCoreLib 31 May 2022
CloudCompare Core algorithms
Public Member Functions | Public Attributes | List of all members
CCCoreLib::SquareMatrixTpl< Scalar > Class Template Reference

Square matrix. More...

#include <SquareMatrix.h>

Public Member Functions

 SquareMatrixTpl ()
 Default constructor. More...
 
 SquareMatrixTpl (unsigned size)
 Constructor with a given size. More...
 
 SquareMatrixTpl (const SquareMatrixTpl< double > &mat)
 Constructor from another double matrix. More...
 
 SquareMatrixTpl (const SquareMatrixTpl< float > &mat)
 Constructor from another float matrix. More...
 
 SquareMatrixTpl (const float M16f[], bool rotationOnly=false)
 "From OpenGl" constructor (float version) More...
 
 SquareMatrixTpl (const double M16d[], bool rotationOnly=false)
 "From OpenGl" constructor (double version) More...
 
virtual ~SquareMatrixTpl ()
 Default destructor.
 
unsigned size () const
 Returns matrix size.
 
bool isValid () const
 Returns matrix validity. More...
 
void invalidate ()
 Invalidates matrix. More...
 
Scalar * row (unsigned index)
 Returns pointer to matrix row.
 
void setValue (unsigned row, unsigned column, Scalar value)
 Sets a particular matrix value.
 
Scalar getValue (unsigned row, unsigned column) const
 Returns a particular matrix value.
 
SquareMatrixTploperator= (const SquareMatrixTpl &B)
 Matrix copy operator.
 
SquareMatrixTpl operator+ (const SquareMatrixTpl &B) const
 Addition.
 
const SquareMatrixTploperator+= (const SquareMatrixTpl &B)
 In-place addition.
 
SquareMatrixTpl operator- (const SquareMatrixTpl &B) const
 Subtraction.
 
const SquareMatrixTploperator-= (const SquareMatrixTpl &B)
 In-place subtraction.
 
SquareMatrixTpl operator* (const SquareMatrixTpl &B) const
 Multiplication (M = A*B)
 
Vector3Tpl< Scalar > operator* (const CCVector3f &V) const
 Multiplication by a vector.
 
CCVector3d operator* (const CCVector3d &V) const
 Multiplication by a vector.
 
const SquareMatrixTploperator*= (const SquareMatrixTpl &B)
 In-place multiplication.
 
void apply (const float vec[], float result[]) const
 Multiplication by a float vector, outputs a float vector. More...
 
void apply (const float vec[], double result[]) const
 Multiplication by a float vector, outputs a double vector. More...
 
void apply (const double vec[], double result[]) const
 Multiplication by a double vector. More...
 
void transpose ()
 In-place transpose.
 
SquareMatrixTpl transposed () const
 Returns the transposed version of this matrix.
 
void clear ()
 Sets all elements to 0.
 
SquareMatrixTpl inv () const
 Returns inverse (Gauss)
 
void print (FILE *fp=nullptr) const
 Prints out matrix to console or file. More...
 
void toIdentity ()
 Sets matrix to identity.
 
void scale (Scalar coef)
 Scales matrix (all elements are multiplied by the same coef.)
 
Scalar trace () const
 Returns trace.
 
double computeDet () const
 Returns determinant.
 
void initFromQuaternion (const float q[])
 Creates a rotation matrix from a quaternion (float version) More...
 
void initFromQuaternion (const double q[])
 Creates a rotation matrix from a quaternion (double version) More...
 
bool toQuaternion (double q[])
 Converts rotation matrix to quaternion. More...
 
Scalar deltaDeterminant (unsigned column, Scalar *Vec) const
 Returns Delta-determinant (see Kramer formula)
 
void toGlMatrix (float M16f[]) const
 Converts a 3*3 or 4*4 matrix to an OpenGL-style float matrix (float[16])
 
void toGlMatrix (double M16d[]) const
 Converts a 3*3 or 4*4 matrix to an OpenGL-style double matrix (double[16])
 
bool svd (SquareMatrixTpl &S, SquareMatrixTpl &U, SquareMatrixTpl &V) const
 SVD decomposition (inspired from https://github.com/dmalhotra/pvfmm/blob/develop/include/mat_utils.txx)
 

Public Attributes

Scalar ** m_values = nullptr
 The matrix rows. More...
 

Detailed Description

template<typename Scalar>
class CCCoreLib::SquareMatrixTpl< Scalar >

Square matrix.

Row-major ordered matrix (i.e. elements are accessed with 'values[row][column]')

Constructor & Destructor Documentation

◆ SquareMatrixTpl() [1/6]

template<typename Scalar >
CCCoreLib::SquareMatrixTpl< Scalar >::SquareMatrixTpl ( )
inline

Default constructor.

Warning: invalid matrix.

◆ SquareMatrixTpl() [2/6]

template<typename Scalar >
CCCoreLib::SquareMatrixTpl< Scalar >::SquareMatrixTpl ( unsigned  size)
inline

Constructor with a given size.

Parameters
sizethe (square) matrix dimension

◆ SquareMatrixTpl() [3/6]

template<typename Scalar >
CCCoreLib::SquareMatrixTpl< Scalar >::SquareMatrixTpl ( const SquareMatrixTpl< double > &  mat)
inline

Constructor from another double matrix.

Parameters
matmatrix

◆ SquareMatrixTpl() [4/6]

template<typename Scalar >
CCCoreLib::SquareMatrixTpl< Scalar >::SquareMatrixTpl ( const SquareMatrixTpl< float > &  mat)
inline

Constructor from another float matrix.

Parameters
matmatrix

◆ SquareMatrixTpl() [5/6]

template<typename Scalar >
CCCoreLib::SquareMatrixTpl< Scalar >::SquareMatrixTpl ( const float  M16f[],
bool  rotationOnly = false 
)
inline

"From OpenGl" constructor (float version)

The matrix dimension is automatically set to 4. It can be forced to 3 (size_3 = true). In this case, only the rotation part will be 'imported'.

Parameters
M16fa table of 16 floats (OpenGL float transformation matrix)
rotationOnlyconsider only the roation part (3x3 matrix)

◆ SquareMatrixTpl() [6/6]

template<typename Scalar >
CCCoreLib::SquareMatrixTpl< Scalar >::SquareMatrixTpl ( const double  M16d[],
bool  rotationOnly = false 
)
inline

"From OpenGl" constructor (double version)

The matrix dimension is automatically set to 4. It can be forced to 3 (size_3 = true). In this case, only the rotation part will be 'imported'.

Parameters
M16da table of 16 floats (OpenGL double transformation matrix)
rotationOnlyconsider only the roation part (3x3 matrix)

Member Function Documentation

◆ apply() [1/3]

template<typename Scalar >
void CCCoreLib::SquareMatrixTpl< Scalar >::apply ( const double  vec[],
double  result[] 
) const
inline

Multiplication by a double vector.

Vec must have the same size as this matrix.

Parameters
vecinput vector
resultoutput vector (= M * vec)

◆ apply() [2/3]

template<typename Scalar >
void CCCoreLib::SquareMatrixTpl< Scalar >::apply ( const float  vec[],
double  result[] 
) const
inline

Multiplication by a float vector, outputs a double vector.

Vec must have the same size as this matrix.

Parameters
vecinput vector
resultoutput vector (= M * vec)

◆ apply() [3/3]

template<typename Scalar >
void CCCoreLib::SquareMatrixTpl< Scalar >::apply ( const float  vec[],
float  result[] 
) const
inline

Multiplication by a float vector, outputs a float vector.

Vec must have the same size as this matrix.

Parameters
vecinput vector
resultoutput vector (= M * vec)

◆ initFromQuaternion() [1/2]

template<typename Scalar >
void CCCoreLib::SquareMatrixTpl< Scalar >::initFromQuaternion ( const double  q[])
inline

Creates a rotation matrix from a quaternion (double version)

Quaternion is composed of 4 values: an angle (cos(alpha/2)) and an axis (sin(alpha/2)*unit vector).

Parameters
qnormalized quaternion (w,x,y,z)

◆ initFromQuaternion() [2/2]

template<typename Scalar >
void CCCoreLib::SquareMatrixTpl< Scalar >::initFromQuaternion ( const float  q[])
inline

Creates a rotation matrix from a quaternion (float version)

Shortcut to double version of initFromQuaternion)

Parameters
qnormalized quaternion (4 float values)

◆ invalidate()

template<typename Scalar >
void CCCoreLib::SquareMatrixTpl< Scalar >::invalidate ( )
inline

Invalidates matrix.

Size is reset to 0.

◆ isValid()

template<typename Scalar >
bool CCCoreLib::SquareMatrixTpl< Scalar >::isValid ( ) const
inline

Returns matrix validity.

Matrix is invalid if its size is 0!

◆ print()

template<typename Scalar >
void CCCoreLib::SquareMatrixTpl< Scalar >::print ( FILE *  fp = nullptr) const
inline

Prints out matrix to console or file.

Parameters
fpASCII FILE handle (or 0 to print to console)

◆ toQuaternion()

template<typename Scalar >
bool CCCoreLib::SquareMatrixTpl< Scalar >::toQuaternion ( double  q[])
inline

Converts rotation matrix to quaternion.

Warning: for 3x3 matrix only! From libE57 'best practices' (http://www.libe57.org/best.html)

Parameters
qquaternion (w,x,y,z)
Returns
success

Member Data Documentation

◆ m_values

template<typename Scalar >
Scalar** CCCoreLib::SquareMatrixTpl< Scalar >::m_values = nullptr

The matrix rows.

public for easy/fast access


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