Directory: | ./ |
---|---|
File: | include/coal/serialization/contact_patch.h |
Date: | 2025-04-01 09:23:31 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 37 | 37 | 100.0% |
Branches: | 26 | 48 | 54.2% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // Copyright (c) 2024 INRIA | ||
3 | // | ||
4 | |||
5 | #ifndef COAL_SERIALIZATION_CONTACT_PATCH_H | ||
6 | #define COAL_SERIALIZATION_CONTACT_PATCH_H | ||
7 | |||
8 | #include "coal/collision_data.h" | ||
9 | #include "coal/serialization/fwd.h" | ||
10 | #include "coal/serialization/transform.h" | ||
11 | |||
12 | namespace boost { | ||
13 | namespace serialization { | ||
14 | |||
15 | template <class Archive> | ||
16 | 56 | void serialize(Archive& ar, coal::ContactPatch& contact_patch, | |
17 | const unsigned int /*version*/) { | ||
18 | using namespace coal; | ||
19 | typedef Eigen::Matrix<Scalar, 2, Eigen::Dynamic> PolygonPoints; | ||
20 | |||
21 | 56 | size_t patch_size = contact_patch.size(); | |
22 |
1/2✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
|
56 | ar& make_nvp("patch_size", patch_size); |
23 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
56 | if (patch_size > 0) { |
24 | if (Archive::is_loading::value) { | ||
25 |
1/2✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
|
28 | contact_patch.points().resize(patch_size); |
26 | } | ||
27 |
2/4✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 28 times.
✗ Branch 5 not taken.
|
112 | Eigen::Map<PolygonPoints> points_map( |
28 | 56 | reinterpret_cast<Scalar*>(contact_patch.points().data()), 2, | |
29 | static_cast<Eigen::Index>(patch_size)); | ||
30 |
1/2✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
|
56 | ar& make_nvp("points", points_map); |
31 | } | ||
32 | |||
33 |
1/2✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
|
56 | ar& make_nvp("penetration_depth", contact_patch.penetration_depth); |
34 |
1/2✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
|
56 | ar& make_nvp("direction", contact_patch.direction); |
35 |
1/2✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
|
56 | ar& make_nvp("tf", contact_patch.tf); |
36 | 56 | } | |
37 | |||
38 | template <class Archive> | ||
39 | 28 | void serialize(Archive& ar, coal::ContactPatchRequest& request, | |
40 | const unsigned int /*version*/) { | ||
41 | using namespace coal; | ||
42 | |||
43 |
1/2✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
|
28 | ar& make_nvp("max_num_patch", request.max_num_patch); |
44 | |||
45 | 28 | size_t num_samples_curved_shapes = request.getNumSamplesCurvedShapes(); | |
46 | 28 | Scalar patch_tolerance = request.getPatchTolerance(); | |
47 |
1/2✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
|
28 | ar& make_nvp("num_samples_curved_shapes", num_samples_curved_shapes); |
48 |
1/2✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
|
28 | ar& make_nvp("patch_tolerance", num_samples_curved_shapes); |
49 | |||
50 | if (Archive::is_loading::value) { | ||
51 | 14 | request.setNumSamplesCurvedShapes(num_samples_curved_shapes); | |
52 | 14 | request.setPatchTolerance(patch_tolerance); | |
53 | } | ||
54 | 28 | } | |
55 | |||
56 | template <class Archive> | ||
57 | 28 | void serialize(Archive& ar, coal::ContactPatchResult& result, | |
58 | const unsigned int /*version*/) { | ||
59 | using namespace coal; | ||
60 | |||
61 | 28 | size_t num_patches = result.numContactPatches(); | |
62 |
1/2✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
|
28 | ar& make_nvp("num_patches", num_patches); |
63 | |||
64 | 28 | std::vector<ContactPatch> patches; | |
65 |
1/2✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
|
28 | patches.resize(num_patches); |
66 | if (Archive::is_loading::value) { | ||
67 |
1/2✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
14 | ar& make_nvp("patches", patches); |
68 | |||
69 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | const ContactPatchRequest request(num_patches); |
70 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | result.set(request); |
71 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7 times.
|
28 | for (size_t i = 0; i < num_patches; ++i) { |
72 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | ContactPatch& patch = result.getUnusedContactPatch(); |
73 |
1/2✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
14 | patch = patches[i]; |
74 | } | ||
75 | } else { | ||
76 | 14 | patches.clear(); | |
77 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7 times.
|
28 | for (size_t i = 0; i < num_patches; ++i) { |
78 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
14 | patches.emplace_back(result.getContactPatch(i)); |
79 | } | ||
80 |
1/2✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
14 | ar& make_nvp("patches", patches); |
81 | } | ||
82 | 28 | } | |
83 | |||
84 | } // namespace serialization | ||
85 | } // namespace boost | ||
86 | |||
87 | #endif // COAL_SERIALIZATION_CONTACT_PATCH_H | ||
88 |