GCC Code Coverage Report


Directory: ./
File: include/coal/serialization/convex.h
Date: 2025-05-02 10:16:21
Exec Total Coverage
Lines: 41 64 64.1%
Branches: 27 96 28.1%

Line Branch Exec Source
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"
11 #include "coal/serialization/geometric_shapes.h"
12 #include "coal/serialization/memory.h"
13 #include "coal/serialization/triangle.h"
14 #include "coal/serialization/quadrilateral.h"
15
16 namespace boost {
17 namespace serialization {
18
19 namespace internal {
20 template <typename IndexType>
21 struct ConvexBaseAccessor : coal::ConvexBaseTpl<IndexType> {
22 typedef coal::ConvexBaseTpl<IndexType> Base;
23 };
24
25 } // namespace internal
26
27 template <class Archive, typename IndexType>
28 4 void serialize(Archive& ar, coal::ConvexBaseTpl<IndexType>& convex_base,
29 const unsigned int /*version*/) {
30 using namespace coal;
31
32
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 ar& make_nvp("base",
33
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 boost::serialization::base_object<coal::ShapeBase>(convex_base));
34
35 4 const unsigned int num_points_previous = convex_base.num_points;
36
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 ar& make_nvp("num_points", convex_base.num_points);
37
38 4 const unsigned int num_normals_and_offsets_previous =
39 convex_base.num_normals_and_offsets;
40
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 ar& make_nvp("num_normals_and_offsets", convex_base.num_normals_and_offsets);
41
42 4 const int num_warm_start_supports_previous =
43 4 static_cast<int>(convex_base.support_warm_starts.points.size());
44
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
4 assert(num_warm_start_supports_previous ==
45 static_cast<int>(convex_base.support_warm_starts.indices.size()));
46 4 int num_warm_start_supports = num_warm_start_supports_previous;
47
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 ar& make_nvp("num_warm_start_supports", num_warm_start_supports);
48
49 if (Archive::is_loading::value) {
50
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
2 if (num_points_previous != convex_base.num_points) {
51 2 convex_base.points.reset();
52
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
2 if (convex_base.num_points > 0)
53
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
4 convex_base.points.reset(
54
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 new std::vector<Vec3s>(convex_base.num_points));
55 }
56
57 2 if (num_normals_and_offsets_previous !=
58
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
2 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
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
2 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
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
4 if (convex_base.num_points > 0) {
79
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
8 Eigen::Map<MatrixPoints> points_map(
80 4 reinterpret_cast<Scalar*>(convex_base.points->data()), 3,
81 4 convex_base.num_points);
82
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 ar& make_nvp("points", points_map);
83 }
84
85 typedef Eigen::Matrix<Scalar, 1, Eigen::Dynamic> VecOfReals;
86
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
4 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
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
4 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
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 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
117 namespace internal {
118 template <typename PolygonT>
119 struct ConvexAccessor : coal::ConvexTpl<PolygonT> {
120 typedef coal::ConvexTpl<PolygonT> Base;
121 using Base::fillNeighbors;
122 };
123
124 } // namespace internal
125
126 template <class Archive, typename PolygonT>
127 4 void serialize(Archive& ar, coal::ConvexTpl<PolygonT>& convex_,
128 const unsigned int /*version*/) {
129 using namespace coal;
130 typedef internal::ConvexAccessor<PolygonT> Accessor;
131 typedef ConvexBaseTpl<typename PolygonT::IndexType> Base;
132
133 4 Accessor& convex = reinterpret_cast<Accessor&>(convex_);
134
1/2
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
4 ar& make_nvp("base", boost::serialization::base_object<Base>(convex_));
135
136 4 const unsigned int num_polygons_previous = convex.num_polygons;
137
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 ar& make_nvp("num_polygons", convex.num_polygons);
138
139 if (Archive::is_loading::value) {
140
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
2 if (num_polygons_previous != convex.num_polygons) {
141
3/6
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
2 convex.polygons.reset(new std::vector<PolygonT>(convex.num_polygons));
142 }
143 }
144
145
1/2
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
4 ar& make_array<PolygonT>(convex.polygons->data(), convex.num_polygons);
146
147 2 if (Archive::is_loading::value) convex.fillNeighbors();
148 }
149
150 } // namespace serialization
151 } // namespace boost
152
153 36 COAL_SERIALIZATION_DECLARE_EXPORT(coal::ConvexTpl<coal::Triangle16>)
154 36 COAL_SERIALIZATION_DECLARE_EXPORT(coal::ConvexTpl<coal::Triangle32>)
155 36 COAL_SERIALIZATION_DECLARE_EXPORT(coal::ConvexTpl<coal::Quadrilateral16>)
156 36 COAL_SERIALIZATION_DECLARE_EXPORT(coal::ConvexTpl<coal::Quadrilateral32>)
157
158 namespace 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
172