eos 1.4.0
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
eos::morphablemodel::PcaModel Class Reference

This class represents a PCA-model that consists of: More...

#include <PcaModel.hpp>

Public Member Functions

 PcaModel (Eigen::VectorXf mean, Eigen::MatrixXf orthonormal_pca_basis, Eigen::VectorXf eigenvalues, std::vector< std::array< int, 3 > > triangle_list)
 
int get_num_principal_components () const
 
int get_data_dimension () const
 
const std::vector< std::array< int, 3 > > & get_triangle_list () const
 
const Eigen::VectorXf & get_mean () const
 
Eigen::Vector3f get_mean_at_point (int vertex_index) const
 
template<class RNG >
Eigen::VectorXf draw_sample (RNG &engine, float sigma=1.0f) const
 
Eigen::VectorXf draw_sample (std::vector< float > coefficients) const
 
Eigen::VectorXf draw_sample (std::vector< double > coefficients) const
 
const Eigen::MatrixXf & get_rescaled_pca_basis () const
 
Eigen::MatrixXf get_rescaled_pca_basis_at_point (int vertex_id) const
 
const Eigen::MatrixXf & get_orthonormal_pca_basis () const
 
Eigen::MatrixXf get_orthonormal_pca_basis_at_point (int vertex_id) const
 
const Eigen::VectorXf & get_eigenvalues () const
 
float get_eigenvalue (int index) const
 
std::vector< float > project (const Eigen::VectorXf &instance) const
 

Friends

class cereal::access
 

Detailed Description

This class represents a PCA-model that consists of:

It also contains a list of triangles to built a mesh as well as a mapping from landmark points to the corresponding vertex-id in the mesh.

Constructor & Destructor Documentation

◆ PcaModel()

eos::morphablemodel::PcaModel::PcaModel ( Eigen::VectorXf  mean,
Eigen::MatrixXf  orthonormal_pca_basis,
Eigen::VectorXf  eigenvalues,
std::vector< std::array< int, 3 > >  triangle_list 
)
inline

Construct a PCA model from given mean, normalised PCA basis, eigenvalues and triangle list.

See the documentation of the member variables for how the data should be arranged.

Parameters
[in]meanThe mean used to build the PCA model.
[in]orthonormal_pca_basisAn orthonormal PCA basis (eigenvectors).
[in]eigenvaluesThe eigenvalues used to build the PCA model.
[in]triangle_listAn index list of how to assemble the mesh.

Member Function Documentation

◆ draw_sample() [1/3]

template<class RNG >
Eigen::VectorXf eos::morphablemodel::PcaModel::draw_sample ( RNG &  engine,
float  sigma = 1.0f 
) const
inline

Draws a random sample from the model, where the coefficients are drawn from a standard normal (or with the given standard deviation).

Parameters
[in]engineRandom number engine used to draw random coefficients.
[in]sigmaThe standard deviation.
Returns
A random sample from the model.

◆ draw_sample() [2/3]

Eigen::VectorXf eos::morphablemodel::PcaModel::draw_sample ( std::vector< double >  coefficients) const
inline

Returns a sample from the model with the given PCA coefficients. The given coefficients should follow a standard normal distribution, i.e. not be "normalised" with their eigenvalues/variances.

Parameters
[in]coefficientsThe PCA coefficients used to generate the sample.
Returns
A model instance with given coefficients.

◆ draw_sample() [3/3]

Eigen::VectorXf eos::morphablemodel::PcaModel::draw_sample ( std::vector< float >  coefficients) const
inline

Returns a sample from the model with the given PCA coefficients. The given coefficients should follow a standard normal distribution, i.e. not be "normalised" with their eigenvalues/variances.

Parameters
[in]coefficientsThe PCA coefficients used to generate the sample.
Returns
A model instance with given coefficients.

◆ get_data_dimension()

int eos::morphablemodel::PcaModel::get_data_dimension ( ) const
inline

Returns the dimension of the data, i.e. the number of shape dimensions.

As the data is arranged in a [x y z x y z ...] fashion, dividing this by three yields the number of vertices in the model.

