-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #363 from jcarpent/topic/devel
Add support of Pickling
- Loading branch information
Showing
14 changed files
with
397 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// | ||
// Copyright (c) 2022 INRIA | ||
// | ||
|
||
#ifndef HPP_FCL_SERIALIZATION_CONVEX_H | ||
#define HPP_FCL_SERIALIZATION_CONVEX_H | ||
|
||
#include "hpp/fcl/shape/convex.h" | ||
|
||
#include "hpp/fcl/serialization/fwd.h" | ||
#include "hpp/fcl/serialization/geometric_shapes.h" | ||
#include "hpp/fcl/serialization/memory.h" | ||
#include "hpp/fcl/serialization/triangle.h" | ||
#include "hpp/fcl/serialization/quadrilateral.h" | ||
|
||
namespace boost { | ||
namespace serialization { | ||
|
||
namespace internal { | ||
struct ConvexBaseAccessor : hpp::fcl::ConvexBase { | ||
typedef hpp::fcl::ConvexBase Base; | ||
using Base::own_storage_; | ||
}; | ||
|
||
} // namespace internal | ||
|
||
template <class Archive> | ||
void serialize(Archive &ar, hpp::fcl::ConvexBase &convex_base, | ||
const unsigned int /*version*/) { | ||
using namespace hpp::fcl; | ||
|
||
typedef internal::ConvexBaseAccessor Accessor; | ||
Accessor &accessor = reinterpret_cast<Accessor &>(convex_base); | ||
|
||
ar &make_nvp("base", boost::serialization::base_object<hpp::fcl::ShapeBase>( | ||
convex_base)); | ||
const unsigned int num_points_previous = convex_base.num_points; | ||
ar &make_nvp("num_points", convex_base.num_points); | ||
|
||
if (Archive::is_loading::value) { | ||
if (num_points_previous != convex_base.num_points || | ||
!accessor.own_storage_) { | ||
delete[] convex_base.points; | ||
convex_base.points = new hpp::fcl::Vec3f[convex_base.num_points]; | ||
accessor.own_storage_ = true; | ||
} | ||
} | ||
|
||
{ | ||
typedef Eigen::Matrix<FCL_REAL, 3, Eigen::Dynamic> MatrixPoints; | ||
Eigen::Map<MatrixPoints> points_map( | ||
reinterpret_cast<double *>(convex_base.points), 3, | ||
convex_base.num_points); | ||
ar &make_nvp("points", points_map); | ||
} | ||
|
||
ar &make_nvp("center", convex_base.center); | ||
// We don't save neighbors as they will be computed directly by calling | ||
// fillNeighbors. | ||
} | ||
|
||
namespace internal { | ||
template <typename PolygonT> | ||
struct ConvexAccessor : hpp::fcl::Convex<PolygonT> { | ||
typedef hpp::fcl::Convex<PolygonT> Base; | ||
using Base::fillNeighbors; | ||
}; | ||
|
||
} // namespace internal | ||
|
||
template <class Archive, typename PolygonT> | ||
void serialize(Archive &ar, hpp::fcl::Convex<PolygonT> &convex_, | ||
const unsigned int /*version*/) { | ||
using namespace hpp::fcl; | ||
typedef internal::ConvexAccessor<PolygonT> Accessor; | ||
|
||
Accessor &convex = reinterpret_cast<Accessor &>(convex_); | ||
ar &make_nvp("base", boost::serialization::base_object<ConvexBase>(convex)); | ||
|
||
const unsigned int num_polygons_previous = convex.num_polygons; | ||
ar &make_nvp("num_polygons", convex.num_polygons); | ||
|
||
if (Archive::is_loading::value) { | ||
if (num_polygons_previous != convex.num_polygons) { | ||
delete[] convex.polygons; | ||
convex.polygons = new PolygonT[convex.num_polygons]; | ||
} | ||
} | ||
|
||
ar &make_array<PolygonT>(convex.polygons, convex.num_polygons); | ||
|
||
if (Archive::is_loading::value) convex.fillNeighbors(); | ||
} | ||
|
||
} // namespace serialization | ||
} // namespace boost | ||
|
||
namespace hpp { | ||
namespace fcl { | ||
|
||
// namespace internal { | ||
// template <typename BV> | ||
// struct memory_footprint_evaluator< ::hpp::fcl::BVHModel<BV> > { | ||
// static size_t run(const ::hpp::fcl::BVHModel<BV> &bvh_model) { | ||
// return static_cast<size_t>(bvh_model.memUsage(false)); | ||
// } | ||
// }; | ||
// } // namespace internal | ||
|
||
} // namespace fcl | ||
} // namespace hpp | ||
|
||
#endif // ifndef HPP_FCL_SERIALIZATION_CONVEX_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// Copyright (c) 2022 INRIA | ||
// | ||
|
||
#ifndef HPP_FCL_SERIALIZATION_QUADRILATERAL_H | ||
#define HPP_FCL_SERIALIZATION_QUADRILATERAL_H | ||
|
||
#include "hpp/fcl/data_types.h" | ||
#include "hpp/fcl/serialization/fwd.h" | ||
|
||
namespace boost { | ||
namespace serialization { | ||
|
||
template <class Archive> | ||
void serialize(Archive &ar, hpp::fcl::Quadrilateral &quadrilateral, | ||
const unsigned int /*version*/) { | ||
ar &make_nvp("p0", quadrilateral[0]); | ||
ar &make_nvp("p1", quadrilateral[1]); | ||
ar &make_nvp("p2", quadrilateral[2]); | ||
ar &make_nvp("p3", quadrilateral[3]); | ||
} | ||
|
||
} // namespace serialization | ||
} // namespace boost | ||
|
||
#endif // ifndef HPP_FCL_SERIALIZATION_QUADRILATERAL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// Copyright (c) 2021-2022 INRIA | ||
// | ||
|
||
#ifndef HPP_FCL_SERIALIZATION_TRIANGLE_H | ||
#define HPP_FCL_SERIALIZATION_TRIANGLE_H | ||
|
||
#include "hpp/fcl/data_types.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]); | ||
} | ||
|
||
} // namespace serialization | ||
} // namespace boost | ||
|
||
#endif // ifndef HPP_FCL_SERIALIZATION_TRIANGLE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.