Directory: | ./ |
---|---|
File: | src/contact_patch/contact_patch_solver.cpp |
Date: | 2025-04-01 09:23:31 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 15 | 32 | 46.9% |
Branches: | 4 | 45 | 8.9% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Software License Agreement (BSD License) | ||
3 | * | ||
4 | * Copyright (c) 2024, INRIA | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * | ||
11 | * * Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * * Redistributions in binary form must reproduce the above | ||
14 | * copyright notice, this list of conditions and the following | ||
15 | * disclaimer in the documentation and/or other materials provided | ||
16 | * with the distribution. | ||
17 | * * Neither the name of INRIA nor the names of its | ||
18 | * contributors may be used to endorse or promote products derived | ||
19 | * from this software without specific prior written permission. | ||
20 | * | ||
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
24 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
25 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
31 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
32 | * POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | |||
35 | /** \authors Louis Montaut */ | ||
36 | |||
37 | #include "coal/contact_patch/contact_patch_solver.h" | ||
38 | |||
39 | namespace coal { | ||
40 | |||
41 | namespace details { | ||
42 | |||
43 | /// @brief Templated shape support set functions. | ||
44 | template <typename ShapeType, | ||
45 | int _SupportOptions = SupportOptions::NoSweptSphere> | ||
46 | 44 | void getShapeSupportSetTpl(const ShapeBase* shape, SupportSet& support_set, | |
47 | int& hint, ShapeSupportData& support_data, | ||
48 | size_t num_sampled_supports = 6, | ||
49 | Scalar tol = Scalar(1e-3)) { | ||
50 | 44 | const ShapeType* shape_ = static_cast<const ShapeType*>(shape); | |
51 | 44 | getShapeSupportSet<_SupportOptions>(shape_, support_set, hint, support_data, | |
52 | num_sampled_supports, tol); | ||
53 | } | ||
54 | |||
55 | } // namespace details | ||
56 | |||
57 | // ============================================================================ | ||
58 | ContactPatchSolver::SupportSetFunction | ||
59 | 22 | ContactPatchSolver::makeSupportSetFunction(const ShapeBase* shape, | |
60 | ShapeSupportData& support_data) { | ||
61 | // Note: because the swept-sphere radius was already taken into account when | ||
62 | // constructing the contact patch frame, there is actually no need to take the | ||
63 | // swept-sphere radius of shapes into account. The origin of the contact patch | ||
64 | // frame already encodes this information. | ||
65 | using Options = details::SupportOptions; | ||
66 |
2/9✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 18 times.
✗ Branch 9 not taken.
|
22 | switch (shape->getNodeType()) { |
67 | ✗ | case GEOM_TRIANGLE: | |
68 | ✗ | return details::getShapeSupportSetTpl<TriangleP, Options::NoSweptSphere>; | |
69 | 4 | case GEOM_BOX: { | |
70 | 4 | const size_t num_corners_box = 8; | |
71 | 4 | support_data.polygon.reserve(num_corners_box); | |
72 | 4 | return details::getShapeSupportSetTpl<Box, Options::NoSweptSphere>; | |
73 | } | ||
74 | ✗ | case GEOM_SPHERE: | |
75 | ✗ | return details::getShapeSupportSetTpl<Sphere, Options::NoSweptSphere>; | |
76 | ✗ | case GEOM_ELLIPSOID: | |
77 | ✗ | return details::getShapeSupportSetTpl<Ellipsoid, Options::NoSweptSphere>; | |
78 | ✗ | case GEOM_CAPSULE: | |
79 | ✗ | return details::getShapeSupportSetTpl<Capsule, Options::NoSweptSphere>; | |
80 | ✗ | case GEOM_CONE: | |
81 | ✗ | return details::getShapeSupportSetTpl<Cone, Options::NoSweptSphere>; | |
82 | ✗ | case GEOM_CYLINDER: | |
83 | ✗ | return details::getShapeSupportSetTpl<Cylinder, Options::NoSweptSphere>; | |
84 | 18 | case GEOM_CONVEX: { | |
85 | 18 | const ConvexBase* convex = static_cast<const ConvexBase*>(shape); | |
86 |
1/2✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
|
18 | if (support_data.polygon.capacity() < default_num_preallocated_supports) { |
87 | 18 | support_data.polygon.reserve(default_num_preallocated_supports); | |
88 | } | ||
89 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
|
18 | if ((size_t)(convex->num_points) > |
90 | ConvexBase::num_vertices_large_convex_threshold) { | ||
91 | ✗ | support_data.visited.assign(convex->num_points, false); | |
92 | ✗ | support_data.last_dir.setZero(); | |
93 | ✗ | return details::getShapeSupportSetTpl<details::LargeConvex, | |
94 | Options::NoSweptSphere>; | ||
95 | } else { | ||
96 | 18 | return details::getShapeSupportSetTpl<details::SmallConvex, | |
97 | Options::NoSweptSphere>; | ||
98 | } | ||
99 | } | ||
100 | ✗ | default: | |
101 | ✗ | COAL_THROW_PRETTY("Unsupported geometric shape.", std::logic_error); | |
102 | } | ||
103 | } | ||
104 | |||
105 | } // namespace coal | ||
106 |