Commit 583af657 authored by JasonChmn's avatar JasonChmn Committed by Pierre Fernbach
Browse files

[contact-sequence] Edit serialization functions => Add test OK

parent 26c9b5ef
......@@ -60,7 +60,7 @@ namespace multicontact_api
/*Variables*/
std::vector<std::string> m_effector_names_;
std::vector<std::string> m_effector_names;
ContactPatchMap m_contact_patches;
std::pair<double,double> m_time_interval;
ConfigurationVector m_reference_configuration;
......@@ -186,12 +186,14 @@ namespace multicontact_api
protected:
/*Attributes 2*/
/// \brief Second Order Wrench Cone (SOWC) representing the Minkoski sum of the patch linear wrench cone.
SOC6 m_sowc;
SE3 m_sowc_placement;
Matrix6x m_double_description;
/// \brief Linear Wrench Cone (LWC) representing the Minkoski sum of the patch linear wrench cone.
WrenchCone m_lwc;
/*Attributes 2*/
private:
......@@ -244,7 +246,7 @@ namespace multicontact_api
template<class Archive>
void save(Archive & ar, const unsigned int /*version*/) const
{
ar & boost::serialization::make_nvp("effector_names",m_effector_names_);
ar & boost::serialization::make_nvp("effector_names",m_effector_names);
ar & boost::serialization::make_nvp("contact_patches",m_contact_patches);
ar & boost::serialization::make_nvp("time_interval",m_time_interval);
ar & boost::serialization::make_nvp("reference_configuration",m_reference_configuration);
......@@ -280,7 +282,7 @@ namespace multicontact_api
template<class Archive>
void load(Archive & ar, const unsigned int /*version*/)
{
ar >> boost::serialization::make_nvp("effector_names",m_effector_names_);
ar >> boost::serialization::make_nvp("effector_names",m_effector_names);
ar >> boost::serialization::make_nvp("contact_patches",m_contact_patches);
ar >> boost::serialization::make_nvp("time_interval",m_time_interval);
ar >> boost::serialization::make_nvp("reference_configuration",m_reference_configuration);
......
......@@ -9,89 +9,112 @@
#include "multicontact-api/scenario/ms-interval.hpp"
#include "multicontact-api/serialization/archive.hpp"
#include "multicontact-api/serialization/aligned-vector.hpp"
#include <vector>
#include <boost/serialization/vector.hpp>
#include <Eigen/StdVector>
#include <pinocchio/container/aligned-vector.hpp>
namespace multicontact_api {
namespace scenario {
template <class _ContactPhase>
struct ContactSequenceTpl : public serialization::Serializable<ContactSequenceTpl<_ContactPhase> > {
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
typedef _ContactPhase ContactPhase;
typedef typename ContactPhase::Scalar Scalar;
typedef typename ContactPhase::TimeVector TimeVector;
typedef typename ContactPhase::StateVector StateVector;
typedef typename ContactPhase::ConfigurationVector ConfigurationVector;
typedef MSIntervalDataTpl<TimeVector, StateVector, ConfigurationVector> MSIntervalData;
typedef pinocchio::container::aligned_vector<MSIntervalData> MSIntervalDataVector;
typedef pinocchio::container::aligned_vector<ContactPhase> ContactPhaseVector;
// typedef std::vector<ContactPhase, Eigen::aligned_allocator<ContactPhase> > ContactPhaseVector;
ContactSequenceTpl(const size_t size = 0)
: m_contact_phases(size), m_ms_interval_data(0), m_conic_type(CONIC_UNDEFINED) {}
/// \brief Copy contructor
ContactSequenceTpl(const ContactSequenceTpl& other)
: m_contact_phases(other.m_contact_phases),
m_ms_interval_data(other.m_ms_interval_data),
m_conic_type(other.m_conic_type) {}
size_t size() const { return m_contact_phases.size(); }
// protected:
ContactPhaseVector m_contact_phases;
bool operator==(const ContactSequenceTpl& other) const {
return m_contact_phases == other.m_contact_phases && m_ms_interval_data == other.m_ms_interval_data &&
m_conic_type == other.m_conic_type;
}
bool operator!=(const ContactSequenceTpl& other) const { return !(*this == other); }
void resize(const size_t size) { m_contact_phases.resize(size); }
MSIntervalDataVector m_ms_interval_data;
ConicType m_conic_type;
private:
// Serialization of the class
friend class boost::serialization::access;
namespace multicontact_api{
namespace scenario {
template<class _ContactPhase>
struct ContactSequenceTpl : public serialization::Serializable< ContactSequenceTpl<_ContactPhase> >
{
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
typedef _ContactPhase ContactPhase;
typedef typename ContactPhase::Scalar Scalar;
typedef std::vector<Scalar> TimeVector;
typedef typename ContactPhase::StateVector StateVector;
typedef typename ContactPhase::ConfigurationVector ConfigurationVector;
typedef MSIntervalDataTpl<TimeVector,StateVector,ConfigurationVector> MSIntervalData;
typedef pinocchio::container::aligned_vector<MSIntervalData> MSIntervalDataVector;
typedef pinocchio::container::aligned_vector<ContactPhase> ContactPhaseVector;
// typedef std::vector<ContactPhase, Eigen::aligned_allocator<ContactPhase> > ContactPhaseVector;
ContactSequenceTpl(const size_t size = 0)
: m_contact_phases(size)
, m_ms_interval_data(0)
, m_conic_type(CONIC_UNDEFINED)
{}
/// \brief Copy contructor
ContactSequenceTpl(const ContactSequenceTpl & other)
: m_contact_phases(other.m_contact_phases)
, m_ms_interval_data(other.m_ms_interval_data)
, m_conic_type(other.m_conic_type)
{}
size_t size() const { return m_contact_phases.size(); }
bool operator==(const ContactSequenceTpl & other) const
{
return
m_contact_phases == other.m_contact_phases
&& m_ms_interval_data == other.m_ms_interval_data
&& m_conic_type == other.m_conic_type
;
}
template <class Archive>
void save(Archive& ar, const unsigned int /*version*/) const {
const size_t m_size = size();
ar& boost::serialization::make_nvp("size", m_size);
for (typename ContactPhaseVector::const_iterator it = m_contact_phases.begin(); it != m_contact_phases.end(); ++it)
ar& boost::serialization::make_nvp("contact_phase", *it);
bool operator!=(const ContactSequenceTpl & other) const
{ return !(*this == other); }
ar& boost::serialization::make_nvp("ms_interval_data", m_ms_interval_data);
ar& boost::serialization::make_nvp("conic_type", m_conic_type);
}
void resize(const size_t size)
{
m_contact_phases.resize(size);
}
template <class Archive>
void load(Archive& ar, const unsigned int /*version*/) {
size_t m_size;
ar >> boost::serialization::make_nvp("size", m_size);
assert(m_size > 0);
resize(m_size);
for (typename ContactPhaseVector::iterator it = m_contact_phases.begin(); it != m_contact_phases.end(); ++it) {
ar >> boost::serialization::make_nvp("contact_phase", *it);
/*Attributes*/
ContactPhaseVector m_contact_phases;
std::vector<std::string> m_effector_names;
MSIntervalDataVector m_ms_interval_data;
ConicType m_conic_type;
/*Attributes*/
private:
// Serialization of the class
friend class boost::serialization::access;
template<class Archive>
void save(Archive & ar, const unsigned int /*version*/) const
{
const size_t m_size = size();
ar & boost::serialization::make_nvp("size",m_size);
for(typename ContactPhaseVector::const_iterator it = m_contact_phases.begin();
it != m_contact_phases.end(); ++it)
{
ar & boost::serialization::make_nvp("contact_phase",*it);
}
ar & boost::serialization::make_nvp("m_effector_names",m_effector_names);
ar & boost::serialization::make_nvp("ms_interval_data",m_ms_interval_data);
ar & boost::serialization::make_nvp("conic_type",m_conic_type);
}
ar >> boost::serialization::make_nvp("ms_interval_data", m_ms_interval_data);
ar >> boost::serialization::make_nvp("conic_type", m_conic_type);
}
template<class Archive>
void load(Archive & ar, const unsigned int /*version*/)
{
size_t m_size;
ar >> boost::serialization::make_nvp("size",m_size);
assert(m_size>0);
resize(m_size);
for(typename ContactPhaseVector::iterator it = m_contact_phases.begin();
it != m_contact_phases.end(); ++it)
{
ar >> boost::serialization::make_nvp("contact_phase",*it);
}
ar >> boost::serialization::make_nvp("m_effector_names",m_effector_names);
ar >> boost::serialization::make_nvp("ms_interval_data",m_ms_interval_data);
ar >> boost::serialization::make_nvp("conic_type",m_conic_type);
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
};
BOOST_SERIALIZATION_SPLIT_MEMBER()
};
} // namespace scenario
} // namespace multicontact_api
......
......@@ -8,6 +8,7 @@
#include <boost/utility/binary.hpp>
#include "multicontact-api/scenario/contact-phase.hpp"
#include "multicontact-api/scenario/contact-sequence.hpp"
#include "multicontact-api/scenario/contact-patch.hpp"
using namespace multicontact_api::scenario;
......@@ -48,10 +49,8 @@ BOOST_AUTO_TEST_CASE(contact_patch) {
cp.worldContactModelPlacement().setRandom();
ContactPatch cp2(cp);
ContactPatch cp3 = cp2;
BOOST_CHECK(cp == cp);
BOOST_CHECK(cp == cp2);
Ad a1;
Ad a2(a1);
}
......@@ -69,10 +68,8 @@ BOOST_AUTO_TEST_CASE(contact_phase)
it->second.worldContactModelPlacement().setRandom();
}
ContactPhase4 cp2(cp);
BOOST_CHECK(cp == cp);
BOOST_CHECK(cp == cp2);
// test serialization
cp.saveAsText("serialization_cp_test.test");
cp_test.loadFromText("serialization_cp_test.test");
......@@ -80,4 +77,17 @@ BOOST_AUTO_TEST_CASE(contact_phase)
BOOST_CHECK(cp == cp_test);
}
BOOST_AUTO_TEST_CASE(contact_sequence)
{
ContactPhase4 cp;
ContactSequence4 cs(1);
ContactSequence4 cs_test(0);
cs.m_contact_phases[0] = cp;
// test serialization
cs.saveAsText("serialization_cs_test.test");
cs_test.loadFromText("serialization_cs_test.test");
remove("serialization_cp_test.test");
BOOST_CHECK(cs == cs_test);
}
BOOST_AUTO_TEST_SUITE_END()
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