eos 1.4.0
Loading...
Searching...
No Matches
eigen_cerealisation.hpp
1/*
2 * eos - A 3D Morphable Model fitting library written in modern C++11/14.
3 *
4 * File: include/eos/morphablemodel/io/eigen_cerealisation.hpp
5 *
6 * Copyright 2017 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_EIGEN_MATRIX_BINARY_CEREALISATION_HPP
23#define EOS_EIGEN_MATRIX_BINARY_CEREALISATION_HPP
24
25#include "cereal/cereal.hpp"
26
27#include "Eigen/Core"
28
29#include <cstdint>
30
41namespace cereal {
42
52template <class Archive, class _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
53inline
54typename std::enable_if<traits::is_output_serializable<BinaryData<_Scalar>, Archive>::value, void>::type
55save(Archive& ar, const Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& matrix)
56{
57 const std::int32_t rows = static_cast<std::int32_t>(matrix.rows());
58 const std::int32_t cols = static_cast<std::int32_t>(matrix.cols());
59 ar(rows);
60 ar(cols);
61 ar(binary_data(matrix.data(), rows * cols * sizeof(_Scalar)));
62};
63
72template <class Archive, class _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
73inline
74typename std::enable_if<traits::is_input_serializable<BinaryData<_Scalar>, Archive>::value, void>::type
75load(Archive& ar, Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& matrix)
76{
77 std::int32_t rows;
78 std::int32_t cols;
79 ar(rows);
80 ar(cols);
81
82 matrix.resize(rows, cols);
83
84 ar(binary_data(matrix.data(), static_cast<std::size_t>(rows * cols * sizeof(_Scalar))));
85};
86
87} /* namespace cereal */
88
89#endif /* EOS_EIGEN_MATRIX_BINARY_CEREALISATION_HPP */
Serialisation of Eigen matrices for the serialisation library cereal (http://uscilab....
Definition: eigen_cerealisation.hpp:41
std::enable_if< traits::is_input_serializable< BinaryData< _Scalar >, Archive >::value, void >::type load(Archive &ar, Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &matrix)
De-serialise an Eigen::Matrix using cereal.
Definition: eigen_cerealisation.hpp:75
std::enable_if< traits::is_output_serializable< BinaryData< _Scalar >, Archive >::value, void >::type save(Archive &ar, const Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &matrix)
Serialise an Eigen::Matrix using cereal.
Definition: eigen_cerealisation.hpp:55