Verified Commit c16f80be authored by Justin Carpentier's avatar Justin Carpentier
Browse files

serialization: add more features

parent 09c9db56
Pipeline #13648 failed with stage
in 17 minutes and 15 seconds
......@@ -174,8 +174,12 @@ SET(${PROJECT_NAME}_HEADERS
include/hpp/fcl/internal/traversal_node_shapes.h
include/hpp/fcl/internal/traversal_recurse.h
include/hpp/fcl/internal/traversal.h
include/hpp/fcl/serialization/fwd.h
include/hpp/fcl/serialization/AABB.h
include/hpp/fcl/serialization/eigen.h
include/hpp/fcl/serialization/collision_data.h
include/hpp/fcl/serialization/collision_object.h
include/hpp/fcl/serialization/BVH_model.h
)
add_subdirectory(doc)
......
//
// Copyright (c) 2021 INRIA
//
#ifndef HPP_FCL_SERIALIZATION_AABB_H
#define HPP_FCL_SERIALIZATION_AABB_H
#include <boost/serialization/split_free.hpp>
#include "hpp/fcl/BV/AABB.h"
#include "hpp/fcl/serialization/fwd.h"
namespace boost
{
namespace serialization
{
template <class Archive>
void serialize(Archive & ar,
hpp::fcl::AABB & aabb,
const unsigned int /*version*/)
{
ar & make_nvp("min_",aabb.min_);
ar & make_nvp("max_",aabb.max_);
}
}
}
#endif // ifndef HPP_FCL_SERIALIZATION_AABB_H
//
// Copyright (c) 2021 INRIA
//
#ifndef HPP_FCL_SERIALIZATION_BVH_MODEL_H
#define HPP_FCL_SERIALIZATION_BVH_MODEL_H
#include <boost/serialization/split_free.hpp>
#include "hpp/fcl/BVH/BVH_model.h"
#include "hpp/fcl/serialization/fwd.h"
namespace boost
{
namespace serialization
{
template <class Archive>
void serialize(Archive & ar,
hpp::fcl::Triangle & triangle,
const unsigned int /*version*/)
{
ar & make_nvp("p0",triangle[0]);
ar & make_nvp("p1",triangle[1]);
ar & make_nvp("p2",triangle[2]);
}
template <class Archive>
void save(Archive & ar,
const hpp::fcl::BVHModelBase & bvh_model,
const unsigned int /*version*/)
{
ar & make_nvp("num_tris",bvh_model.num_tris);
ar & make_nvp("num_vertices",bvh_model.num_vertices);
ar & make_nvp("tri_indices",make_array(bvh_model.tri_indices,bvh_model.num_tris));
ar & make_nvp("vertices",make_array(bvh_model.vertices,bvh_model.num_vertices));
ar & make_nvp("build_state",bvh_model.build_state);
if(bvh_model.prev_vertices)
{
const bool has_prev_vertices = true;
ar << make_nvp("has_prev_vertices",has_prev_vertices);
ar << make_nvp("prev_vertices",make_array(bvh_model.prev_vertices,bvh_model.num_vertices));
}
else
{
const bool has_prev_vertices = false;
ar & make_nvp("has_prev_vertices",has_prev_vertices);
}
}
template <class Archive>
void load(Archive & ar,
hpp::fcl::BVHModelBase & bvh_model,
const unsigned int /*version*/)
{
using namespace hpp::fcl;
ar >> make_nvp("num_tris",bvh_model.num_tris);
if(bvh_model.num_tris > 0)
bvh_model.tri_indices = new Triangle[bvh_model.num_tris];
ar >> make_nvp("num_vertices",bvh_model.num_vertices);
if(bvh_model.num_vertices > 0)
bvh_model.vertices = new Vec3f[bvh_model.num_vertices];
ar >> make_nvp("tri_indices",make_array(bvh_model.tri_indices,bvh_model.num_tris));
ar >> make_nvp("vertices",make_array(bvh_model.vertices,bvh_model.num_vertices));
ar >> make_nvp("build_state",bvh_model.build_state);
bool has_prev_vertices;
ar >> make_nvp("has_prev_vertices",has_prev_vertices);
if(has_prev_vertices)
{
bvh_model.prev_vertices = new Vec3f[bvh_model.num_vertices];
ar >> make_nvp("prev_vertices",make_array(bvh_model.prev_vertices,bvh_model.num_vertices));
}
}
HPP_FCL_SERIALIZATION_SPLIT(hpp::fcl::BVHModelBase)
}
}
#endif // ifndef HPP_FCL_SERIALIZATION_BVH_MODEL_H
......@@ -8,16 +8,7 @@
#include <boost/serialization/split_free.hpp>
#include "hpp/fcl/collision_data.h"
#include "hpp/fcl/serialization/eigen.h"
#define HPP_FCL_SERIALIZATION_SPLIT(Type) \
template <class Archive> \
void serialize(Archive & ar, \
Type & value, \
const unsigned int version) \
{ \
split_free(ar,value,version); \
}
#include "hpp/fcl/serialization/fwd.h"
namespace boost
{
......@@ -154,6 +145,4 @@ namespace boost
}
}
#undef HPP_FCL_SERIALIZATION_SPLIT
#endif // ifndef HPP_FCL_SERIALIZATION_COLLISION_DATA_H
//
// Copyright (c) 2021 INRIA
//
#ifndef HPP_FCL_SERIALIZATION_COLLISION_OBJECT_H
#define HPP_FCL_SERIALIZATION_COLLISION_OBJECT_H
#include <boost/serialization/split_free.hpp>
#include "hpp/fcl/collision_object.h"
#include "hpp/fcl/serialization/fwd.h"
#include "hpp/fcl/serialization/AABB.h"
namespace boost
{
namespace serialization
{
template <class Archive>
void save(Archive & ar,
const hpp::fcl::CollisionGeometry & collision_geometry,
const unsigned int /*version*/)
{
ar & make_nvp("aabb_center",collision_geometry.aabb_center);
ar & make_nvp("aabb_radius",collision_geometry.aabb_radius);
ar & make_nvp("aabb_local",collision_geometry.aabb_local);
ar & make_nvp("cost_density",collision_geometry.cost_density);
ar & make_nvp("threshold_occupied",collision_geometry.threshold_occupied);
ar & make_nvp("threshold_free",collision_geometry.threshold_free);
}
template <class Archive>
void load(Archive & ar,
hpp::fcl::CollisionGeometry & collision_geometry,
const unsigned int /*version*/)
{
ar >> make_nvp("aabb_center",collision_geometry.aabb_center);
ar >> make_nvp("aabb_radius",collision_geometry.aabb_radius);
ar >> make_nvp("aabb_local",collision_geometry.aabb_local);
ar >> make_nvp("cost_density",collision_geometry.cost_density);
ar >> make_nvp("threshold_occupied",collision_geometry.threshold_occupied);
ar >> make_nvp("threshold_free",collision_geometry.threshold_free);
collision_geometry.user_data = NULL; // no way to recover this
}
HPP_FCL_SERIALIZATION_SPLIT(hpp::fcl::CollisionGeometry)
}
}
#endif // ifndef HPP_FCL_SERIALIZATION_COLLISION_OBJECT_H
//
// Copyright (c) 2021 INRIA
//
#ifndef HPP_FCL_SERIALIZATION_FWD_H
#define HPP_FCL_SERIALIZATION_FWD_H
#include <boost/serialization/split_free.hpp>
#include "hpp/fcl/serialization/eigen.h"
#define HPP_FCL_SERIALIZATION_SPLIT(Type) \
template <class Archive> \
void serialize(Archive & ar, \
Type & value, \
const unsigned int version) \
{ \
split_free(ar,value,version); \
}
#endif // ifndef HPP_FCL_SERIALIZATION_FWD_H
......@@ -41,6 +41,7 @@
#include <hpp/fcl/distance.h>
#include <hpp/fcl/serialization/collision_data.h>
#include <hpp/fcl/serialization/AABB.h>
#include "utility.h"
#include "fcl_resources/config.h"
......@@ -84,6 +85,12 @@ void test_serialization(const T & value)
BOOST_CHECK(check(value,copy_value));
}
BOOST_AUTO_TEST_CASE(aabb)
{
AABB aabb(-Vec3f::Ones(),Vec3f::Ones());
test_serialization(aabb);
}
BOOST_AUTO_TEST_CASE(collision_data)
{
Contact contact(NULL, NULL, 1, 2, Vec3f::Ones(), Vec3f::Zero(), -10.);
......
Supports Markdown
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