hpp-fcl  3.0.0
HPP fork of FCL -- The Flexible Collision Library
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 HPP_FCL_CONTACT_PATCH_SOLVER_H
37 #define HPP_FCL_CONTACT_PATCH_SOLVER_H
38 
39 #include "hpp/fcl/collision_data.h"
40 #include "hpp/fcl/logging.h"
42 
43 namespace hpp {
44 namespace fcl {
45 
61  // Note: `ContactPatch` is an alias for `SupportSet`.
62  // The two can be used interchangeably.
65 
85  typedef void (*SupportSetFunction)(const ShapeBase* shape,
86  SupportSet& support_set, int& hint,
87  ShapeSupportData& support_data,
88  size_t num_sampled_supports, FCL_REAL tol);
89 
91  static constexpr size_t default_num_preallocated_supports = 16;
92 
98 
102 
104  mutable SupportSetFunction supportFuncShape1;
105 
107  mutable SupportSetFunction supportFuncShape2;
108 
110  mutable std::array<ShapeSupportData, 2> supports_data;
111 
114 
118 
122 
125 
130  mutable std::vector<bool> added_to_patch;
131 
133  explicit ContactPatchSolver() {
134  const size_t num_contact_patch = 1;
135  const size_t preallocated_patch_size =
137  const FCL_REAL patch_tolerance = 1e-3;
138  const ContactPatchRequest request(num_contact_patch,
139  preallocated_patch_size, patch_tolerance);
140  this->set(request);
141  }
142 
144  explicit ContactPatchSolver(const ContactPatchRequest& request) {
145  this->set(request);
146  }
147 
149  void set(const ContactPatchRequest& request);
150 
153  void setSupportGuess(const support_func_guess_t guess) const {
154  this->support_guess = guess;
155  }
156 
162  template <typename ShapeType1, typename ShapeType2>
163  void computePatch(const ShapeType1& s1, const Transform3f& tf1,
164  const ShapeType2& s2, const Transform3f& tf2,
165  const Contact& contact, ContactPatch& contact_patch) const;
166 
168  template <typename ShapeType1, typename ShapeType2>
169  void reset(const ShapeType1& shape1, const Transform3f& tf1,
170  const ShapeType2& shape2, const Transform3f& tf2,
171  const ContactPatch& contact_patch) const;
172 
175  void getResult(const Contact& contact, const ContactPatch::Polygon* result,
176  ContactPatch& contact_patch) const;
177 
183  static Vec2f computeLineSegmentIntersection(const Vec2f& a, const Vec2f& b,
184  const Vec2f& c, const Vec2f& d);
185 
187  static SupportSetFunction makeSupportSetFunction(
188  const ShapeBase* shape, ShapeSupportData& support_data);
189 
190  bool operator==(const ContactPatchSolver& other) const {
191  return this->num_samples_curved_shapes == other.num_samples_curved_shapes &&
192  this->patch_tolerance == other.patch_tolerance &&
193  this->support_guess == other.support_guess &&
194  this->support_set_shape1 == other.support_set_shape1 &&
195  this->support_set_shape2 == other.support_set_shape2 &&
196  this->support_set_buffer == other.support_set_buffer &&
197  this->added_to_patch == other.added_to_patch &&
198  this->supportFuncShape1 == other.supportFuncShape1 &&
199  this->supportFuncShape2 == other.supportFuncShape2;
200  }
201 
202  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
203 };
204 
205 } // namespace fcl
206 } // namespace hpp
207 
209 
210 #endif // HPP_FCL_CONTACT_PATCH_SOLVER_H
Base class for all basic geometric shapes.
Definition: geometric_shapes.h:59
Simple transform class used locally by InterpMotion.
Definition: transform.h:56
#define HPP_FCL_DLLAPI
Definition: config.hh:88
Eigen::Matrix< FCL_REAL, 2, 1 > Vec2f
Definition: data_types.h:68
double FCL_REAL
Definition: data_types.h:66
Eigen::Vector2i support_func_guess_t
Definition: data_types.h:77
Main namespace.
Definition: broadphase_bruteforce.h:44
Request for a contact patch computation.
Definition: collision_data.h:726
Solver to compute contact patches, i.e. the intersection between two contact surfaces projected onto ...
Definition: contact_patch_solver.h:60
SupportSet support_set_buffer
Temporary support set used for the Sutherland-Hodgman algorithm.
Definition: contact_patch_solver.h:124
SupportSetFunction supportFuncShape2
Support set function for shape s2.
Definition: contact_patch_solver.h:107
ContactPatchSolver(const ContactPatchRequest &request)
Construct the solver with a ContactPatchRequest.
Definition: contact_patch_solver.h:144
SupportSetFunction supportFuncShape1
Support set function for shape s1.
Definition: contact_patch_solver.h:104
FCL_REAL patch_tolerance
Tolerance below which points are added to the shapes support sets. See ContactPatchRequest::m_patch_t...
Definition: contact_patch_solver.h:101
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:121
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:113
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:117
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:130
ContactPatchSolver()
Default constructor.
Definition: contact_patch_solver.h:133
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:97
bool operator==(const ContactPatchSolver &other) const
Definition: contact_patch_solver.h:190
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:153
std::array< ShapeSupportData, 2 > supports_data
Temporary data to compute the support sets on each shape.
Definition: contact_patch_solver.h:110
This structure allows to encode contact patches. A contact patch is defined by a set of points belong...
Definition: collision_data.h:512
static constexpr size_t default_preallocated_size
Default maximum size of the polygon representing the contact patch. Used to pre-allocate memory for t...
Definition: collision_data.h:549
PatchDirection
Direction of ContactPatch. When doing collision detection, the convention of HPP-FCL is that the norm...
Definition: collision_data.h:529
std::vector< Vec2f > Polygon
Definition: collision_data.h:514
Contact information returned by collision.
Definition: collision_data.h:59
Stores temporary data for the computation of support points.
Definition: support_functions.h:81