eigen.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2017-2021 CNRS INRIA
3 //
4 
5 /*
6  Code adapted from Pinocchio and
7  https://gist.githubusercontent.com/mtao/5798888/raw/5be9fa9b66336c166dba3a92c0e5b69ffdb81501/eigen_boost_serialization.hpp
8  Copyright (c) 2015 Michael Tao
9 */
10 
11 #ifndef HPP_FCL_SERIALIZATION_EIGEN_H
12 #define HPP_FCL_SERIALIZATION_EIGEN_H
13 
14 #include <Eigen/Dense>
15 
16 #include <boost/serialization/split_free.hpp>
17 #include <boost/serialization/vector.hpp>
18 #include <boost/serialization/array.hpp>
19 
20 // Workaround a bug in GCC >= 7 and C++17
21 // ref. https://gitlab.com/libeigen/eigen/-/issues/1676
22 #ifdef __GNUC__
23 #if __GNUC__ >= 7 && __cplusplus >= 201703L
24 namespace boost {
25 namespace serialization {
26 struct U;
27 }
28 } // namespace boost
29 namespace Eigen {
30 namespace internal {
31 template <>
32 struct traits<boost::serialization::U> {
33  enum { Flags = 0 };
34 };
35 } // namespace internal
36 } // namespace Eigen
37 #endif
38 #endif
39 
40 namespace boost {
41 namespace serialization {
42 
43 #ifndef HPP_FCL_SKIP_EIGEN_BOOST_SERIALIZATION
44 
45 template <class Archive, typename Scalar, int Rows, int Cols, int Options,
46  int MaxRows, int MaxCols>
47 void save(Archive& ar,
48  const Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>& m,
49  const unsigned int /*version*/) {
50  Eigen::DenseIndex rows(m.rows()), cols(m.cols());
51  if (Rows == Eigen::Dynamic) ar& BOOST_SERIALIZATION_NVP(rows);
52  if (Cols == Eigen::Dynamic) ar& BOOST_SERIALIZATION_NVP(cols);
53  ar& make_nvp("data", make_array(m.data(), (size_t)m.size()));
54 }
55 
56 template <class Archive, typename Scalar, int Rows, int Cols, int Options,
57  int MaxRows, int MaxCols>
58 void load(Archive& ar,
59  Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>& m,
60  const unsigned int /*version*/) {
61  Eigen::DenseIndex rows = Rows, cols = Cols;
62  if (Rows == Eigen::Dynamic) ar >> BOOST_SERIALIZATION_NVP(rows);
63  if (Cols == Eigen::Dynamic) ar >> BOOST_SERIALIZATION_NVP(cols);
64  m.resize(rows, cols);
65  ar >> make_nvp("data", make_array(m.data(), (size_t)m.size()));
66 }
67 
68 template <class Archive, typename Scalar, int Rows, int Cols, int Options,
69  int MaxRows, int MaxCols>
70 void serialize(Archive& ar,
71  Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>& m,
72  const unsigned int version) {
73  split_free(ar, m, version);
74 }
75 
76 template <class Archive, typename PlainObjectBase, int MapOptions,
77  typename StrideType>
78 void save(Archive& ar,
79  const Eigen::Map<PlainObjectBase, MapOptions, StrideType>& m,
80  const unsigned int /*version*/) {
81  Eigen::DenseIndex rows(m.rows()), cols(m.cols());
82  if (PlainObjectBase::RowsAtCompileTime == Eigen::Dynamic)
83  ar& BOOST_SERIALIZATION_NVP(rows);
84  if (PlainObjectBase::ColsAtCompileTime == Eigen::Dynamic)
85  ar& BOOST_SERIALIZATION_NVP(cols);
86  ar& make_nvp("data", make_array(m.data(), (size_t)m.size()));
87 }
88 
89 template <class Archive, typename PlainObjectBase, int MapOptions,
90  typename StrideType>
91 void load(Archive& ar, Eigen::Map<PlainObjectBase, MapOptions, StrideType>& m,
92  const unsigned int /*version*/) {
93  Eigen::DenseIndex rows = PlainObjectBase::RowsAtCompileTime,
94  cols = PlainObjectBase::ColsAtCompileTime;
95  if (PlainObjectBase::RowsAtCompileTime == Eigen::Dynamic)
96  ar >> BOOST_SERIALIZATION_NVP(rows);
97  if (PlainObjectBase::ColsAtCompileTime == Eigen::Dynamic)
98  ar >> BOOST_SERIALIZATION_NVP(cols);
99  m.resize(rows, cols);
100  ar >> make_nvp("data", make_array(m.data(), (size_t)m.size()));
101 }
102 
103 template <class Archive, typename PlainObjectBase, int MapOptions,
104  typename StrideType>
105 void serialize(Archive& ar,
106  Eigen::Map<PlainObjectBase, MapOptions, StrideType>& m,
107  const unsigned int version) {
108  split_free(ar, m, version);
109 }
110 
111 #endif // ifned HPP_FCL_SKIP_EIGEN_BOOST_SERIALIZATION
112 } // namespace serialization
113 } // namespace boost
114 
115 #endif // ifndef HPP_FCL_SERIALIZATION_EIGEN_H
int rows
void serialize(Archive &ar, hpp::fcl::AABB &aabb, const unsigned int)
void save(Archive &ar, const hpp::fcl::BVSplitter< BV > &splitter_, const unsigned int)
int cols
void load(Archive &ar, hpp::fcl::BVSplitter< BV > &splitter_, const unsigned int)


hpp-fcl
Author(s):
autogenerated on Fri Jun 2 2023 02:39:01