Loading...
Searching...
No Matches
eigen-matrix.hpp
Go to the documentation of this file.
1// Copyright (c) 2015-2018, CNRS
2// Authors: Justin Carpentier <jcarpent@laas.fr>
3
4/*
5 Code adapted from:
6 https://gist.githubusercontent.com/mtao/5798888/raw/5be9fa9b66336c166dba3a92c0e5b69ffdb81501/eigen_boost_serialization.hpp
7 Copyright (c) 2015 Michael Tao
8
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 */
27
28#ifndef EIGEN_BOOST_SERIALIZATION
29#define EIGEN_BOOST_SERIALIZATION
30
31#ifdef CURVES_WITH_PINOCCHIO_SUPPORT
32#include <pinocchio/config.hpp>
33#if PINOCCHIO_VERSION_AT_LEAST(2, 6, 0)
34#define CURVES_WITH_PINOCCHIO_260
35#endif
36#endif
37
38#ifdef CURVES_WITH_PINOCCHIO_260
39#include <pinocchio/serialization/eigen.hpp>
40#else
41
42#include <Eigen/Dense>
43#include <boost/serialization/split_free.hpp>
44#include <boost/serialization/vector.hpp>
45
46namespace boost {
47namespace serialization {
48template <class Archive, typename _Scalar, int _Rows, int _Cols, int _Options,
49 int _MaxRows, int _MaxCols>
50void save(
51 Archive& ar,
52 const Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& m,
53 const unsigned int) // version
54{
55 Eigen::DenseIndex rows(m.rows()), cols(m.cols());
56 ar& BOOST_SERIALIZATION_NVP(rows);
57 ar& BOOST_SERIALIZATION_NVP(cols);
58 ar& make_nvp("data", make_array(m.data(), (size_t)m.size()));
59}
60
61template <class Archive, typename _Scalar, int _Rows, int _Cols, int _Options,
62 int _MaxRows, int _MaxCols>
63void load(Archive& ar,
64 Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& m,
65 const unsigned int) // version
66{
67 Eigen::DenseIndex rows, cols;
68 ar >> BOOST_SERIALIZATION_NVP(rows);
69 ar >> BOOST_SERIALIZATION_NVP(cols);
70 m.resize(rows, cols);
71 // if(m.size() > 0)
72 ar >> make_nvp("data", make_array(m.data(), (size_t)m.size()));
73}
74
75template <class Archive, typename _Scalar, int _Rows, int _Cols, int _Options,
76 int _MaxRows, int _MaxCols>
78 Archive& ar,
79 Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& m,
80 const unsigned int version) {
81 split_free(ar, m, version);
82}
83} // namespace serialization
84} // namespace boost
85
86#endif
87
88#undef CURVES_WITH_PINOCCHIO_260
89
90#endif // ifndef __multicontact_api_serialization_eigen_matrix_hpp__
void load(Archive &ar, Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &m, const unsigned int)
Definition eigen-matrix.hpp:63
void save(Archive &ar, const Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &m, const unsigned int)
Definition eigen-matrix.hpp:50
void serialize(Archive &ar, Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &m, const unsigned int version)
Definition eigen-matrix.hpp:77
Definition eigen-matrix.hpp:46