opensurgsim
Namespaces | Typedefs | Functions
Matrix.h File Reference

Definitions of small fixed-size square matrix types. More...

#include <vector>
#include <Eigen/Core>
#include <Eigen/Geometry>
#include <Eigen/LU>

Go to the source code of this file.

Namespaces

 SurgSim
 Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui needs glew but we need to call glewInit() from a osg callback, using this call we avoid getting warnings about redefinitions.
 

Typedefs

typedef Eigen::Matrix< float, 2, 2, Eigen::RowMajor > SurgSim::Math::Matrix22f
 A 2x2 matrix of floats. More...
 
typedef Eigen::Matrix< float, 3, 3, Eigen::RowMajor > SurgSim::Math::Matrix33f
 A 3x3 matrix of floats. More...
 
typedef Eigen::Matrix< float, 4, 4, Eigen::RowMajor > SurgSim::Math::Matrix44f
 A 4x4 matrix of floats. More...
 
typedef Eigen::Matrix< double, 2, 2, Eigen::RowMajor > SurgSim::Math::Matrix22d
 A 2x2 matrix of doubles. More...
 
typedef Eigen::Matrix< double, 3, 3, Eigen::RowMajor > SurgSim::Math::Matrix33d
 A 3x3 matrix of doubles. More...
 
typedef Eigen::Matrix< double, 4, 4, Eigen::RowMajor > SurgSim::Math::Matrix44d
 A 4x4 matrix of doubles. More...
 
typedef Eigen::Matrix< double, 6, 6, Eigen::RowMajor > SurgSim::Math::Matrix66d
 A 6x6 matrix of doubles. More...
 
typedef Eigen::DiagonalMatrix< double, Eigen::Dynamic > SurgSim::Math::DiagonalMatrix
 A dynamic size diagonal matrix.
 
typedef Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > SurgSim::Math::Matrix
 A dynamic size matrix.
 

Functions

template<typename T , int VOpt>
Eigen::Matrix< T, 3, 3 > SurgSim::Math::makeRotationMatrix (const T &angle, const Eigen::Matrix< T, 3, 1, VOpt > &axis)
 Create a rotation matrix corresponding to the specified angle (in radians) and axis. More...
 
template<typename T , int VOpt>
Eigen::Matrix< T, 3, 3 > SurgSim::Math::makeSkewSymmetricMatrix (const Eigen::Matrix< T, 3, 1, VOpt > &vector)
 Create a skew-symmetric matrix corresponding to the specified vector. More...
 
template<typename T , int MOpt>
Eigen::Matrix< T, 3, 1 > SurgSim::Math::skew (const Eigen::Matrix< T, 3, 3, MOpt > &matrix)
 Extract the unique vector from the skew-symmetric part of a given matrix. More...
 
template<typename T , int MOpt, int VOpt>
void SurgSim::Math::computeAngleAndAxis (const Eigen::Matrix< T, 3, 3, MOpt > &matrix, T *angle, Eigen::Matrix< T, 3, 1, VOpt > *axis)
 Get the angle (in radians) and axis corresponding to a rotation matrix. More...
 
template<typename T , int MOpt>
SurgSim::Math::computeAngle (const Eigen::Matrix< T, 3, 3, MOpt > &matrix)
 Get the angle corresponding to a quaternion's rotation, in radians. More...
 
template<class Matrix , class SubMatrix >
void SurgSim::Math::addSubMatrix (const SubMatrix &subMatrix, size_t blockIdRow, size_t blockIdCol, size_t blockSizeRow, size_t blockSizeCol, Matrix *matrix)
 Helper method to add a sub-matrix into a matrix, for the sake of clarity. More...
 
template<class Matrix , class SubMatrix >
void SurgSim::Math::addSubMatrix (const SubMatrix &subMatrix, const std::vector< size_t > &blockIds, size_t blockSize, Matrix *matrix)
 Helper method to add a sub-matrix made of squared-blocks into a matrix, for the sake of clarity. More...
 
template<class Matrix , class SubMatrix >
void SurgSim::Math::setSubMatrix (const SubMatrix &subMatrix, size_t blockIdRow, size_t blockIdCol, size_t blockSizeRow, size_t blockSizeCol, Matrix *matrix)
 Helper method to set a sub-matrix into a matrix, for the sake of clarity. More...
 
template<class Matrix >
Eigen::Block< Matrix > SurgSim::Math::getSubMatrix (Matrix &matrix, size_t blockIdRow, size_t blockIdCol, size_t blockSizeRow, size_t blockSizeCol)
 Helper method to access a sub-matrix from a matrix, for the sake of clarity. More...
 
