coal
3.0.4
Coal, The Collision Detection Library. Previously known as HPP-FCL, fork of FCL -- The Flexible Collision Library
Toggle main menu visibility
Loading...
Searching...
No Matches
octree.h
Go to the documentation of this file.
1
//
2
// Copyright (c) 2023-2024 INRIA
3
//
4
5
#ifndef COAL_SERIALIZATION_OCTREE_H
6
#define COAL_SERIALIZATION_OCTREE_H
7
8
#include <sstream>
9
#include <iostream>
10
11
#include <boost/serialization/string.hpp>
12
13
#include "
coal/octree.h
"
14
#include "
coal/serialization/fwd.h
"
15
16
namespace
boost
{
17
namespace
serialization
{
18
19
namespace
internal
{
20
struct
OcTreeAccessor
:
coal::OcTree
{
21
typedef
coal::OcTree
Base
;
22
using
Base::default_occupancy
;
23
using
Base::free_threshold
;
24
using
Base::occupancy_threshold
;
25
using
Base::tree
;
26
};
27
}
// namespace internal
28
29
template
<
class
Archive>
30
void
save_construct_data
(Archive &ar,
const
coal::OcTree
*octree_ptr,
31
const
unsigned
int
/*version*/
) {
32
const
double
resolution = octree_ptr->
getResolution
();
33
ar << make_nvp(
"resolution"
, resolution);
34
}
35
36
template
<
class
Archive>
37
void
save
(Archive &ar,
const
coal::OcTree
&octree,
38
const
unsigned
int
/*version*/
) {
39
typedef
internal::OcTreeAccessor
Accessor;
40
const
Accessor &access =
reinterpret_cast<
const
Accessor &
>
(octree);
41
42
std::ostringstream stream;
43
access.
tree
->write(stream);
44
const
std::string stream_str = stream.str();
45
auto
size = stream_str.size();
46
// We can't directly serialize stream_str because it contains binary data.
47
// This create a bug on Windows with text_archive
48
ar << make_nvp(
"tree_data_size"
, size);
49
ar << make_nvp(
"tree_data"
,
50
make_array(stream_str.c_str(), stream_str.size()));
51
52
ar << make_nvp(
"base"
, base_object<coal::CollisionGeometry>(octree));
53
ar << make_nvp(
"default_occupancy"
, access.default_occupancy);
54
ar << make_nvp(
"occupancy_threshold"
, access.occupancy_threshold);
55
ar << make_nvp(
"free_threshold"
, access.free_threshold);
56
}
57
58
template
<
class
Archive>
59
void
load_construct_data
(Archive &ar,
coal::OcTree
*octree_ptr,
60
const
unsigned
int
/*version*/
) {
61
double
resolution;
62
ar >> make_nvp(
"resolution"
, resolution);
63
new
(octree_ptr)
coal::OcTree
(resolution);
64
}
65
66
template
<
class
Archive>
67
void
load
(Archive &ar,
coal::OcTree
&octree,
const
unsigned
int
/*version*/
) {
68
typedef
internal::OcTreeAccessor
Accessor;
69
Accessor &access =
reinterpret_cast<
Accessor &
>
(octree);
70
71
std::size_t tree_data_size;
72
ar >> make_nvp(
"tree_data_size"
, tree_data_size);
73
74
std::string stream_str;
75
stream_str.resize(tree_data_size);
77
assert(tree_data_size > 0 &&
"tree_data_size should be greater than 0"
);
78
ar >> make_nvp(
"tree_data"
, make_array(&stream_str[0], tree_data_size));
79
std::istringstream stream(stream_str);
80
81
octomap::AbstractOcTree *new_tree = octomap::AbstractOcTree::read(stream);
82
access.tree = std::shared_ptr<const octomap::OcTree>(
83
dynamic_cast<
octomap::OcTree *
>
(new_tree));
84
85
ar >> make_nvp(
"base"
, base_object<coal::CollisionGeometry>(octree));
86
ar >> make_nvp(
"default_occupancy"
, access.default_occupancy);
87
ar >> make_nvp(
"occupancy_threshold"
, access.occupancy_threshold);
88
ar >> make_nvp(
"free_threshold"
, access.free_threshold);
89
}
90
91
template
<
class
Archive>
92
void
serialize
(Archive &ar,
coal::OcTree
&octree,
const
unsigned
int
version) {
93
split_free(ar, octree, version);
94
}
95
96
}
// namespace serialization
97
}
// namespace boost
98
99
COAL_SERIALIZATION_DECLARE_EXPORT
(
::coal::OcTree
)
100
101
#endif
// ifndef COAL_SERIALIZATION_OCTREE_H
coal::OcTree
Octree is one type of collision geometry which can encode uncertainty information in the sensor data.
Definition
octree.h:53
coal::OcTree::tree
shared_ptr< const octomap::OcTree > tree
Definition
octree.h:55
coal::OcTree::default_occupancy
CoalScalar default_occupancy
Definition
octree.h:57
coal::OcTree::getResolution
CoalScalar getResolution() const
Returns the resolution of the octree.
Definition
octree.h:153
coal::OcTree::free_threshold
CoalScalar free_threshold
Definition
octree.h:60
coal::OcTree::occupancy_threshold
CoalScalar occupancy_threshold
Definition
octree.h:59
fwd.h
COAL_SERIALIZATION_DECLARE_EXPORT
#define COAL_SERIALIZATION_DECLARE_EXPORT(T)
Definition
fwd.h:30
boost::serialization::internal
Definition
BV_splitter.h:15
boost::serialization
Definition
AABB.h:12
boost::serialization::load_construct_data
void load_construct_data(Archive &ar, coal::OcTree *octree_ptr, const unsigned int)
Definition
octree.h:59
boost::serialization::save_construct_data
void save_construct_data(Archive &ar, const coal::OcTree *octree_ptr, const unsigned int)
Definition
octree.h:30
boost::serialization::load
void load(Archive &ar, coal::BVSplitter< BV > &splitter_, const unsigned int)
Definition
BV_splitter.h:44
boost::serialization::save
void save(Archive &ar, const coal::BVSplitter< BV > &splitter_, const unsigned int)
Definition
BV_splitter.h:30
boost::serialization::serialize
void serialize(Archive &ar, coal::AABB &aabb, const unsigned int)
Definition
AABB.h:15
boost
Definition
AABB.h:11
octree.h
boost::serialization::internal::OcTreeAccessor
Definition
octree.h:20
boost::serialization::internal::OcTreeAccessor::Base
coal::OcTree Base
Definition
octree.h:21
boost::serialization::internal::OcTreeAccessor::tree
shared_ptr< const octomap::OcTree > tree
Definition
octree.h:55
include
coal
serialization
octree.h
Generated by
1.17.0