Skip to content

Commit

Permalink
Added get_shape_at_point() for PCA expression models
Browse files Browse the repository at this point in the history
  • Loading branch information
patrikhuber committed Jan 29, 2024
1 parent 61ccbcb commit 3276019
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions include/eos/fitting/ceres_nonlinear.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ Eigen::Vector3<T> get_shape_at_point(const eos::morphablemodel::PcaModel& shape_
Eigen::Map<const Eigen::VectorX<T>> shape_coeffs,
Eigen::Map<const Eigen::VectorX<T>> blendshape_coeffs);

template <typename T>
Eigen::Vector3<T> get_shape_at_point(const eos::morphablemodel::PcaModel& shape_model,
const eos::morphablemodel::PcaModel& expression_model, int vertex_id,
Eigen::Map<const Eigen::VectorX<T>> shape_coeffs,
Eigen::Map<const Eigen::VectorX<T>> expression_coeffs);

template <typename T>
Eigen::Vector3<T> get_vertex_color_at_point(const eos::morphablemodel::PcaModel& color_model, int vertex_id,
Eigen::Map<const Eigen::VectorX<T>> color_coeffs);
Expand Down Expand Up @@ -402,6 +408,41 @@ Eigen::Vector3<T> get_shape_at_point(const eos::morphablemodel::PcaModel& shape_
return Eigen::Vector3<T>(mean.cast<T>() + shape_vector + expression_vector);
};

/**
* Returns the 3D position of a single point of the 3D shape generated by the parameters given.
*
* @param[in] shape_model A PCA 3D shape model.
* @param[in] expression_model A PCA 3D expression model.
* @param[in] vertex_id Vertex id of the 3D model that should be projected.
* @param[in] shape_coeffs A set of PCA shape coefficients used to generate the point.
* @param[in] expression_coeffs A set of expression coefficients used to generate the point.
* @return The 3D point.
*/
template <typename T>
Eigen::Vector3<T> get_shape_at_point(const eos::morphablemodel::PcaModel& shape_model,
const eos::morphablemodel::PcaModel& expression_model, int vertex_id,
Eigen::Map<const Eigen::VectorX<T>> shape_coeffs,
Eigen::Map<const Eigen::VectorX<T>> expression_coeffs)
{
// Computing Shape = shape_mean + shape_basis*shape_coeffs +
// expression_mean + expression_basis*expression_coeffs:
const Eigen::Vector3f shape_mean = shape_model.get_mean_at_point(vertex_id);
const Eigen::Vector3f expression_mean = expression_model.get_mean_at_point(vertex_id);
// Note: We seem to have a dependent name here, so we need 'template', to help the compiler that 'cast<T>'
// is a template.
const Eigen::Vector3<T> shape_vector = shape_model.get_rescaled_pca_basis_at_point(vertex_id)
.leftCols(shape_coeffs.size())
.template cast<T>() *
shape_coeffs;
const Eigen::Vector3<T> expression_vector = expression_model.get_rescaled_pca_basis_at_point(vertex_id)
.leftCols(expression_coeffs.size())
.template cast<T>() *
expression_coeffs;

return Eigen::Vector3<T>(shape_mean.cast<T>() + shape_vector + expression_mean.cast<T>() +
expression_vector);
};

/**
* Returns the colour value of a single point of the 3D model generated by the parameters given.
*
Expand Down

0 comments on commit 3276019

Please sign in to comment.