template<class Derived >
void SurgSim::Math::zeroRow (size_t row, Eigen::DenseBase< Derived > *matrix)
 Helper method to zero a row of a matrix. More...
 
template<class Derived >
void SurgSim::Math::zeroColumn (size_t column, Eigen::DenseBase< Derived > *matrix)
 Helper method to zero a column of a matrix. More...
 

Detailed Description

Definitions of small fixed-size square matrix types.

Typedef Documentation

§ Matrix22d

typedef Eigen::Matrix<double, 2, 2, Eigen::RowMajor> SurgSim::Math::Matrix22d

A 2x2 matrix of doubles.

This type (and any structs that contain it) can be safely allocated via new.

§ Matrix22f

typedef Eigen::Matrix<float, 2, 2, Eigen::RowMajor> SurgSim::Math::Matrix22f

A 2x2 matrix of floats.

This type (and any structs that contain it) can be safely allocated via new.

§ Matrix33d

typedef Eigen::Matrix<double, 3, 3, Eigen::RowMajor> SurgSim::Math::Matrix33d

A 3x3 matrix of doubles.

This type (and any structs that contain it) can be safely allocated via new.

§ Matrix33f

typedef Eigen::Matrix<float, 3, 3, Eigen::RowMajor> SurgSim::Math::Matrix33f

A 3x3 matrix of floats.

This type (and any structs that contain it) can be safely allocated via new.

§ Matrix44d

typedef Eigen::Matrix<double, 4, 4, Eigen::RowMajor> SurgSim::Math::Matrix44d

A 4x4 matrix of doubles.

This type (and any structs that contain it) can be safely allocated via new.

§ Matrix44f

typedef Eigen::Matrix<float, 4, 4, Eigen::RowMajor> SurgSim::Math::Matrix44f

A 4x4 matrix of floats.

This type (and any structs that contain it) can be safely allocated via new.

§ Matrix66d

typedef Eigen::Matrix<double, 6, 6, Eigen::RowMajor> SurgSim::Math::Matrix66d

A 6x6 matrix of doubles.

This type (and any structs that contain it) can be safely allocated via new.

Function Documentation

§ addSubMatrix() [1/2]

template<class Matrix , class SubMatrix >
void SurgSim::Math::addSubMatrix ( const SubMatrix &  subMatrix,
size_t  blockIdRow,
size_t  blockIdCol,
size_t  blockSizeRow,
size_t  blockSizeCol,
Matrix matrix 
)

Helper method to add a sub-matrix into a matrix, for the sake of clarity.

Template Parameters
MatrixThe matrix type
SubMatrixThe sub-matrix type
Parameters
subMatrixThe sub-matrix
blockIdRow,blockIdColThe block indices in matrix
blockSizeRow,blockSizeColThe block size (size of the sub-matrix)
[out]matrixThe matrix to add the sub-matrix into

§ addSubMatrix() [2/2]

template<class Matrix , class SubMatrix >
void SurgSim::Math::addSubMatrix ( const SubMatrix &  subMatrix,
const std::vector< size_t > &  blockIds,
size_t  blockSize,
Matrix matrix 
)

Helper method to add a sub-matrix made of squared-blocks into a matrix, for the sake of clarity.

Template Parameters
MatrixThe matrix type
SubMatrixThe sub-matrix type
Parameters
subMatrixThe sub-matrix (containing all the squared-blocks)
blockIdsVector of block indices (for accessing matrix) corresponding to the blocks in sub-matrix
blockSizeThe blocks size
[out]matrixThe matrix to add the sub-matrix blocks into

§ computeAngle()

template<typename T , int MOpt>
T SurgSim::Math::computeAngle ( const Eigen::Matrix< T, 3, 3, MOpt > &  matrix)
inline

Get the angle corresponding to a quaternion's rotation, in radians.

If you don't care about the rotation axis, this is more efficient than computeAngleAndAxis().

Template Parameters
Tthe numeric data type used for arguments and the return value. Can usually be deduced.
MOptthe option flags (alignment etc.) used for the rotation matrix argument. Can be deduced.
Parameters
matrixthe rotation matrix to inspect.
Returns
the angle of the rotation, in radians.

§ computeAngleAndAxis()

template<typename T , int MOpt, int VOpt>
void SurgSim::Math::computeAngleAndAxis ( const Eigen::Matrix< T, 3, 3, MOpt > &  matrix,
T *  angle,
Eigen::Matrix< T, 3, 1, VOpt > *  axis 
)
inline

Get the angle (in radians) and axis corresponding to a rotation matrix.

