Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Humanoid Path Planner
hpp-pinocchio
Commits
d2ce34b8
Commit
d2ce34b8
authored
May 12, 2020
by
Joseph Mirabel
Browse files
Add missing hpp/pinocchio/serialization.hh + test array serialization.
parent
7d67bfa8
Changes
3
Hide whitespace changes
Inline
Side-by-side
include/hpp/pinocchio/serialization.hh
0 → 100644
View file @
d2ce34b8
//
// Copyright (c) 2020 CNRS
// Author: Joseph Mirabel
//
// 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_SERIALIZATION_HH
# define HPP_PINOCCHIO_SERIALIZATION_HH
# include <boost/serialization/split_free.hpp>
# include <boost/serialization/shared_ptr.hpp>
# include <boost/serialization/weak_ptr.hpp>
# include <hpp/pinocchio/fwd.hh>
namespace
hpp
{
namespace
serialization
{
struct
archive_device_wrapper
{
pinocchio
::
DevicePtr_t
device
;
virtual
~
archive_device_wrapper
()
{}
};
}
// namespace pinocchio
}
// namespace hpp
BOOST_SERIALIZATION_SPLIT_FREE
(
hpp
::
pinocchio
::
DevicePtr_t
)
BOOST_SERIALIZATION_SPLIT_FREE
(
hpp
::
pinocchio
::
DeviceWkPtr_t
)
namespace
boost
{
namespace
serialization
{
template
<
class
Archive
>
inline
void
load
(
Archive
&
ar
,
hpp
::
pinocchio
::
DevicePtr_t
&
d
,
const
unsigned
int
version
)
{
load
<
Archive
,
hpp
::
pinocchio
::
Device
>
(
ar
,
d
,
version
);
using
hpp
::
serialization
::
archive_device_wrapper
;
archive_device_wrapper
*
adw
=
dynamic_cast
<
archive_device_wrapper
*>
(
&
ar
);
if
(
adw
)
d
=
adw
->
device
;
}
template
<
class
Archive
>
inline
void
load
(
Archive
&
ar
,
hpp
::
pinocchio
::
DeviceWkPtr_t
&
d
,
const
unsigned
int
version
)
{
load
<
Archive
,
hpp
::
pinocchio
::
Device
>
(
ar
,
d
,
version
);
using
hpp
::
serialization
::
archive_device_wrapper
;
archive_device_wrapper
*
adw
=
dynamic_cast
<
archive_device_wrapper
*>
(
&
ar
);
if
(
adw
)
d
=
adw
->
device
;
}
template
<
class
Archive
>
inline
void
load
(
Archive
&
ar
,
hpp
::
pinocchio
::
HumanoidRobotPtr_t
&
d
,
const
unsigned
int
version
)
{
load
<
Archive
,
hpp
::
pinocchio
::
HumanoidRobot
>
(
ar
,
d
,
version
);
using
hpp
::
serialization
::
archive_device_wrapper
;
archive_device_wrapper
*
adw
=
dynamic_cast
<
archive_device_wrapper
*>
(
&
ar
);
if
(
adw
)
d
=
boost
::
dynamic_pointer_cast
<
hpp
::
pinocchio
::
HumanoidRobot
>
(
adw
->
device
);
}
template
<
class
Archive
>
inline
void
load
(
Archive
&
ar
,
hpp
::
pinocchio
::
HumanoidRobotWkPtr_t
&
d
,
const
unsigned
int
version
)
{
load
<
Archive
,
hpp
::
pinocchio
::
HumanoidRobot
>
(
ar
,
d
,
version
);
using
hpp
::
serialization
::
archive_device_wrapper
;
archive_device_wrapper
*
adw
=
dynamic_cast
<
archive_device_wrapper
*>
(
&
ar
);
if
(
adw
)
d
=
boost
::
dynamic_pointer_cast
<
hpp
::
pinocchio
::
HumanoidRobot
>
(
adw
->
device
);
}
template
<
class
Archive
,
typename
_Scalar
,
int
_Rows
,
int
_Cols
,
int
_Options
,
int
_MaxRows
,
int
_MaxCols
>
inline
void
serialize
(
Archive
&
ar
,
Eigen
::
Array
<
_Scalar
,
_Rows
,
_Cols
,
_Options
,
_MaxRows
,
_MaxCols
>
&
m
,
const
unsigned
int
version
)
{
(
void
)
version
;
Eigen
::
DenseIndex
rows
(
m
.
rows
()),
cols
(
m
.
cols
());
ar
&
BOOST_SERIALIZATION_NVP
(
rows
);
ar
&
BOOST_SERIALIZATION_NVP
(
cols
);
if
(
!
Archive
::
is_saving
::
value
)
m
.
resize
(
rows
,
cols
);
if
(
m
.
size
()
>
0
)
ar
&
make_nvp
(
"data"
,
make_array
(
m
.
data
(),
(
size_t
)
m
.
size
()));
}
}
// namespace serialization
}
// namespace boost
#endif // HPP_PINOCCHIO_SERIALIZATION_HH
tests/CMakeLists.txt
View file @
d2ce34b8
...
...
@@ -51,6 +51,7 @@ ADD_TESTCASE(urdf)
ADD_TESTCASE
(
liegroup-element
)
ADD_TESTCASE
(
print
)
ADD_TESTCASE
(
joint-bounds
)
ADD_TESTCASE
(
serialization
)
FIND_PACKAGE
(
OpenMP
)
IF
(
OPENMP_FOUND
)
...
...
tests/serialization.cc
0 → 100644
View file @
d2ce34b8
// 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/>.
#define BOOST_TEST_MODULE tserialization
#include <boost/test/unit_test.hpp>
#include <sstream>
#include <fstream>
#include <boost/archive/polymorphic_xml_iarchive.hpp>
#include <boost/archive/polymorphic_xml_oarchive.hpp>
#include <pinocchio/fwd.hpp>
#include <hpp/pinocchio/fwd.hh>
#include <hpp/pinocchio/serialization.hh>
using
namespace
hpp
::
pinocchio
;
BOOST_AUTO_TEST_CASE
(
empty_array
)
{
Eigen
::
ArrayXi
empty
(
0
);
std
::
stringstream
ss
;
{
boost
::
archive
::
xml_oarchive
oa
(
ss
);
oa
<<
boost
::
serialization
::
make_nvp
(
"array"
,
empty
);
}
Eigen
::
ArrayXi
empty_r
;
{
boost
::
archive
::
xml_iarchive
ia
(
ss
);
ia
>>
boost
::
serialization
::
make_nvp
(
"array"
,
empty_r
);
}
BOOST_CHECK_EQUAL
(
empty_r
.
size
(),
0
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment