GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/hpp/fcl/broadphase/default_broadphase_callbacks.h Lines: 14 15 93.3 %
Date: 2024-02-09 12:57:42 Branches: 0 0 - %

Line Branch Exec Source
1
/*
2
 * Software License Agreement (BSD License)
3
 *
4
 *  Copyright (c) 2020, Toyota Research Institute
5
 *  Copyright (c) 2022, INRIA
6
 *  All rights reserved.
7
 *
8
 *  Redistribution and use in source and binary forms, with or without
9
 *  modification, are permitted provided that the following conditions
10
 *  are met:
11
 *
12
 *   * Redistributions of source code must retain the above copyright
13
 *     notice, this list of conditions and the following disclaimer.
14
 *   * Redistributions in binary form must reproduce the above
15
 *     copyright notice, this list of conditions and the following
16
 *     disclaimer in the documentation and/or other materials provided
17
 *     with the distribution.
18
 *   * Neither the name of the copyright holder nor the names of its
19
 *     contributors may be used to endorse or promote products derived
20
 *     from this software without specific prior written permission.
21
 *
22
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32
 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
 *  POSSIBILITY OF SUCH DAMAGE.
34
 */
35
36
/** @author Sean Curtis (sean@tri.global) */
37
/** @author Justin Carpentier (justin.carpentier@inria.fr) */
38
39
#ifndef HPP_FCL_BROADPHASE_DEFAULT_BROADPHASE_CALLBACKS_H
40
#define HPP_FCL_BROADPHASE_DEFAULT_BROADPHASE_CALLBACKS_H
41
42
#include "hpp/fcl/broadphase/broadphase_callbacks.h"
43
#include "hpp/fcl/collision.h"
44
#include "hpp/fcl/distance.h"
45
// #include "hpp/fcl/narrowphase/continuous_collision.h"
46
// #include "hpp/fcl/narrowphase/continuous_collision_request.h"
47
// #include "hpp/fcl/narrowphase/continuous_collision_result.h"
48
// #include "hpp/fcl/narrowphase/distance_request.h"
49
// #include "hpp/fcl/narrowphase/distance_result.h"
50
51
namespace hpp {
52
namespace fcl {
53
54
/// @brief Collision data stores the collision request and the result given by
55
/// collision algorithm.
56
struct CollisionData {
57
35655
  CollisionData() { done = false; }
58
59
  /// @brief Collision request
60
  CollisionRequest request;
61
62
  /// @brief Collision result
63
  CollisionResult result;
64
65
  /// @brief Whether the collision iteration can stop
66
  bool done;
67
68
  /// @brief Clears the CollisionData
69
31689
  void clear() {
70
31689
    result.clear();
71
31689
    done = false;
72
31689
  }
73
};
74
75
/// @brief Distance data stores the distance request and the result given by
76
/// distance algorithm.
77
struct DistanceData {
78
774
  DistanceData() { done = false; }
79
80
  /// @brief Distance request
81
  DistanceRequest request;
82
83
  /// @brief Distance result
84
  DistanceResult result;
85
86
  /// @brief Whether the distance iteration can stop
87
  bool done;
88
89
  /// @brief Clears the DistanceData
90
688
  void clear() {
91
688
    result.clear();
92
688
    done = false;
93
688
  }
94
};
95
96
/// @brief Provides a simple callback for the collision query in the
97
/// BroadPhaseCollisionManager. It assumes the `data` parameter is non-null and
98
/// points to an instance of CollisionData. It simply invokes the
99
/// `collide()` method on the culled pair of geometries and stores the results
100
/// in the data's CollisionResult instance.
101
///
102
/// This callback will cause the broadphase evaluation to stop if:
103
///   - the collision requests _disables_ cost _and_
104
///   - the collide() reports a collision for the culled pair, _and_
105
///   - we've reported the number of contacts requested in the CollisionRequest.
106
///
107
/// For a given instance of CollisionData, if broadphase evaluation has
108
/// already terminated (i.e., defaultCollisionFunction() returned `true`),
109
/// subsequent invocations with the same instance of CollisionData will
110
/// return immediately, requesting termination of broadphase evaluation (i.e.,
111
/// return `true`).
112
///
113
/// @param o1   The first object in the culled pair.
114
/// @param o2   The second object in the culled pair.
115
/// @param data A non-null pointer to a CollisionData instance.
116
/// @return `true` if the broadphase evaluation should stop.
117
/// @tparam S   The scalar type with which the computation will be performed.
118
bool defaultCollisionFunction(CollisionObject* o1, CollisionObject* o2,
119
                              void* data);
120
121
/// @brief Collision data for use with the DefaultContinuousCollisionFunction.
122
/// It stores the collision request and the result given by the collision
123
/// algorithm (and stores the conclusion of whether further evaluation of the
124
/// broadphase collision manager has been deemed unnecessary).
125
// struct DefaultContinuousCollisionData {
126
//   ContinuousCollisionRequest request;
127
//   ContinuousCollisionResult result;
128
//
129
//   /// If `true`, requests that the broadphase evaluation stop.
130
//   bool done{false};
131
// };
132
133
/// @brief Provides a simple callback for the continuous collision query in the
134
/// BroadPhaseCollisionManager. It assumes the `data` parameter is non-null and
135
/// points to an instance of DefaultContinuousCollisionData. It simply invokes
136
/// the `collide()` method on the culled pair of geometries and stores the
137
/// results in the data's ContinuousCollisionResult instance.
138
///
139
/// This callback will never cause the broadphase evaluation to terminate early.
140
/// However, if the `done` member of the DefaultContinuousCollisionData is set
141
/// to true, this method will simply return without doing any computation.
142
///
143
/// For a given instance of DefaultContinuousCollisionData, if broadphase
144
/// evaluation has already terminated (i.e.,
145
/// DefaultContinuousCollisionFunction() returned `true`), subsequent
146
/// invocations with the same instance of CollisionData will return
147
/// immediately, requesting termination of broadphase evaluation (i.e., return
148
/// `true`).
149
///
150
/// @param o1   The first object in the culled pair.
151
/// @param o2   The second object in the culled pair.
152
/// @param data A non-null pointer to a CollisionData instance.
153
/// @return True if the broadphase evaluation should stop.
154
/// @tparam S   The scalar type with which the computation will be performed.
155
// bool DefaultContinuousCollisionFunction(ContinuousCollisionObject* o1,
156
//                                         ContinuousCollisionObject* o2,
157
//                                         void* data) {
158
//   assert(data != nullptr);
159
//   auto* cdata = static_cast<DefaultContinuousCollisionData*>(data);
160
//
161
//   if (cdata->done) return true;
162
//
163
//   const ContinuousCollisionRequest& request = cdata->request;
164
//   ContinuousCollisionResult& result = cdata->result;
165
//   collide(o1, o2, request, result);
166
//
167
//   return cdata->done;
168
// }
169
170
/// @brief Provides a simple callback for the distance query in the
171
/// BroadPhaseCollisionManager. It assumes the `data` parameter is non-null and
172
/// points to an instance of DistanceData. It simply invokes the
173
/// `distance()` method on the culled pair of geometries and stores the results
174
/// in the data's DistanceResult instance.
175
///
176
/// This callback will cause the broadphase evaluation to stop if:
177
///   - The distance is less than or equal to zero (i.e., the pair is in
178
///     contact).
179
///
180
/// For a given instance of DistanceData, if broadphase evaluation has
181
/// already terminated (i.e., defaultDistanceFunction() returned `true`),
182
/// subsequent invocations with the same instance of DistanceData will
183
/// simply report the previously reported minimum distance and request
184
/// termination of broadphase evaluation (i.e., return `true`).
185
///
186
/// @param o1     The first object in the culled pair.
187
/// @param o2     The second object in the culled pair.
188
/// @param data   A non-null pointer to a DistanceData instance.
189
/// @param dist   The distance computed by distance().
190
/// @return `true` if the broadphase evaluation should stop.
191
/// @tparam S   The scalar type with which the computation will be performed.
192
bool defaultDistanceFunction(CollisionObject* o1, CollisionObject* o2,
193
                             void* data, FCL_REAL& dist);
194
195
/// @brief Default collision callback to check collision between collision
196
/// objects.
197
struct HPP_FCL_DLLAPI CollisionCallBackDefault : CollisionCallBackBase {
198
  /// @brief Initialize the callback.
199
  /// Clears the collision result and sets the done boolean to false.
200
31689
  void init() { data.clear(); }
201
202
  bool collide(CollisionObject* o1, CollisionObject* o2);
203
204
  CollisionData data;
205
206
71094
  virtual ~CollisionCallBackDefault(){};
207
};
208
209
/// @brief Default distance callback to check collision between collision
210
/// objects.
211
struct HPP_FCL_DLLAPI DistanceCallBackDefault : DistanceCallBackBase {
212
  /// @brief Initialize the callback.
213
  /// Clears the distance result and sets the done boolean to false.
214
688
  void init() { data.clear(); }
215
216
  bool distance(CollisionObject* o1, CollisionObject* o2, FCL_REAL& dist);
217
218
  DistanceData data;
219
220
1548
  virtual ~DistanceCallBackDefault(){};
221
};
222
223
/// @brief Collision callback to collect collision pairs potentially in contacts
224
struct HPP_FCL_DLLAPI CollisionCallBackCollect : CollisionCallBackBase {
225
  typedef std::pair<CollisionObject*, CollisionObject*> CollisionPair;
226
227
  /// @brief Default constructor.
228
  CollisionCallBackCollect(const size_t max_size);
229
230
  bool collide(CollisionObject* o1, CollisionObject* o2);
231
232
  /// @brief Returns the number of registered collision pairs
233
  size_t numCollisionPairs() const;
234
235
  /// @brief Returns a const reference to the active collision_pairs to check
236
  const std::vector<CollisionPair>& getCollisionPairs() const;
237
238
  /// @brief Reset the callback
239
  void init();
240
241
  /// @brief Check wether a collision pair exists
242
  bool exist(const CollisionPair& pair) const;
243
244
  virtual ~CollisionCallBackCollect(){};
245
246
 protected:
247
  std::vector<CollisionPair> collision_pairs;
248
  size_t max_size;
249
};
250
251
}  // namespace fcl
252
253
}  // namespace hpp
254
255
#endif  // HPP_FCL_BROADPHASE_DEFAULT_BROADPHASE_CALLBACKS_H