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

hpp-fcl 1.7.0 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
20 namespace boost
21 {
22 namespace serialization
23 {
24
25 #ifndef HPP_FCL_SKIP_EIGEN_BOOST_SERIALIZATION
26
27 template <class Archive, typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
28 void save(Archive & ar, const Eigen::Matrix<Scalar,Rows,Cols,Options,MaxRows,MaxCols> & m, const unsigned int /*version*/)
29 {
30 Eigen::DenseIndex rows(m.rows()), cols(m.cols());
31 if (Rows == Eigen::Dynamic)
32 ar & BOOST_SERIALIZATION_NVP(rows);
33 if (Cols == Eigen::Dynamic)
34 ar & BOOST_SERIALIZATION_NVP(cols);
35 ar & make_nvp("data",make_array(m.data(), (size_t)m.size()));
36 }
37
38 template <class Archive, typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
39 void load(Archive & ar, Eigen::Matrix<Scalar,Rows,Cols,Options,MaxRows,MaxCols> & m, const unsigned int /*version*/)
40 {
41 Eigen::DenseIndex rows = Rows, cols = Cols;
42 if (Rows == Eigen::Dynamic)
43 ar >> BOOST_SERIALIZATION_NVP(rows);
44 if (Cols == Eigen::Dynamic)
45 ar >> BOOST_SERIALIZATION_NVP(cols);
46 m.resize(rows,cols);
47 ar >> make_nvp("data",make_array(m.data(), (size_t)m.size()));
48 }
49
50 template <class Archive, typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
51 void serialize(Archive & ar, Eigen::Matrix<Scalar,Rows,Cols,Options,MaxRows,MaxCols> & m, const unsigned int version)
52 {
53 split_free(ar,m,version);
54 }
55
56 template <class Archive, typename PlainObjectBase, int MapOptions, typename StrideType>
57 void save(Archive & ar, const Eigen::Map<PlainObjectBase,MapOptions,StrideType> & m, const unsigned int /*version*/)
58 {
59 Eigen::DenseIndex rows(m.rows()), cols(m.cols());
60 if (PlainObjectBase::RowsAtCompileTime == Eigen::Dynamic)
61 ar & BOOST_SERIALIZATION_NVP(rows);
62 if (PlainObjectBase::ColsAtCompileTime == Eigen::Dynamic)
63 ar & BOOST_SERIALIZATION_NVP(cols);
64 ar & make_nvp("data",make_array(m.data(), (size_t)m.size()));
65 }
66
67 template <class Archive, typename PlainObjectBase, int MapOptions, typename StrideType>
68 void load(Archive & ar, Eigen::Map<PlainObjectBase,MapOptions,StrideType> & m, const unsigned int /*version*/)
69 {
70 Eigen::DenseIndex rows = PlainObjectBase::RowsAtCompileTime, cols = PlainObjectBase::ColsAtCompileTime;
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 m.resize(rows,cols);
76 ar >> make_nvp("data",make_array(m.data(), (size_t)m.size()));
77 }
78
79 template <class Archive, typename PlainObjectBase, int MapOptions, typename StrideType>
80 void serialize(Archive & ar, Eigen::Map<PlainObjectBase,MapOptions,StrideType> & m, const unsigned int version)
81 {
82 split_free(ar,m,version);
83 }
84
85 #endif // ifned HPP_FCL_SKIP_EIGEN_BOOST_SERIALIZATION
86 }
87 }
88
89 #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