Verified Commit 4684a156 authored by Justin Carpentier's avatar Justin Carpentier
Browse files

serialization: add computeMemoryFootprint

This function is useful when performing binary serialization (size of the allocated buffer)
parent b62e8c0a
Pipeline #14670 passed with stage
in 43 minutes and 46 seconds
......@@ -181,8 +181,9 @@ SET(${PROJECT_NAME}_HEADERS
include/hpp/fcl/serialization/BVH_model.h
include/hpp/fcl/serialization/collision_data.h
include/hpp/fcl/serialization/collision_object.h
include/hpp/fcl/serialization/geometric_shapes.h
include/hpp/fcl/serialization/eigen.h
include/hpp/fcl/serialization/geometric_shapes.h
include/hpp/fcl/serialization/memory.h
include/hpp/fcl/serialization/OBB.h
include/hpp/fcl/serialization/RSS.h
include/hpp/fcl/serialization/OBBRSS.h
......
......@@ -11,6 +11,7 @@
#include "hpp/fcl/serialization/BV_node.h"
#include "hpp/fcl/serialization/BV_splitter.h"
#include "hpp/fcl/serialization/collision_object.h"
#include "hpp/fcl/serialization/memory.h"
namespace boost
{
......@@ -314,4 +315,22 @@ 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 fcl
} // namespace hpp
#endif // ifndef HPP_FCL_SERIALIZATION_BVH_MODEL_H
//
// Copyright (c) 2021 INRIA
//
#ifndef HPP_FCL_SERIALIZATION_MEMORY_H
#define HPP_FCL_SERIALIZATION_MEMORY_H
namespace hpp {
namespace fcl {
namespace internal
{
template<typename T>
struct memory_footprint_evaluator
{
static size_t run(const T &) { return sizeof(T); }
};
}
/// \brief Returns the memory footpring of the input object.
/// For POD objects, this function returns the result of sizeof(T)
///
/// \param[in] object whose memory footprint needs to be evaluated.
///
/// \return the memory footprint of the input object.
template<typename T>
size_t computeMemoryFootprint(const T & object)
{
return internal::memory_footprint_evaluator<T>::run(object);
}
} // namespace fcl
} // namespace hpp
#endif // ifndef HPP_FCL_SERIALIZATION_MEMORY_H
......@@ -46,6 +46,7 @@
#include <hpp/fcl/serialization/AABB.h>
#include <hpp/fcl/serialization/BVH_model.h>
#include <hpp/fcl/serialization/geometric_shapes.h>
#include <hpp/fcl/serialization/memory.h>
#include "utility.h"
#include "fcl_resources/config.h"
......@@ -287,3 +288,25 @@ BOOST_AUTO_TEST_CASE(test_shapes)
test_serialization(plane,plane_copy);
}
}
BOOST_AUTO_TEST_CASE(test_memory_footprint)
{
Sphere sphere(1.);
BOOST_CHECK(sizeof(Sphere) == computeMemoryFootprint(sphere));
std::vector<Vec3f> p1;
std::vector<Triangle> t1;
boost::filesystem::path path(TEST_RESOURCES_DIR);
loadOBJFile((path / "env.obj").string().c_str(), p1, t1);
BVHModel<OBBRSS> m1;
m1.beginModel();
m1.addSubModel(p1, t1);
m1.endModel();
std::cout << "computeMemoryFootprint(m1): " << computeMemoryFootprint(m1) << std::endl;
BOOST_CHECK(sizeof(BVHModel<OBBRSS>) < computeMemoryFootprint(m1));
BOOST_CHECK(m1.memUsage(false) == computeMemoryFootprint(m1));
}
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