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
contact_patch.h
Go to the documentation of this file.
1//
2// Copyright (c) 2024 INRIA
3//
4
5#ifndef COAL_SERIALIZATION_CONTACT_PATCH_H
6#define COAL_SERIALIZATION_CONTACT_PATCH_H
7
11
12namespace boost {
13namespace serialization {
14
15template <class Archive>
16void 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 size_t patch_size = contact_patch.size();
22 ar& make_nvp("patch_size", patch_size);
23 if (patch_size > 0) {
24 if (Archive::is_loading::value) {
25 contact_patch.points().resize(patch_size);
26 }
27 Eigen::Map<PolygonPoints> points_map(
28 reinterpret_cast<Scalar*>(contact_patch.points().data()), 2,
29 static_cast<Eigen::Index>(patch_size));
30 ar& make_nvp("points", points_map);
31 }
32
33 ar& make_nvp("penetration_depth", contact_patch.penetration_depth);
34 ar& make_nvp("direction", contact_patch.direction);
35 ar& make_nvp("tf", contact_patch.tf);
36}
37
38template <class Archive>
39void serialize(Archive& ar, coal::ContactPatchRequest& request,
40 const unsigned int /*version*/) {
41 using namespace coal;
42
43 ar& make_nvp("max_num_patch", request.max_num_patch);
44
45 size_t num_samples_curved_shapes = request.getNumSamplesCurvedShapes();
46 Scalar patch_tolerance = request.getPatchTolerance();
47 ar& make_nvp("num_samples_curved_shapes", num_samples_curved_shapes);
48 ar& make_nvp("patch_tolerance", num_samples_curved_shapes);
49
50 if (Archive::is_loading::value) {
51 request.setNumSamplesCurvedShapes(num_samples_curved_shapes);
52 request.setPatchTolerance(patch_tolerance);
53 }
54}
55
56template <class Archive>
57void serialize(Archive& ar, coal::ContactPatchResult& result,
58 const unsigned int /*version*/) {
59 using namespace coal;
60
61 size_t num_patches = result.numContactPatches();
62 ar& make_nvp("num_patches", num_patches);
63
64 std::vector<ContactPatch> patches;
65 patches.resize(num_patches);
66 if (Archive::is_loading::value) {
67 ar& make_nvp("patches", patches);
68
69 const ContactPatchRequest request(num_patches);
70 result.set(request);
71 for (size_t i = 0; i < num_patches; ++i) {
72 ContactPatch& patch = result.getUnusedContactPatch();
73 patch = patches[i];
74 }
75 } else {
76 patches.clear();
77 for (size_t i = 0; i < num_patches; ++i) {
78 patches.emplace_back(result.getContactPatch(i));
79 }
80 ar& make_nvp("patches", patches);
81 }
82}
83
84} // namespace serialization
85} // namespace boost
86
87#endif // COAL_SERIALIZATION_CONTACT_PATCH_H
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
Request for a contact patch computation.
Definition collision_data.h:723
size_t getNumSamplesCurvedShapes() const
Maximum samples to compute the support sets of curved shapes, i.e. when the normal is perpendicular t...
Definition collision_data.h:792
size_t max_num_patch
Maximum number of contact patches that will be computed.
Definition collision_data.h:725
Scalar getPatchTolerance() const
Tolerance below which points are added to a contact patch. In details, given two shapes S1 and S2,...
Definition collision_data.h:809
void setNumSamplesCurvedShapes(const size_t num_samples_curved_shapes)
Maximum samples to compute the support sets of curved shapes, i.e. when the normal is perpendicular t...
Definition collision_data.h:780
void setPatchTolerance(const Scalar patch_tolerance)
Tolerance below which points are added to a contact patch. In details, given two shapes S1 and S2,...
Definition collision_data.h:797
Result for a contact patch computation.
Definition collision_data.h:821
size_t numContactPatches() const
Number of contact patches in the result.
Definition collision_data.h:858
ContactPatchRef getUnusedContactPatch()
Returns a new unused contact patch from the internal data vector.
Definition collision_data.h:861
void set(const ContactPatchRequest &request)
Set up a ContactPatchResult from a ContactPatchRequest
Definition collision_data.h:918
const ContactPatch & getContactPatch(const size_t i) const
Const getter for the i-th contact patch of the result.
Definition collision_data.h:881
This structure allows to encode contact patches. A contact patch is defined by a set of points belong...
Definition collision_data.h:511
PatchDirection direction
Direction of this contact patch.
Definition collision_data.h:531
Polygon & points()
Getter for the 2D points in the set.
Definition collision_data.h:615
size_t size() const
Returns the number of points in the contact patch.
Definition collision_data.h:576
Scalar penetration_depth
Penetration depth of the contact patch. This value corresponds to the signed distance d between the s...
Definition collision_data.h:544
Transform3s tf
Frame of the set, expressed in the world coordinates. The z-axis of the frame's rotation is the conta...
Definition collision_data.h:517
void clear()
Clear the set.
Definition collision_data.h:639