GCC Code Coverage Report


Directory: ./
File: include/coal/serialization/convex.h
Date: 2025-04-01 09:23:31
Exec Total Coverage
Lines: 39 61 63.9%
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 struct ConvexBaseAccessor : coal::ConvexBase {
21 typedef coal::ConvexBase Base;
22 };
23
24 } // namespace internal
25
26 template <class Archive>
27 4 void serialize(Archive& ar, coal::ConvexBase& convex_base,
28 const unsigned int /*version*/) {
29 using namespace coal;
30
31
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 ar& make_nvp("base",
32
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 boost::serialization::base_object<coal::ShapeBase>(convex_base));
33
34 4 const unsigned int num_points_previous = convex_base.num_points;
35
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 ar& make_nvp("num_points", convex_base.num_points);
36
37 4 const unsigned int num_normals_and_offsets_previous =
38 convex_base.num_normals_and_offsets;
39
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);
40
41 4 const int num_warm_start_supports_previous =
42 4 static_cast<int>(convex_base.support_warm_starts.points.size());
43
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
4 assert(num_warm_start_supports_previous ==
44 static_cast<int>(convex_base.support_warm_starts.indices.size()));
45 4 int num_warm_start_supports = num_warm_start_supports_previous;
46
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 ar& make_nvp("num_warm_start_supports", num_warm_start_supports);
47
48 if (Archive::is_loading::value) {
49
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
2 if (num_points_previous != convex_base.num_points) {
50 2 convex_base.points.reset();
51
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
2 if (convex_base.num_points > 0)
52
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
4 convex_base.points.reset(
53
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));
54 }
55
56 2 if (num_normals_and_offsets_previous !=
57
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
2 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<Scalar>(convex_base.num_normals_and_offsets));
65 }
66 }
67
68
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
2 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<Scalar, 3, Eigen::Dynamic> MatrixPoints;
77
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
4 if (convex_base.num_points > 0) {
78
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(
79 4 reinterpret_cast<Scalar*>(convex_base.points->data()), 3,
80 4 convex_base.num_points);
81
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 ar& make_nvp("points", points_map);
82 }
83
84 typedef Eigen::Matrix<Scalar, 1, Eigen::Dynamic> VecOfReals;
85
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
4 if (convex_base.num_normals_and_offsets > 0) {
86 Eigen::Map<MatrixPoints> normals_map(
87 reinterpret_cast<Scalar*>(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<Scalar*>(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
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
4 if (num_warm_start_supports > 0) {
99 Eigen::Map<MatrixPoints> warm_start_support_points_map(
100 reinterpret_cast<Scalar*>(
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
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 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> {
119 typedef coal::Convex<PolygonT> Base;
120 using Base::fillNeighbors;
121 };
122
123 } // namespace internal
124
125 template <class Archive, typename PolygonT>
126 4 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 4 Accessor& convex = reinterpret_cast<Accessor&>(convex_);
132
1/2
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
4 ar& make_nvp("base", boost::serialization::base_object<ConvexBase>(convex_));
133
134 4 const unsigned int num_polygons_previous = convex.num_polygons;
135
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 ar& make_nvp("num_polygons", convex.num_polygons);
136
137 if (Archive::is_loading::value) {
138
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
2 if (num_polygons_previous != convex.num_polygons) {
139
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));
140 }
141 }
142
143
1/2
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
4 ar& make_array<PolygonT>(convex.polygons->data(), convex.num_polygons);
144
145 2 if (Archive::is_loading::value) convex.fillNeighbors();
146 }
147
148 } // namespace serialization
149 } // namespace boost
150
151 36 COAL_SERIALIZATION_DECLARE_EXPORT(coal::Convex<coal::Triangle>)
152 36 COAL_SERIALIZATION_DECLARE_EXPORT(coal::Convex<coal::Quadrilateral>)
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
168