eos 1.4.0
Loading...
Searching...
No Matches
coefficients.hpp
1/*
2 * eos - A 3D Morphable Model fitting library written in modern C++11/14.
3 *
4 * File: include/eos/morphablemodel/coefficients.hpp
5 *
6 * Copyright 2016 Patrik Huber
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20#pragma once
21
22#ifndef EOS_COEFFICIENTS_HPP
23#define EOS_COEFFICIENTS_HPP
24
25#include "cereal/cereal.hpp"
26#include "cereal/archives/json.hpp"
27
28#include <string>
29#include <vector>
30#include <fstream>
31
32namespace eos {
33namespace morphablemodel {
34
42inline void save_coefficients(std::vector<float> coefficients, std::string filename)
43{
44 std::ofstream file(filename);
45 if (!file)
46 {
47 throw std::runtime_error("Error opening file for writing: " + filename);
48 }
49 cereal::JSONOutputArchive output_archive(file);
50 output_archive(cereal::make_nvp("shape_coefficients", coefficients));
51};
52
60inline std::vector<float> load_coefficients(std::string filename)
61{
62 std::vector<float> coefficients;
63 std::ifstream file(filename);
64 if (!file)
65 {
66 throw std::runtime_error("Error opening file for reading: " + filename);
67 }
68 cereal::JSONInputArchive input_archive(file);
69 input_archive(cereal::make_nvp("shape_coefficients", coefficients));
70 return coefficients;
71};
72
73} /* namespace morphablemodel */
74} /* namespace eos */
75
76#endif /* EOS_COEFFICIENTS_HPP */
void save_coefficients(std::vector< float > coefficients, std::string filename)
Definition: coefficients.hpp:42
std::vector< float > load_coefficients(std::string filename)
Definition: coefficients.hpp:60
Namespace containing all of eos's 3D model fitting functionality.