Template Parameters
Tthe numeric data type used for arguments and the return value. Can usually be deduced.
MOptthe option flags (alignment etc.) used for the rotation matrix argument. Can be deduced.
VOptthe option flags (alignment etc.) used for the axis vector argument. Can be deduced.
Parameters
matrixthe rotation matrix to inspect.
[out]anglethe angle of the rotation, in radians.
[out]axisthe axis of the rotation.

§ getSubMatrix()

template<class Matrix >
Eigen::Block<Matrix> SurgSim::Math::getSubMatrix ( Matrix matrix,
size_t  blockIdRow,
size_t  blockIdCol,
size_t  blockSizeRow,
size_t  blockSizeCol 
)

Helper method to access a sub-matrix from a matrix, for the sake of clarity.

Template Parameters
MatrixThe matrix type to get the sub-matrix from
Parameters
matrixThe matrix to get the sub-matrix from
blockIdRow,blockIdColThe block indices
blockSizeRow,blockSizeColThe block size
Returns
The requested sub-matrix
Note
Disable cpplint warnings for use of non-const reference
Eigen has a specific type for Block that we want to return with read/write access
therefore the Matrix from which the Block is built from must not be const

§ makeRotationMatrix()

template<typename T , int VOpt>
Eigen::Matrix<T, 3, 3> SurgSim::Math::makeRotationMatrix ( const T &  angle,
const Eigen::Matrix< T, 3, 1, VOpt > &  axis 
)
inline

Create a rotation matrix corresponding to the specified angle (in radians) and axis.

Template Parameters
Tthe numeric data type used for arguments and the return value. Can usually be deduced.
VOptthe option flags (alignment etc.) used for the axis vector argument. Can be deduced.
Parameters
anglethe angle of the rotation, in radians.
axisthe axis of the rotation.
Returns
the rotation matrix.

§ makeSkewSymmetricMatrix()

template<typename T , int VOpt>
Eigen::Matrix<T, 3, 3> SurgSim::Math::makeSkewSymmetricMatrix ( const Eigen::Matrix< T, 3, 1, VOpt > &  vector)
inline

Create a skew-symmetric matrix corresponding to the specified vector.

Skew-symmetric matrices are particularly useful for representing a portion of the vector cross-product.

Template Parameters
Tthe numeric data type used for arguments and the return value. Can usually be deduced.
VOptthe option flags (alignment etc.) used for the vector argument. Can be deduced.
Parameters
vectorthe vector to be transformed.
Returns
the skew-symmetric matrix corresponding with the vector argument.

§ setSubMatrix()

template<class Matrix , class SubMatrix >
void SurgSim::Math::setSubMatrix ( const SubMatrix &  subMatrix,
size_t  blockIdRow,
size_t  blockIdCol,
size_t  blockSizeRow,
size_t  blockSizeCol,
Matrix matrix 
)

Helper method to set a sub-matrix into a matrix, for the sake of clarity.

Template Parameters
MatrixThe matrix type
SubMatrixThe sub-matrix type
Parameters
subMatrixThe sub-matrix
blockIdRow,blockIdColThe block indices for row and column in matrix
blockSizeRow,blockSizeColThe size of the sub-matrix
[out]matrixThe matrix to set the sub-matrix into

§ skew()

template<typename T , int MOpt>
Eigen::Matrix<T, 3, 1> SurgSim::Math::skew ( const Eigen::Matrix< T, 3, 3, MOpt > &  matrix)
inline

Extract the unique vector from the skew-symmetric part of a given matrix.

Template Parameters
Tthe numeric data type used for arguments and the return value. Can usually be deduced.
MOptthe option flags (alignment etc.) used for the matrix argument. Can be deduced.
Parameters
matrixthe matrix to compute the skew symmetric part from.
Returns
the unique vector defining the skew-symmetric part of the matrix.
Note
For any vector u, skew(makeSkewSymmetricMatrix(u)) = u
In general, returns the vector of the skew symmetric part of matrix: (matrix - matrix^T)/2

§ zeroColumn()

template<class Derived >
void SurgSim::Math::zeroColumn ( size_t  column,
Eigen::DenseBase< Derived > *  matrix 
)

Helper method to zero a column of a matrix.

Template Parameters
MatrixThe matrix type
Parameters
columnThe column to set to zero
[in,out]matrixThe matrix to set the zero column on.

§ zeroRow()

template<class Derived >
void SurgSim::Math::zeroRow ( size_t  row,
Eigen::DenseBase< Derived > *  matrix 
)

Helper method to zero a row of a matrix.

Template Parameters
MatrixThe matrix type
Parameters
rowThe row to set to zero
[in,out]matrixThe matrix to set the zero row on.