Caribou
Public Types | Public Member Functions | List of all members
SofaCaribou::Algebra::EigenMatrix< Derived, Enable > Class Template Reference

Detailed Description

template<typename Derived, typename Enable = void>
class SofaCaribou::Algebra::EigenMatrix< Derived, Enable >

This class can be use to represent any Eigen matrix within SOFA.

It implements (and overloads) the BaseMatrix class of Sofa. This class hence allows to either to create a new Eigen matrix or copy/map an existing one and use it in Sofa's components or visitors.

Note
The wrapper around Eigen sparse matrices has the following exceptions:
  1. Before the matrix is initialized using a series of triplets, accessing an element of the matrix has undefined behavior.

Example:

// Wrapper by copy
using EigenDense = Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic>;
EigenDense m(100,100);
m(30, 30) = 1;
EigenMatrixWrapper<EigenDense> wrapper(m);
std::cout << m(30, 30) == wrapper(30, 30); // TRUE
wrapper(30, 30) = 100;
std::cout << m(30, 30) == wrapper(30, 30); // FALSE

Example:

// Wrapper by reference
using EigenDense = Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic>;
EigenDense m(100,100);
m(30, 30) = 1;
EigenMatrixWrapper<EigenDense &> wrapper(m);x
std::cout << m(30, 30) == wrapper(30, 30); // TRUE
wrapper(30, 30) = 100;
std::cout << m(30, 30) == wrapper(30, 30); // TRUE

#include <EigenMatrix.h>

Inheritance diagram for SofaCaribou::Algebra::EigenMatrix< Derived, Enable >:

Public Types

using EigenType = std::remove_cv_t< std::remove_reference_t< Derived > >
 
using Base = sofa::defaulttype::BaseMatrix
 
using Index = Base::Index
 
using Real = SReal
 

Public Member Functions

 EigenMatrix (std::remove_reference_t< Derived > &eigen_matrix)
 Construct the class using another Eigen matrix. More...
 
 EigenMatrix (Eigen::Index rows, Eigen::Index cols)
 Construct a new rows x cols Eigen matrix of type Derived. More...
 
Index rowSize () const final
 
Index colSize () const final
 
Real element (Index i, Index j) const final
 
void resize (Index nbRow, Index nbCol) final
 Resize the matrix to nbRow x nbCol dimensions. More...
 
void clear () override
 Set all entries to zero. More...
 
void set (Index i, Index j, double v) final
 Set this value of the matrix entry (i, j) to the value of v.
 
void add (Index i, Index j, double v) final
 Adds v to the value of the matrix entry (i, j).
 
void add (Index i, Index j, const sofa::defaulttype::Mat3x3d &m) override
 
void add (Index i, Index j, const sofa::defaulttype::Mat3x3f &m) override
 
void add (Index i, Index j, const sofa::defaulttype::Mat2x2d &m) override
 
void add (Index i, Index j, const sofa::defaulttype::Mat2x2f &m) override
 
void clearRow (Index i) final
 Sets the entire row i to zero.
 
void clearRows (Index imin, Index imax) final
 Sets the rows from index imin to index imax (inclusively) to zero.
 
void clearCol (Index i) final
 Sets the entire columns i to zero.
 
void clearCols (Index imin, Index imax) final
 Sets the columns from index imin to index imax (inclusively) to zero.
 
const EigenType & matrix () const
 Get a const reference to the underlying Eigen matrix

 

Constructor & Destructor Documentation

◆ EigenMatrix() [1/2]

template<typename Derived , typename Enable = void>
SofaCaribou::Algebra::EigenMatrix< Derived, Enable >::EigenMatrix ( std::remove_reference_t< Derived > &  eigen_matrix)
inlineexplicit

Construct the class using another Eigen matrix.

Depending on the template parameter used for the class, this constructor will either create a new Eigen matrix and copy its content from the parameter eigen_matrix, or it will simply store a reference to this external matrix.

Parameters
eigen_matrixThe external matrix

◆ EigenMatrix() [2/2]

template<typename Derived , typename Enable = void>
SofaCaribou::Algebra::EigenMatrix< Derived, Enable >::EigenMatrix ( Eigen::Index  rows,
Eigen::Index  cols 
)
inline

Construct a new rows x cols Eigen matrix of type Derived.

Parameters
rowsNumber of rows.
colsNumber of columns.

Member Function Documentation

◆ clear()

template<typename Derived , typename Enable = void>
void SofaCaribou::Algebra::EigenMatrix< Derived, Enable >::clear ( )
inlineoverride

Set all entries to zero.

Keeps the current matrix dimensions.

◆ resize()

template<typename Derived , typename Enable = void>
void SofaCaribou::Algebra::EigenMatrix< Derived, Enable >::resize ( Index  nbRow,
Index  nbCol 
)
inlinefinal

Resize the matrix to nbRow x nbCol dimensions.

This method resets to zero all entries.


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