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_solver.h
Go to the documentation of this file.
1/*
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2024, INRIA
5 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials provided
15 * with the distribution.
16 * * Neither the name of INRIA nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
36#ifndef COAL_CONTACT_PATCH_SOLVER_H
37#define COAL_CONTACT_PATCH_SOLVER_H
38
39#include "coal/collision_data.h"
40#include "coal/logging.h"
42
43namespace coal {
44
60 // Note: `ContactPatch` is an alias for `SupportSet`.
61 // The two can be used interchangeably.
64
84 typedef void (*SupportSetFunction)(const ShapeBase* shape,
85 SupportSet& support_set, int& hint,
86 ShapeSupportData& support_data,
87 size_t num_sampled_supports, Scalar tol);
88
90 static constexpr size_t default_num_preallocated_supports = 16;
91
97
101
103 mutable SupportSetFunction supportFuncShape1;
104
106 mutable SupportSetFunction supportFuncShape2;
107
109 mutable std::array<ShapeSupportData, 2> supports_data;
110
113
117
121
124
129 mutable std::vector<bool> added_to_patch;
130
133 const size_t num_contact_patch = 1;
134 const size_t preallocated_patch_size =
135 ContactPatch::default_preallocated_size;
136 const Scalar patch_tolerance = Scalar(1e-3);
137 const ContactPatchRequest request(num_contact_patch,
138 preallocated_patch_size, patch_tolerance);
139 this->set(request);
140 }
141
143 explicit ContactPatchSolver(const ContactPatchRequest& request) {
144 this->set(request);
145 }
146
148 void set(const ContactPatchRequest& request);
149
152 void setSupportGuess(const support_func_guess_t guess) const {
153 this->support_guess = guess;
154 }
155
161 template <typename ShapeType1, typename ShapeType2>
162 void computePatch(const ShapeType1& s1, const Transform3s& tf1,
163 const ShapeType2& s2, const Transform3s& tf2,
164 const Contact& contact, ContactPatch& contact_patch) const;
165
167 template <typename ShapeType1, typename ShapeType2>
168 void reset(const ShapeType1& shape1, const Transform3s& tf1,
169 const ShapeType2& shape2, const Transform3s& tf2,
170 const ContactPatch& contact_patch) const;
171
174 void getResult(const Contact& contact, const ContactPatch::Polygon* result,
175 ContactPatch& contact_patch) const;
176
182 static Vec2s computeLineSegmentIntersection(const Vec2s& a, const Vec2s& b,
183 const Vec2s& c, const Vec2s& d);
184
186 static SupportSetFunction makeSupportSetFunction(
187 const ShapeBase* shape, ShapeSupportData& support_data);
188
189 bool operator==(const ContactPatchSolver& other) const {
190 return this->num_samples_curved_shapes == other.num_samples_curved_shapes &&
191 this->patch_tolerance == other.patch_tolerance &&
192 this->support_guess == other.support_guess &&
193 this->support_set_shape1 == other.support_set_shape1 &&
194 this->support_set_shape2 == other.support_set_shape2 &&
195 this->support_set_buffer == other.support_set_buffer &&
196 this->added_to_patch == other.added_to_patch &&
197 this->supportFuncShape1 == other.supportFuncShape1 &&
198 this->supportFuncShape2 == other.supportFuncShape2;
199 }
200
201 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
202};
203
204} // namespace coal
205
207
208#endif // COAL_CONTACT_PATCH_SOLVER_H
Base class for all basic geometric shapes.
Definition geometric_shapes.h:58
Simple transform class used locally by InterpMotion.
Definition transform.h:55
#define COAL_DLLAPI
Definition config.hh:88
Main namespace.
Definition broadphase_bruteforce.h:44
double Scalar
Definition data_types.h:68
Eigen::Vector2i support_func_guess_t
Definition data_types.h:80
Eigen::Matrix< Scalar, 2, 1 > Vec2s
Definition data_types.h:71
Request for a contact patch computation.
Definition collision_data.h:723
Solver to compute contact patches, i.e. the intersection between two contact surfaces projected onto ...
Definition contact_patch_solver.h:59
size_t num_samples_curved_shapes
Number of points sampled for Cone and Cylinder when the normal is orthogonal to the shapes' basis....
Definition contact_patch_solver.h:96
SupportSetFunction supportFuncShape2
Support set function for shape s2.
Definition contact_patch_solver.h:106
ContactPatchSolver(const ContactPatchRequest &request)
Construct the solver with a ContactPatchRequest.
Definition contact_patch_solver.h:143
void setSupportGuess(const support_func_guess_t guess) const
Sets the support guess used during support set computation of shapes s1 and s2.
Definition contact_patch_solver.h:152
std::array< ShapeSupportData, 2 > supports_data
Temporary data to compute the support sets on each shape.
Definition contact_patch_solver.h:109
Scalar patch_tolerance
Tolerance below which points are added to the shapes support sets. See ContactPatchRequest::m_patch_t...
Definition contact_patch_solver.h:100
bool operator==(const ContactPatchSolver &other) const
Definition contact_patch_solver.h:189
SupportSet support_set_shape1
Holder for support set of shape 1, used for internal computation. After computePatch has been called,...
Definition contact_patch_solver.h:116
static SupportSetFunction makeSupportSetFunction(const ShapeBase *shape, ShapeSupportData &support_data)
Construct support set function for shape.
support_func_guess_t support_guess
Guess for the support sets computation.
Definition contact_patch_solver.h:112
SupportSet support_set_shape2
Holder for support set of shape 2, used for internal computation. After computePatch has been called,...
Definition contact_patch_solver.h:120
SupportSetFunction supportFuncShape1
Support set function for shape s1.
Definition contact_patch_solver.h:103
SupportSet support_set_buffer
Temporary support set used for the Sutherland-Hodgman algorithm.
Definition contact_patch_solver.h:123
ContactPatchSolver()
Default constructor.
Definition contact_patch_solver.h:132
std::vector< bool > added_to_patch
Tracks which point of the Sutherland-Hodgman result have been added to the contact patch....
Definition contact_patch_solver.h:129
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 of ContactPatch. When doing collision detection, the convention of Coal is that the normal ...
Definition collision_data.h:528
std::vector< Vec2s > Polygon
Definition collision_data.h:513
Contact information returned by collision.
Definition collision_data.h:58
Stores temporary data for the computation of support points.
Definition support_data.h:62