coal 3.0.1
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
8#include "coal/shape/convex.h"
9
15
16namespace boost {
17namespace serialization {
18
19namespace internal {
20template <typename IndexType>
24
25} // namespace internal
26
27template <class Archive, typename IndexType>
28void serialize(Archive& ar, coal::ConvexBaseTpl<IndexType>& convex_base,
29 const unsigned int /*version*/) {
30 using namespace coal;
31
32 ar& make_nvp("base",
33 boost::serialization::base_object<coal::ShapeBase>(convex_base));
34
35 const unsigned int num_points_previous = convex_base.num_points;
36 ar& make_nvp("num_points", convex_base.num_points);
37
38 const unsigned int num_normals_and_offsets_previous =
39 convex_base.num_normals_and_offsets;
40 ar& make_nvp("num_normals_and_offsets", convex_base.num_normals_and_offsets);
41
42 const int num_warm_start_supports_previous =
43 static_cast<int>(convex_base.support_warm_starts.points.size());
44 assert(num_warm_start_supports_previous ==
45 static_cast<int>(convex_base.support_warm_starts.indices.size()));
46 int num_warm_start_supports = num_warm_start_supports_previous;
47 ar& make_nvp("num_warm_start_supports", num_warm_start_supports);
48
49 if (Archive::is_loading::value) {
50 if (num_points_previous != convex_base.num_points) {
51 convex_base.points.reset();
52 if (convex_base.num_points > 0)
53 convex_base.points.reset(
54 new std::vector<Vec3s>(convex_base.num_points));
55 }
56
57 if (num_normals_and_offsets_previous !=
58 convex_base.num_normals_and_offsets) {
59 convex_base.normals.reset();
60 convex_base.offsets.reset();
61 if (convex_base.num_normals_and_offsets > 0) {
62 convex_base.normals.reset(
63 new std::vector<Vec3s>(convex_base.num_normals_and_offsets));
64 convex_base.offsets.reset(
65 new std::vector<Scalar>(convex_base.num_normals_and_offsets));
66 }
67 }
68
69 if (num_warm_start_supports_previous != num_warm_start_supports) {
70 convex_base.support_warm_starts.points.resize(
71 static_cast<size_t>(num_warm_start_supports));
72 convex_base.support_warm_starts.indices.resize(
73 static_cast<size_t>(num_warm_start_supports));
74 }
75 }
76
77 typedef Eigen::Matrix<Scalar, 3, Eigen::Dynamic> MatrixPoints;
78 if (convex_base.num_points > 0) {
79 Eigen::Map<MatrixPoints> points_map(
80 reinterpret_cast<Scalar*>(convex_base.points->data()), 3,
81 convex_base.num_points);
82 ar& make_nvp("points", points_map);
83 }
84
85 typedef Eigen::Matrix<Scalar, 1, Eigen::Dynamic> VecOfReals;
86 if (convex_base.num_normals_and_offsets > 0) {
87 Eigen::Map<MatrixPoints> normals_map(
88 reinterpret_cast<Scalar*>(convex_base.normals->data()), 3,
89 convex_base.num_normals_and_offsets);
90 ar& make_nvp("normals", normals_map);
91
92 Eigen::Map<VecOfReals> offsets_map(
93 reinterpret_cast<Scalar*>(convex_base.offsets->data()), 1,
94 convex_base.num_normals_and_offsets);
95 ar& make_nvp("offsets", offsets_map);
96 }
97
98 typedef Eigen::Matrix<int, 1, Eigen::Dynamic> VecOfInts;
99 if (num_warm_start_supports > 0) {
100 Eigen::Map<MatrixPoints> warm_start_support_points_map(
101 reinterpret_cast<Scalar*>(
102 convex_base.support_warm_starts.points.data()),
103 3, num_warm_start_supports);
104 ar& make_nvp("warm_start_support_points", warm_start_support_points_map);
105
106 Eigen::Map<VecOfInts> warm_start_support_indices_map(
107 reinterpret_cast<int*>(convex_base.support_warm_starts.indices.data()),
108 1, num_warm_start_supports);
109 ar& make_nvp("warm_start_support_indices", warm_start_support_indices_map);
110 }
111
112 ar& make_nvp("center", convex_base.center);
113 // We don't save neighbors as they will be computed directly by calling
114 // fillNeighbors.
115}
116
117namespace internal {
118template <typename PolygonT>
123
124} // namespace internal
125
126template <class Archive, typename PolygonT>
127void serialize(Archive& ar, coal::ConvexTpl<PolygonT>& convex_,
128 const unsigned int /*version*/) {
129 using namespace coal;
130 typedef internal::ConvexAccessor<PolygonT> Accessor;
132
133 Accessor& convex = reinterpret_cast<Accessor&>(convex_);
134 ar& make_nvp("base", boost::serialization::base_object<Base>(convex_));
135
136 const unsigned int num_polygons_previous = convex.num_polygons;
137 ar& make_nvp("num_polygons", convex.num_polygons);
138
139 if (Archive::is_loading::value) {
140 if (num_polygons_previous != convex.num_polygons) {
141 convex.polygons.reset(new std::vector<PolygonT>(convex.num_polygons));
142 }
143 }
144
145 ar& make_array<PolygonT>(convex.polygons->data(), convex.num_polygons);
146
147 if (Archive::is_loading::value) convex.fillNeighbors();
148}
149
150} // namespace serialization
151} // namespace boost
152
157
158namespace coal {
159
160// namespace internal {
161// template <typename BV>
162// struct memory_footprint_evaluator< ::coal::BVHModel<BV> > {
163// static size_t run(const ::coal::BVHModel<BV> &bvh_model) {
164// return static_cast<size_t>(bvh_model.memUsage(false));
165// }
166// };
167// } // namespace internal
168
169} // namespace coal
170
171#endif // ifndef COAL_SERIALIZATION_CONVEX_H
Base for convex polytope.
Definition geometric_shapes.h:691
unsigned int num_points
Definition geometric_shapes.h:797
std::shared_ptr< std::vector< Vec3s > > normals
An array of the normals of the polygon.
Definition geometric_shapes.h:800
SupportWarmStartPolytope support_warm_starts
Support warm start polytopes.
Definition geometric_shapes.h:822
std::shared_ptr< std::vector< Vec3s > > points
An array of the points of the polygon.
Definition geometric_shapes.h:796
Vec3s center
center of the convex polytope, this is used for collision: center is guaranteed in the internal of th...
Definition geometric_shapes.h:813
std::shared_ptr< std::vector< Scalar > > offsets
An array of the offsets to the normals of the polygon. Note: there are as many offsets as normals.
Definition geometric_shapes.h:803
unsigned int num_normals_and_offsets
Definition geometric_shapes.h:804
Convex polytope.
Definition convex.h:50
void fillNeighbors()
Definition convex.hxx:266
#define COAL_SERIALIZATION_DECLARE_EXPORT(T)
Definition fwd.h:30
void serialize(Archive &ar, coal::AABB &aabb, const unsigned int)
Definition AABB.h:15
Definition AABB.h:11
Main namespace.
Definition broadphase_bruteforce.h:44
double Scalar
Definition data_types.h:68
coal::ConvexTpl< PolygonT > Base
Definition convex.h:120
coal::ConvexBaseTpl< IndexType > Base
Definition convex.h:22
std::vector< Vec3s > points
Definition geometric_shapes.h:666
std::vector< IndexType > indices
Definition geometric_shapes.h:671
Quadrilateral with 4 indices for points.
Definition data_types.h:212