Returns
The dimension of the data.

◆ get_eigenvalue()

float eos::morphablemodel::PcaModel::get_eigenvalue ( int  index) const
inline

Returns a specific eigenvalue.

Parameters
[in]indexThe index of the eigenvalue to return.
Returns
The eigenvalue.

◆ get_eigenvalues()

const Eigen::VectorXf & eos::morphablemodel::PcaModel::get_eigenvalues ( ) const
inline

Returns the models eigenvalues.

Returns
The eigenvalues.

◆ get_mean()

const Eigen::VectorXf & eos::morphablemodel::PcaModel::get_mean ( ) const
inline

Returns the mean of the model.

Returns
The mean of the model.

◆ get_mean_at_point()

Eigen::Vector3f eos::morphablemodel::PcaModel::get_mean_at_point ( int  vertex_index) const
inline

Return the value of the mean at a given vertex index.

Parameters
[in]vertex_indexA vertex index.
Returns
A 3-dimensional vector containing the values at the given vertex index.

◆ get_num_principal_components()

int eos::morphablemodel::PcaModel::get_num_principal_components ( ) const
inline

Returns the number of principal components in the model.

Returns
The number of principal components in the model.

◆ get_orthonormal_pca_basis()

const Eigen::MatrixXf & eos::morphablemodel::PcaModel::get_orthonormal_pca_basis ( ) const
inline

Returns the PCA basis matrix, i.e. the eigenvectors. Each column of the matrix is an eigenvector. The returned basis is orthonormal, i.e. the eigenvectors are not scaled by their respective eigenvalues.

Returns
Returns the orthonormal PCA basis matrix.

◆ get_orthonormal_pca_basis_at_point()

Eigen::MatrixXf eos::morphablemodel::PcaModel::get_orthonormal_pca_basis_at_point ( int  vertex_id) const
inline

Returns the PCA basis for a particular vertex, from the orthonormal basis.

Note: The function does not return the i-th basis vector - it returns all basis vectors, but only the block that is relevant for the vertex vertex_id.

Parameters
[in]vertex_idA vertex index. Make sure it is valid.
Returns
A 3 x num_principal_components matrix of the relevant rows of the original basis.

◆ get_rescaled_pca_basis()

const Eigen::MatrixXf & eos::morphablemodel::PcaModel::get_rescaled_pca_basis ( ) const
inline

Returns the PCA basis matrix, i.e. the eigenvectors. Each column of the matrix is an eigenvector. The returned basis is rescaled, i.e. every eigenvector is rescaled by multiplying it with the square root of its eigenvalue.

Returns
Returns the rescaled PCA basis matrix.

◆ get_rescaled_pca_basis_at_point()

Eigen::MatrixXf eos::morphablemodel::PcaModel::get_rescaled_pca_basis_at_point ( int  vertex_id) const
inline

Returns the PCA basis for a particular vertex, from the rescaled basis.

Note: The function does not return the i-th basis vector - it returns all basis vectors, but only the block that is relevant for the vertex vertex_id.

Todo: Can we return a const & view that points into the original data? I think it's not that easy - if we return e.g. "const auto&", then the compiler complains about returning a reference to a temporary. This will probably help: https://eigen.tuxfamily.org/dox/classEigen_1_1Block.html

Parameters
[in]vertex_idA vertex index. Make sure it is valid.
Returns
A 3 x num_principal_components matrix of the relevant rows of the original basis.

◆ get_triangle_list()

const std::vector< std::array< int, 3 > > & eos::morphablemodel::PcaModel::get_triangle_list ( ) const
inline

Returns a list of triangles on how to assemble the vertices into a mesh.

Returns
The list of triangles to build a mesh.

◆ project()

std::vector< float > eos::morphablemodel::PcaModel::project ( const Eigen::VectorXf &  instance) const
inline

Projects the given data instance into the model space, and returns the PCA coefficients.

Parameters
[in]instanceA 3m x 1 col-vector (xyzxyz...)', where m is the number of model-vertices.
Returns
The PCA coefficients of the projected data.

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