coal 3.0.2
Coal, The Collision Detection Library. Previously known as HPP-FCL, fork of FCL -- The Flexible Collision Library
Loading...
Searching...
No Matches
convex.h
Go to the documentation of this file.
1//
2// Copyright (c) 2022-2024 INRIA
3//
4
5#ifndef COAL_SERIALIZATION_CONVEX_H
6#define COAL_SERIALIZATION_CONVEX_H
7
9
15
16namespace boost {
17namespace serialization {
18
19namespace internal {
23
24} // namespace internal
25
26template <class Archive>
27void serialize(Archive& ar, coal::ConvexBase& convex_base,
28 const unsigned int /*version*/) {
29 using namespace coal;
30
31 ar& make_nvp("base",
32 boost::serialization::base_object<coal::ShapeBase>(convex_base));
33
34 const unsigned int num_points_previous = convex_base.num_points;
35 ar& make_nvp("num_points", convex_base.num_points);
36
37 const unsigned int num_normals_and_offsets_previous =
38 convex_base.num_normals_and_offsets;
39 ar& make_nvp("num_normals_and_offsets", convex_base.num_normals_and_offsets);
40
41 const int num_warm_start_supports_previous =
42 static_cast<int>(convex_base.support_warm_starts.points.size());
43 assert(num_warm_start_supports_previous ==
44 static_cast<int>(convex_base.support_warm_starts.indices.size()));
45 int num_warm_start_supports = num_warm_start_supports_previous;
46 ar& make_nvp("num_warm_start_supports", num_warm_start_supports);
47
48 if (Archive::is_loading::value) {
49 if (num_points_previous != convex_base.num_points) {
50 convex_base.points.reset();
51 if (convex_base.num_points > 0)
52 convex_base.points.reset(
53 new std::vector<Vec3s>(convex_base.num_points));
54 }
55
56 if (num_normals_and_offsets_previous !=
57 convex_base.num_normals_and_offsets) {
58 convex_base.normals.reset();
59 convex_base.offsets.reset();
60 if (convex_base.num_normals_and_offsets > 0) {
61 convex_base.normals.reset(
62 new std::vector<Vec3s>(convex_base.num_normals_and_offsets));
63 convex_base.offsets.reset(
64 new std::vector<CoalScalar>(convex_base.num_normals_and_offsets));
65 }
66 }
67
68 if (num_warm_start_supports_previous != num_warm_start_supports) {
69 convex_base.support_warm_starts.points.resize(
70 static_cast<size_t>(num_warm_start_supports));
71 convex_base.support_warm_starts.indices.resize(
72 static_cast<size_t>(num_warm_start_supports));
73 }
74 }
75
76 typedef Eigen::Matrix<CoalScalar, 3, Eigen::Dynamic> MatrixPoints;
77 if (convex_base.num_points > 0) {
78 Eigen::Map<MatrixPoints> points_map(
79 reinterpret_cast<CoalScalar*>(convex_base.points->data()), 3,
80 convex_base.num_points);
81 ar& make_nvp("points", points_map);
82 }
83
84 typedef Eigen::Matrix<CoalScalar, 1, Eigen::Dynamic> VecOfReals;
85 if (convex_base.num_normals_and_offsets > 0) {
86 Eigen::Map<MatrixPoints> normals_map(
87 reinterpret_cast<CoalScalar*>(convex_base.normals->data()), 3,
88 convex_base.num_normals_and_offsets);
89 ar& make_nvp("normals", normals_map);
90
91 Eigen::Map<VecOfReals> offsets_map(
92 reinterpret_cast<CoalScalar*>(convex_base.offsets->data()), 1,
93 convex_base.num_normals_and_offsets);
94 ar& make_nvp("offsets", offsets_map);
95 }
96
97 typedef Eigen::Matrix<int, 1, Eigen::Dynamic> VecOfInts;
98 if (num_warm_start_supports > 0) {
99 Eigen::Map<MatrixPoints> warm_start_support_points_map(
100 reinterpret_cast<CoalScalar*>(
101 convex_base.support_warm_starts.points.data()),
102 3, num_warm_start_supports);
103 ar& make_nvp("warm_start_support_points", warm_start_support_points_map);
104
105 Eigen::Map<VecOfInts> warm_start_support_indices_map(
106 reinterpret_cast<int*>(convex_base.support_warm_starts.indices.data()),
107 1, num_warm_start_supports);
108 ar& make_nvp("warm_start_support_indices", warm_start_support_indices_map);
109 }
110
111 ar& make_nvp("center", convex_base.center);
112 // We don't save neighbors as they will be computed directly by calling
113 // fillNeighbors.
114}
115
116namespace internal {
117template <typename PolygonT>
122
123} // namespace internal
124
125template <class Archive, typename PolygonT>
126void serialize(Archive& ar, coal::Convex<PolygonT>& convex_,
127 const unsigned int /*version*/) {
128 using namespace coal;
130
131 Accessor& convex = reinterpret_cast<Accessor&>(convex_);
132 ar& make_nvp("base", boost::serialization::base_object<ConvexBase>(convex_));
133
134 const unsigned int num_polygons_previous = convex.num_polygons;
135 ar& make_nvp("num_polygons", convex.num_polygons);
136
137 if (Archive::is_loading::value) {
138 if (num_polygons_previous != convex.num_polygons) {
139 convex.polygons.reset(new std::vector<PolygonT>(convex.num_polygons));
140 }
141 }
142
143 ar& make_array<PolygonT>(convex.polygons->data(), convex.num_polygons);
144
145 if (Archive::is_loading::value) convex.fillNeighbors();
146}
147
148} // namespace serialization
149} // namespace boost
150
153
154namespace coal {
155
156// namespace internal {
157// template <typename BV>
158// struct memory_footprint_evaluator< ::coal::BVHModel<BV> > {
159// static size_t run(const ::coal::BVHModel<BV> &bvh_model) {
160// return static_cast<size_t>(bvh_model.memUsage(false));
161// }
162// };
163// } // namespace internal
164
165} // namespace coal
166
167#endif // ifndef COAL_SERIALIZATION_CONVEX_H
Base for convex polytope.
Definition geometric_shapes.h:645
Convex polytope.
Definition convex.h:49
void fillNeighbors()
Definition convex.hxx:231
#define COAL_SERIALIZATION_DECLARE_EXPORT(T)
Definition fwd.h:30
std::shared_ptr< std::vector< double > > offsets
An array of the offsets to the normals of the polygon. Note: there are as many offsets as normals.
Definition geometric_shapes.h:726
std::shared_ptr< std::vector< Vec3s > > normals
An array of the normals of the polygon.
Definition geometric_shapes.h:723
unsigned int num_points
Definition geometric_shapes.h:720
std::vector< int > indices
Indices of the support points warm starts. These are the indices of the real convex,...
Definition geometric_shapes.h:750
std::vector< Vec3s > points
Array of support points to warm start the support function computation.
Definition geometric_shapes.h:745
unsigned int num_normals_and_offsets
Definition geometric_shapes.h:727
Vec3s center
center of the convex polytope, this is used for collision: center is guaranteed in the internal of th...
Definition geometric_shapes.h:736
std::shared_ptr< std::vector< Vec3s > > points
An array of the points of the polygon.
Definition geometric_shapes.h:719
SupportWarmStartPolytope support_warm_starts
Support warm start polytopes.
Definition geometric_shapes.h:757
Definition BV_splitter.h:15
Definition AABB.h:12
void serialize(Archive &ar, coal::AABB &aabb, const unsigned int)
Definition AABB.h:15
Definition AABB.h:11
Definition collision_data.h:1174
Main namespace.
Definition broadphase_bruteforce.h:44
double CoalScalar
Definition data_types.h:76
coal::Convex< PolygonT > Base
Definition convex.h:119
coal::ConvexBase Base
Definition convex.h:21
Quadrilateral with 4 indices for points.
Definition data_types.h:157