Commit eaa69bb0 authored by Philipp Kopp's avatar Philipp Kopp

Merge branch 'devel' into multi_image_fit_devel

parents 47fb4148 7b77b8e0
......@@ -26,9 +26,10 @@
#include "eos/core/Mesh.hpp"
#include "eos/morphablemodel/io/mat_cerealisation.hpp"
#include "eos/morphablemodel/io/eigen_cerealisation.hpp"
#include "cereal/cereal.hpp"
#include "cereal/access.hpp"
#include "cereal/types/array.hpp"
#include "cereal/types/vector.hpp"
#include "cereal/archives/binary.hpp"
......@@ -41,6 +42,7 @@
#include <vector>
#include <array>
#include <cstdint>
#include <fstream>
namespace eos {
namespace morphablemodel {
......
......@@ -26,6 +26,7 @@
#include "cereal/access.hpp"
#include "cereal/types/array.hpp"
#include "cereal/types/vector.hpp"
#include "cereal/archives/binary.hpp"
#include "Eigen/Core"
......@@ -34,6 +35,7 @@
#include <array>
#include <random>
#include <cassert>
#include <fstream>
namespace eos {
namespace morphablemodel {
......@@ -57,7 +59,7 @@ public:
PcaModel() = default;
/**
* Construct a PCA model from given mean, normalised PCA basis, eigenvalues
* Construct a PCA model from given mean, orthonormal PCA basis, eigenvalues
* and triangle list.
*
* See the documentation of the member variables for how the data should
......@@ -292,6 +294,45 @@ private:
};
};
/**
* Helper method to load a PCA model from
* a cereal::BinaryInputArchive from the harddisk.
*
* Usually, morphablemodel::load_model(std::string) should be used to directly
* load a MorphableModel. This function can be useful when it is necessary to just
* load a PCA model.
*
* @param[in] filename Filename to a model.
* @return The loaded PCA model.
* @throw std::runtime_error When the file given in \c filename fails to be opened (most likely because the file doesn't exist).
*/
inline PcaModel load_pca_model(std::string filename)
{
PcaModel model;
std::ifstream file(filename, std::ios::binary);
if (file.fail()) {
throw std::runtime_error("Error opening given file: " + filename);
}
cereal::BinaryInputArchive input_archive(file);
input_archive(model);
return model;
};
/**
* Helper method to save a PCA model to the
* harddrive as cereal::BinaryOutputArchive.
*
* @param[in] model The model to be saved.
* @param[in] filename Filename for the model.
*/
inline void save_pca_model(PcaModel model, std::string filename)
{
std::ofstream file(filename, std::ios::binary);
cereal::BinaryOutputArchive output_archive(file);
output_archive(model);
};
/**
* Takes an orthonormal PCA basis matrix (a matrix consisting
......
......@@ -81,8 +81,8 @@ PYBIND11_PLUGIN(eos) {
* Bindings for the eos::morphablemodel namespace:
* - PcaModel
* - MorphableModel
* - load_model()
* - save_model()
* - load_model(), save_model()
* - load_pca_model(), save_pca_model()
*/
py::module morphablemodel_module = eos_module.def_submodule("morphablemodel", "Functionality to represent a Morphable Model, its PCA models, and functions to load models and blendshapes.");
......@@ -107,10 +107,13 @@ PYBIND11_PLUGIN(eos) {
.def("get_mean", &morphablemodel::MorphableModel::get_mean, "Returns the mean of the shape- and colour model as a Mesh.")
.def("draw_sample", (core::Mesh(morphablemodel::MorphableModel::*)(std::vector<float>, std::vector<float>) const)&morphablemodel::MorphableModel::draw_sample, "Returns a sample from the model with the given shape- and colour PCA coefficients.", py::arg("shape_coefficients"), py::arg("color_coefficients"))
.def("has_color_model", &morphablemodel::MorphableModel::has_color_model, "Returns true if this Morphable Model contains a colour model, and false if it is a shape-only model.")
.def("get_texture_coordinates", &morphablemodel::MorphableModel::get_texture_coordinates, "Returns the texture coordinates for all the vertices in the model.")
;
morphablemodel_module.def("load_model", &morphablemodel::load_model, "Load a Morphable Model from a cereal::BinaryInputArchive (.bin) from the harddisk.", py::arg("filename"));
morphablemodel_module.def("save_model", &morphablemodel::save_model, "Save a Morphable Model as cereal::BinaryOutputArchive.", py::arg("model"), py::arg("filename"));
morphablemodel_module.def("load_pca_model", &morphablemodel::load_pca_model, "Load a PCA model from a cereal::BinaryInputArchive (.bin) from the harddisk.", py::arg("filename"));
morphablemodel_module.def("save_pca_model", &morphablemodel::save_pca_model, "Save a PCA model as cereal::BinaryOutputArchive.", py::arg("model"), py::arg("filename"));
/**
* - Blendshape
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment