Commit 5bdf8846 authored by Joseph Mirabel's avatar Joseph Mirabel
Browse files

Add serialization for LiegroupElement and LiegroupSpace.

parent 0631df57
......@@ -94,6 +94,7 @@ SET(${PROJECT_NAME}_HEADERS
include/hpp/pinocchio/liegroup/cartesian-product.hh
include/hpp/pinocchio/liegroup/special-euclidean.hh
include/hpp/pinocchio/liegroup/special-orthogonal.hh
include/hpp/pinocchio/liegroup/serialization.hh
include/hpp/pinocchio/urdf/util.hh
)
......
......@@ -228,4 +228,15 @@ namespace hpp {
} // namespace pinocchio
} // namespace hpp
namespace boost {
namespace serialization {
template<class Archive>
void load (Archive & ar, hpp::pinocchio::LiegroupElement& c, const unsigned int version);
template<class Archive>
void save (Archive & ar, const hpp::pinocchio::LiegroupElement& c, const unsigned int version);
template<class Archive>
void serialize(Archive & ar, hpp::pinocchio::LiegroupElement& c, const unsigned int file_version);
} // namespace serialization
} // namespace boost
#endif // HPP_PINOCCHIO_LIEGROUP_ELEMENT_HH
......@@ -21,6 +21,7 @@
# include <string>
# include <pinocchio/fwd.hpp>
# include <boost/variant.hpp>
# include <hpp/util/serialization-fwd.hh>
# include <pinocchio/multibody/liegroup/special-euclidean.hpp>
# include <pinocchio/multibody/liegroup/special-orthogonal.hpp>
# include <pinocchio/multibody/liegroup/vector-space.hpp>
......@@ -309,6 +310,8 @@ namespace hpp {
vector_t neutral_;
/// weak pointer to itself
LiegroupSpaceWkPtr_t weak_;
HPP_SERIALIZABLE();
}; // class LiegroupSpace
/// Writing in a stream
inline std::ostream& operator<< (std::ostream& os,
......
// Copyright (c) 2020, Joseph Mirabel
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
//
// This file is part of hpp-pinocchio.
// hpp-pinocchio is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// hpp-pinocchio is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// hpp-pinocchio. If not, see <http://www.gnu.org/licenses/>.
#ifndef HPP_PINOCCHIO_LIEGROUP_SERIALIZATION_HH
#define HPP_PINOCCHIO_LIEGROUP_SERIALIZATION_HH
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/split_free.hpp>
#include <hpp/pinocchio/liegroup.hh>
namespace boost {
namespace serialization {
template<class Archive, int Size, bool rot>
inline void load(Archive & ar,
hpp::pinocchio::liegroup::VectorSpaceOperation<Size,rot>& lg,
const unsigned int version)
{
(void) version;
if (Size == Eigen::Dynamic) {
::pinocchio::Index size;
ar & make_nvp("size", size);
lg = hpp::pinocchio::liegroup::VectorSpaceOperation<Size,rot> (size);
}
}
template<class Archive, int Size, bool rot>
inline void save(Archive & ar,
const hpp::pinocchio::liegroup::VectorSpaceOperation<Size,rot>& lg,
const unsigned int version)
{
(void) version;
if (Size == Eigen::Dynamic) {
::pinocchio::Index size (lg.nq());
ar & make_nvp("size", size);
}
}
template<class Archive, int Size, bool rot>
inline void serialize(Archive & ar,
hpp::pinocchio::liegroup::VectorSpaceOperation<Size,rot>& lg,
const unsigned int version)
{
split_free(ar, lg, version);
}
template<class Archive, typename LieGroup1, typename LieGroup2>
inline void serialize(Archive & ar,
hpp::pinocchio::liegroup::CartesianProductOperation<LieGroup1, LieGroup2>& lg,
const unsigned int version)
{
(void) version;
ar & make_nvp("lg1_", lg.lg1_);
ar & make_nvp("lg2_", lg.lg2_);
}
template<class Archive, int N>
inline void serialize(Archive & ar,
hpp::pinocchio::liegroup::SpecialOrthogonalOperation<N>& lg,
const unsigned int version)
{
(void) ar;
(void) lg;
(void) version;
}
template<class Archive, int N>
inline void serialize(Archive & ar,
hpp::pinocchio::liegroup::SpecialEuclideanOperation<N>& lg,
const unsigned int version)
{
(void) ar;
(void) lg;
(void) version;
}
} // namespace serialization
} // namespace boost
#endif // HPP_PINOCCHIO_LIEGROUP_SERIALIZATION_HH
......@@ -15,6 +15,14 @@
// hpp-pinocchio. If not, see <http://www.gnu.org/licenses/>.
#include <hpp/pinocchio/liegroup-element.hh>
#include <boost/serialization/export.hpp>
#include <boost/serialization/split_free.hpp>
#include <hpp/util/serialization.hh>
#include <pinocchio/serialization/eigen.hpp>
#include "../src/size-visitor.hh"
#include "../src/addition-visitor.hh"
#include "../src/substraction-visitor.hh"
......@@ -105,3 +113,42 @@ namespace hpp {
template vector_t log (const LiegroupElementConstBase<vectorOut_t>& lge);
} // namespace pinocchio
} // namespace hpp
namespace boost {
namespace serialization {
template<class Archive>
void load (Archive & ar, hpp::pinocchio::LiegroupElement& c, const unsigned int version)
{
(void) version;
hpp::pinocchio::LiegroupSpacePtr_t space;
hpp::pinocchio::vector_t vector;
ar & make_nvp("space", space);
ar & make_nvp("vector", vector);
c = hpp::pinocchio::LiegroupElement(vector, space);
}
template<class Archive>
void save (Archive & ar, const hpp::pinocchio::LiegroupElement& c, const unsigned int version)
{
(void) version;
ar & make_nvp("space", c.space());
ar & make_nvp("vector", c.vector());
}
template<class Archive>
void serialize(Archive & ar, hpp::pinocchio::LiegroupElement& c, const unsigned int file_version)
{
split_free(ar, c, file_version);
}
using archive::polymorphic_iarchive;
using archive::polymorphic_oarchive;
template void load <polymorphic_iarchive> (polymorphic_iarchive & ar,
hpp::pinocchio::LiegroupElement& c, const unsigned int version);
template void save <polymorphic_oarchive> (polymorphic_oarchive & ar,
const hpp::pinocchio::LiegroupElement& c, const unsigned int version);
template void serialize <polymorphic_iarchive> (polymorphic_iarchive & ar,
hpp::pinocchio::LiegroupElement& c, const unsigned int version);
template void serialize <polymorphic_oarchive> (polymorphic_oarchive & ar,
hpp::pinocchio::LiegroupElement& c, const unsigned int version);
} // namespace serialization
} // namespace boost
......@@ -14,8 +14,20 @@
// received a copy of the GNU Lesser General Public License along with
// hpp-pinocchio. If not, see <http://www.gnu.org/licenses/>.
#include <hpp/pinocchio/liegroup-element.hh>
#include <hpp/pinocchio/liegroup-space.hh>
#include <boost/serialization/variant.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/export.hpp>
#include <boost/serialization/weak_ptr.hpp>
#include <pinocchio/serialization/eigen.hpp>
#include <hpp/util/serialization.hh>
#include <hpp/pinocchio/liegroup-element.hh>
#include <hpp/pinocchio/liegroup/serialization.hh>
#include "../src/comparison.hh"
#include "../src/size-visitor.hh"
#include "../src/dintegrate-visitor.hh"
......@@ -457,9 +469,24 @@ namespace hpp {
mergeVectorSpaces ();
return weak_.lock();
}
template<class Archive>
void LiegroupSpace::serialize(Archive & ar, const unsigned int version)
{
(void) version;
ar & BOOST_SERIALIZATION_NVP(liegroupTypes_);
ar & BOOST_SERIALIZATION_NVP(nq_);
ar & BOOST_SERIALIZATION_NVP(nv_);
ar & BOOST_SERIALIZATION_NVP(neutral_);
ar & BOOST_SERIALIZATION_NVP(weak_);
}
HPP_SERIALIZATION_IMPLEMENT(LiegroupSpace);
} // namespace pinocchio
} // namespace hpp
BOOST_CLASS_EXPORT(hpp::pinocchio::LiegroupSpace)
namespace boost {
using namespace hpp::pinocchio;
......
......@@ -21,6 +21,10 @@
#include <boost/variant.hpp>
#endif
#include <sstream>
#include <boost/archive/polymorphic_xml_iarchive.hpp>
#include <boost/archive/polymorphic_xml_oarchive.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/assign/list_of.hpp>
#include <hpp/pinocchio/liegroup-element.hh>
......@@ -286,3 +290,24 @@ BOOST_AUTO_TEST_CASE (log_)
BOOST_CHECK ((hpp::pinocchio::log(e).isZero(1e-10)));
}
BOOST_AUTO_TEST_CASE (serialization)
{
LiegroupSpacePtr_t R6xSO3 (LiegroupSpace::R3 () * LiegroupSpace::R3xSO3 ());
LiegroupElement e (R6xSO3); e.setNeutral ();
std::stringstream ss;
{
boost::archive::polymorphic_xml_oarchive oa(ss);
oa << boost::serialization::make_nvp("element", e);
}
LiegroupElement e2;
{
boost::archive::polymorphic_xml_iarchive ia(ss);
ia >> boost::serialization::make_nvp("element", e2);
}
BOOST_CHECK_EQUAL(*e.space(), *e2.space());
BOOST_CHECK(e.vector() == e2.vector());
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment