.. _program_listing_file_include_coal_serialization_octree.h: Program Listing for File octree.h ================================= |exhale_lsh| :ref:`Return to documentation for file ` (``include/coal/serialization/octree.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // // Copyright (c) 2023-2024 INRIA // #ifndef COAL_SERIALIZATION_OCTREE_H #define COAL_SERIALIZATION_OCTREE_H #include #include #include #include "coal/octree.h" #include "coal/serialization/fwd.h" namespace boost { namespace serialization { namespace internal { struct OcTreeAccessor : coal::OcTree { typedef coal::OcTree Base; using Base::default_occupancy; using Base::free_threshold; using Base::occupancy_threshold; using Base::tree; }; } // namespace internal template void save_construct_data(Archive &ar, const coal::OcTree *octree_ptr, const unsigned int /*version*/) { const coal::Scalar resolution = octree_ptr->getResolution(); ar << make_nvp("resolution", resolution); } template void save(Archive &ar, const coal::OcTree &octree, const unsigned int /*version*/) { typedef internal::OcTreeAccessor Accessor; const Accessor &access = reinterpret_cast(octree); std::ostringstream stream; access.tree->write(stream); const std::string stream_str = stream.str(); auto size = stream_str.size(); // We can't directly serialize stream_str because it contains binary data. // This create a bug on Windows with text_archive ar << make_nvp("tree_data_size", size); ar << make_nvp("tree_data", make_array(stream_str.c_str(), stream_str.size())); ar << make_nvp("base", base_object(octree)); ar << make_nvp("default_occupancy", access.default_occupancy); ar << make_nvp("occupancy_threshold", access.occupancy_threshold); ar << make_nvp("free_threshold", access.free_threshold); } template void load_construct_data(Archive &ar, coal::OcTree *octree_ptr, const unsigned int /*version*/) { coal::Scalar resolution; ar >> make_nvp("resolution", resolution); new (octree_ptr) coal::OcTree(resolution); } template void load(Archive &ar, coal::OcTree &octree, const unsigned int /*version*/) { typedef internal::OcTreeAccessor Accessor; Accessor &access = reinterpret_cast(octree); std::size_t tree_data_size; ar >> make_nvp("tree_data_size", tree_data_size); std::string stream_str; stream_str.resize(tree_data_size); assert(tree_data_size > 0 && "tree_data_size should be greater than 0"); ar >> make_nvp("tree_data", make_array(&stream_str[0], tree_data_size)); std::istringstream stream(stream_str); octomap::AbstractOcTree *new_tree = octomap::AbstractOcTree::read(stream); access.tree = std::shared_ptr( dynamic_cast(new_tree)); ar >> make_nvp("base", base_object(octree)); ar >> make_nvp("default_occupancy", access.default_occupancy); ar >> make_nvp("occupancy_threshold", access.occupancy_threshold); ar >> make_nvp("free_threshold", access.free_threshold); } template void serialize(Archive &ar, coal::OcTree &octree, const unsigned int version) { split_free(ar, octree, version); } } // namespace serialization } // namespace boost COAL_SERIALIZATION_DECLARE_EXPORT(::coal::OcTree) #endif // ifndef COAL_SERIALIZATION_OCTREE_H