diff --git a/include/eos/fitting/ceres_nonlinear.hpp b/include/eos/fitting/ceres_nonlinear.hpp index c4c03cd7..465e8cda 100644 --- a/include/eos/fitting/ceres_nonlinear.hpp +++ b/include/eos/fitting/ceres_nonlinear.hpp @@ -373,6 +373,30 @@ struct VertexColorCost const eos::core::Image3u& image; // the observed image }; +/** + * 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] 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. + * @return The 3D point. + */ +template +Eigen::Vector3 get_shape_at_point(const eos::morphablemodel::PcaModel& shape_model, int vertex_id, + Eigen::Map> shape_coeffs) +{ + // Computing Shape = shape_mean + shape_basis*shape_coeffs: + const Eigen::Vector3f shape_mean = shape_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' + // is a template. + const Eigen::Vector3 shape_vector = shape_model.get_rescaled_pca_basis_at_point(vertex_id) + .leftCols(shape_coeffs.size()) + .template cast() * + shape_coeffs; + + return Eigen::Vector3(shape_mean.cast() + shape_vector); +}; + /** * Returns the 3D position of a single point of the 3D shape generated by the parameters given. *