hpp-fcl: include/hpp/fcl/serialization/eigen.h Source File

hpp-fcl 1.7.5 HPP fork of FCL -- The Flexible Collision Library

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