Directory: | ./ |
---|---|
File: | src/contact_patch/contact_patch_solver.cpp |
Date: | 2025-05-02 10:16:21 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 19 | 40 | 47.5% |
Branches: | 4 | 46 | 8.7% |
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 | 8 | 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 | 8 | const ShapeType* shape_ = static_cast<const ShapeType*>(shape); | |
51 | 8 | getShapeSupportSet<_SupportOptions>(shape_, support_set, hint, support_data, | |
52 | num_sampled_supports, tol); | ||
53 | } | ||
54 | |||
55 | /// @brief Templated shape support set functions for ConvexBase. | ||
56 | template <typename IndexType, | ||
57 | int _SupportOptions = SupportOptions::NoSweptSphere> | ||
58 | 36 | void getConvexBaseSupportSetTpl(const ShapeBase* shape, SupportSet& support_set, | |
59 | int& hint, ShapeSupportData& support_data, | ||
60 | size_t num_sampled_supports = 6, | ||
61 | Scalar tol = Scalar(1e-3)) { | ||
62 | 36 | const ConvexBaseTpl<IndexType>* convex = | |
63 | static_cast<const ConvexBaseTpl<IndexType>*>(shape); | ||
64 | |||
65 |
1/2✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
|
36 | if (support_data.polygon.capacity() < |
66 | ::coal::ContactPatchSolver::default_num_preallocated_supports) { | ||
67 | 36 | support_data.polygon.reserve( | |
68 | ::coal::ContactPatchSolver::default_num_preallocated_supports); | ||
69 | } | ||
70 | |||
71 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
|
36 | if ((size_t)(convex->num_points) > |
72 | ConvexBaseTpl<IndexType>::num_vertices_large_convex_threshold) { | ||
73 | ✗ | const LargeConvex<IndexType>* convex_ = | |
74 | static_cast<const LargeConvex<IndexType>*>(convex); | ||
75 | ✗ | support_data.visited.assign(convex_->num_points, false); | |
76 | ✗ | support_data.last_dir.setZero(); | |
77 | ✗ | return getShapeSupportSet<_SupportOptions>( | |
78 | ✗ | convex_, support_set, hint, support_data, num_sampled_supports, tol); | |
79 | } else { | ||
80 | 36 | const SmallConvex<IndexType>* convex_ = | |
81 | static_cast<const SmallConvex<IndexType>*>(convex); | ||
82 | 36 | return getShapeSupportSet<_SupportOptions>( | |
83 | 36 | convex_, support_set, hint, support_data, num_sampled_supports, tol); | |
84 | } | ||
85 | } | ||
86 | |||
87 | } // namespace details | ||
88 | |||
89 | // ============================================================================ | ||
90 | ContactPatchSolver::SupportSetFunction | ||
91 | 22 | ContactPatchSolver::makeSupportSetFunction(const ShapeBase* shape, | |
92 | ShapeSupportData& support_data) { | ||
93 | // Note: because the swept-sphere radius was already taken into account when | ||
94 | // constructing the contact patch frame, there is actually no need to take the | ||
95 | // swept-sphere radius of shapes into account. The origin of the contact patch | ||
96 | // frame already encodes this information. | ||
97 | using Options = details::SupportOptions; | ||
98 |
2/10✗ 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 not taken.
✓ Branch 9 taken 18 times.
✗ Branch 10 not taken.
|
22 | switch (shape->getNodeType()) { |
99 | ✗ | case GEOM_TRIANGLE: | |
100 | ✗ | return details::getShapeSupportSetTpl<TriangleP, Options::NoSweptSphere>; | |
101 | 4 | case GEOM_BOX: { | |
102 | 4 | const size_t num_corners_box = 8; | |
103 | 4 | support_data.polygon.reserve(num_corners_box); | |
104 | 4 | return details::getShapeSupportSetTpl<Box, Options::NoSweptSphere>; | |
105 | } | ||
106 | ✗ | case GEOM_SPHERE: | |
107 | ✗ | return details::getShapeSupportSetTpl<Sphere, Options::NoSweptSphere>; | |
108 | ✗ | case GEOM_ELLIPSOID: | |
109 | ✗ | return details::getShapeSupportSetTpl<Ellipsoid, Options::NoSweptSphere>; | |
110 | ✗ | case GEOM_CAPSULE: | |
111 | ✗ | return details::getShapeSupportSetTpl<Capsule, Options::NoSweptSphere>; | |
112 | ✗ | case GEOM_CONE: | |
113 | ✗ | return details::getShapeSupportSetTpl<Cone, Options::NoSweptSphere>; | |
114 | ✗ | case GEOM_CYLINDER: | |
115 | ✗ | return details::getShapeSupportSetTpl<Cylinder, Options::NoSweptSphere>; | |
116 | ✗ | case GEOM_CONVEX16: | |
117 | ✗ | return details::getConvexBaseSupportSetTpl<Triangle16::IndexType, | |
118 | Options::NoSweptSphere>; | ||
119 | 18 | case GEOM_CONVEX32: | |
120 | 18 | return details::getConvexBaseSupportSetTpl<Triangle32::IndexType, | |
121 | Options::NoSweptSphere>; | ||
122 | ✗ | default: | |
123 | ✗ | COAL_THROW_PRETTY("Unsupported geometric shape.", std::logic_error); | |
124 | } | ||
125 | } | ||
126 | |||
127 | } // namespace coal | ||
128 |