coal/serialization/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 COAL_SERIALIZATION_EIGEN_H
12 #define COAL_SERIALIZATION_EIGEN_H
13 
14 #ifdef COAL_BACKWARD_COMPATIBILITY_WITH_HPP_FCL
15 #ifdef HPP_FCL_SKIP_EIGEN_BOOST_SERIALIZATION
16 #define COAL_SKIP_EIGEN_BOOST_SERIALIZATION
17 #endif
18 #endif
19 
20 #ifndef COAL_SKIP_EIGEN_BOOST_SERIALIZATION
21 
22 #include <Eigen/Dense>
23 
24 #include <boost/serialization/split_free.hpp>
25 #include <boost/serialization/vector.hpp>
26 #include <boost/serialization/array.hpp>
27 
28 // Workaround a bug in GCC >= 7 and C++17
29 // ref. https://gitlab.com/libeigen/eigen/-/issues/1676
30 #ifdef __GNUC__
31 #if __GNUC__ >= 7 && __cplusplus >= 201703L
32 namespace boost {
33 namespace serialization {
34 struct U;
35 }
36 } // namespace boost
37 namespace Eigen {
38 namespace internal {
39 template <>
40 struct traits<boost::serialization::U> {
41  enum { Flags = 0 };
42 };
43 } // namespace internal
44 } // namespace Eigen
45 #endif
46 #endif
47 
48 namespace boost {
49 namespace serialization {
50 
51 template <class Archive, typename S, int Rows, int Cols, int Options,
52  int MaxRows, int MaxCols>
53 void save(Archive& ar,
54  const Eigen::Matrix<S, Rows, Cols, Options, MaxRows, MaxCols>& m,
55  const unsigned int /*version*/) {
56  Eigen::DenseIndex rows(m.rows()), cols(m.cols());
57  if (Rows == Eigen::Dynamic) ar& BOOST_SERIALIZATION_NVP(rows);
58  if (Cols == Eigen::Dynamic) ar& BOOST_SERIALIZATION_NVP(cols);
59  ar& make_nvp("data", make_array(m.data(), (size_t)m.size()));
60 }
61 
62 template <class Archive, typename S, int Rows, int Cols, int Options,
63  int MaxRows, int MaxCols>
64 void load(Archive& ar,
65  Eigen::Matrix<S, Rows, Cols, Options, MaxRows, MaxCols>& m,
66  const unsigned int /*version*/) {
67  Eigen::DenseIndex rows = Rows, cols = Cols;
68  if (Rows == Eigen::Dynamic) ar >> BOOST_SERIALIZATION_NVP(rows);
69  if (Cols == Eigen::Dynamic) ar >> BOOST_SERIALIZATION_NVP(cols);
70  m.resize(rows, cols);
71  ar >> make_nvp("data", make_array(m.data(), (size_t)m.size()));
72 }
73 
74 template <class Archive, typename S, int Rows, int Cols, int Options,
75  int MaxRows, int MaxCols>
76 void serialize(Archive& ar,
77  Eigen::Matrix<S, Rows, Cols, Options, MaxRows, MaxCols>& m,
78  const unsigned int version) {
79  split_free(ar, m, version);
80 }
81 
82 template <class Archive, typename PlainObjectBase, int MapOptions,
83  typename StrideType>
84 void save(Archive& ar,
85  const Eigen::Map<PlainObjectBase, MapOptions, StrideType>& m,
86  const unsigned int /*version*/) {
87  Eigen::DenseIndex rows(m.rows()), cols(m.cols());
88  if (PlainObjectBase::RowsAtCompileTime == Eigen::Dynamic)
89  ar& BOOST_SERIALIZATION_NVP(rows);
90  if (PlainObjectBase::ColsAtCompileTime == Eigen::Dynamic)
91  ar& BOOST_SERIALIZATION_NVP(cols);
92  ar& make_nvp("data", make_array(m.data(), (size_t)m.size()));
93 }
94 
95 template <class Archive, typename PlainObjectBase, int MapOptions,
96  typename StrideType>
97 void load(Archive& ar, Eigen::Map<PlainObjectBase, MapOptions, StrideType>& m,
98  const unsigned int /*version*/) {
99  Eigen::DenseIndex rows = PlainObjectBase::RowsAtCompileTime,
100  cols = PlainObjectBase::ColsAtCompileTime;
101  if (PlainObjectBase::RowsAtCompileTime == Eigen::Dynamic)
102  ar >> BOOST_SERIALIZATION_NVP(rows);
103  if (PlainObjectBase::ColsAtCompileTime == Eigen::Dynamic)
104  ar >> BOOST_SERIALIZATION_NVP(cols);
105  m.resize(rows, cols);
106  ar >> make_nvp("data", make_array(m.data(), (size_t)m.size()));
107 }
108 
109 template <class Archive, typename PlainObjectBase, int MapOptions,
110  typename StrideType>
111 void serialize(Archive& ar,
112  Eigen::Map<PlainObjectBase, MapOptions, StrideType>& m,
113  const unsigned int version) {
114  split_free(ar, m, version);
115 }
116 
117 } // namespace serialization
118 } // namespace boost
119 //
120 #endif // ifned COAL_SKIP_EIGEN_BOOST_SERIALIZATION
121 
122 #endif // ifndef COAL_SERIALIZATION_EIGEN_H
U
U
generate_distance_plot.m
float m
Definition: generate_distance_plot.py:6
boost::serialization::load
void load(Archive &ar, coal::BVSplitter< BV > &splitter_, const unsigned int)
Definition: coal/serialization/BV_splitter.h:44
Eigen
boost::serialization::serialize
void serialize(Archive &ar, coal::AABB &aabb, const unsigned int)
Definition: coal/serialization/AABB.h:15
rows
int rows
boost
version
version
traits
Definition: benchmark.cpp:54
boost::serialization::save
void save(Archive &ar, const coal::BVSplitter< BV > &splitter_, const unsigned int)
Definition: coal/serialization/BV_splitter.h:30
cols
int cols


hpp-fcl
Author(s):
autogenerated on Sat Nov 23 2024 03:44:58