coal/serialization/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 
10 #include "coal/serialization/fwd.h"
15 
16 namespace boost {
17 namespace serialization {
18 
19 namespace internal {
22 };
23 
24 } // namespace internal
25 
26 template <class Archive>
27 void 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 
116 namespace internal {
117 template <typename PolygonT>
118 struct ConvexAccessor : coal::Convex<PolygonT> {
120  using Base::fillNeighbors;
121 };
122 
123 } // namespace internal
124 
125 template <class Archive, typename PolygonT>
126 void serialize(Archive& ar, coal::Convex<PolygonT>& convex_,
127  const unsigned int /*version*/) {
128  using namespace coal;
129  typedef internal::ConvexAccessor<PolygonT> Accessor;
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 
154 namespace 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
fwd.h
memory.h
coal::ConvexBase::num_points
unsigned int num_points
Definition: coal/shape/geometric_shapes.h:720
boost::serialization::serialize
void serialize(Archive &ar, coal::AABB &aabb, const unsigned int)
Definition: coal/serialization/AABB.h:15
quadrilateral.h
coal
Main namespace.
Definition: coal/broadphase/broadphase_bruteforce.h:44
boost
COAL_SERIALIZATION_DECLARE_EXPORT
#define COAL_SERIALIZATION_DECLARE_EXPORT(T)
Definition: coal/serialization/fwd.h:30
coal::ConvexBase::normals
std::shared_ptr< std::vector< Vec3s > > normals
An array of the normals of the polygon.
Definition: coal/shape/geometric_shapes.h:723
convex.h
boost::serialization::internal::ConvexAccessor::Base
coal::Convex< PolygonT > Base
Definition: coal/serialization/convex.h:119
coal::ConvexBase::num_normals_and_offsets
unsigned int num_normals_and_offsets
Definition: coal/shape/geometric_shapes.h:727
boost::serialization::internal::ConvexBaseAccessor
Definition: coal/serialization/convex.h:20
coal::Convex
Convex polytope.
Definition: coal/serialization/collision_object.h:51
coal::ConvexBase::center
Vec3s center
center of the convex polytope, this is used for collision: center is guaranteed in the internal of th...
Definition: coal/shape/geometric_shapes.h:736
coal::ConvexBase::SupportWarmStartPolytope::points
std::vector< Vec3s > points
Array of support points to warm start the support function computation.
Definition: coal/shape/geometric_shapes.h:745
boost::serialization::internal::ConvexAccessor
Definition: coal/serialization/convex.h:118
coal::ConvexBase::offsets
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: coal/shape/geometric_shapes.h:726
boost::serialization::internal::ConvexBaseAccessor::Base
coal::ConvexBase Base
Definition: coal/serialization/convex.h:21
coal::ConvexBase::SupportWarmStartPolytope::indices
std::vector< int > indices
Indices of the support points warm starts. These are the indices of the real convex,...
Definition: coal/shape/geometric_shapes.h:750
geometric_shapes.h
coal::ConvexBase::support_warm_starts
SupportWarmStartPolytope support_warm_starts
Support warm start polytopes.
Definition: coal/shape/geometric_shapes.h:757
coal::ConvexBase::points
std::shared_ptr< std::vector< Vec3s > > points
An array of the points of the polygon.
Definition: coal/shape/geometric_shapes.h:719
coal::CoalScalar
double CoalScalar
Definition: coal/data_types.h:76
coal::Convex::fillNeighbors
void fillNeighbors()
coal::ConvexBase
Base for convex polytope.
Definition: coal/shape/geometric_shapes.h:645
triangle.h


hpp-fcl
Author(s):
autogenerated on Sat Nov 23 2024 03:44:57