default_broadphase_callbacks.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2020, Toyota Research Institute
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 the copyright holder 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 
38 #include <algorithm>
39 
40 namespace coal {
41 
43  void* data) {
44  assert(data != nullptr);
45  auto* collision_data = static_cast<CollisionData*>(data);
46  const CollisionRequest& request = collision_data->request;
47  CollisionResult& result = collision_data->result;
48 
49  if (collision_data->done) return true;
50 
51  collide(o1, o2, request, result);
52 
53  if (result.isCollision() &&
54  result.numContacts() >= request.num_max_contacts) {
55  collision_data->done = true;
56  }
57 
58  return collision_data->done;
59 }
60 
62  CollisionObject* o2) {
63  return defaultCollisionFunction(o1, o2, &data);
64 }
65 
67  void* data, CoalScalar& dist) {
68  assert(data != nullptr);
69  auto* cdata = static_cast<DistanceData*>(data);
70  const DistanceRequest& request = cdata->request;
71  DistanceResult& result = cdata->result;
72 
73  if (cdata->done) {
74  dist = result.min_distance;
75  return true;
76  }
77 
78  distance(o1, o2, request, result);
79 
80  dist = result.min_distance;
81 
82  if (dist <= 0) return true; // in collision or in touch
83 
84  return cdata->done;
85 }
86 
88  CoalScalar& dist) {
89  return defaultDistanceFunction(o1, o2, &data, dist);
90 }
91 
93  : max_size(max_size) {
94  collision_pairs.resize(max_size);
95 }
96 
98  CollisionObject* o2) {
99  collision_pairs.push_back(std::make_pair(o1, o2));
100  return false;
101 }
102 
104  return collision_pairs.size();
105 }
106 
107 const std::vector<CollisionCallBackCollect::CollisionPair>&
109  return collision_pairs;
110 }
111 
113 
115  CollisionObject* o2) const {
116  return exist(std::make_pair(o1, o2));
117 }
118 
120  return std::find(collision_pairs.begin(), collision_pairs.end(), pair) !=
121  collision_pairs.end();
122 }
123 
124 } // namespace coal
coal::CollisionCallBackCollect::getCollisionPairs
const std::vector< CollisionPair > & getCollisionPairs() const
Returns a const reference to the active collision_pairs to check.
Definition: default_broadphase_callbacks.cpp:108
coal::CollisionResult::isCollision
bool isCollision() const
return binary collision result
Definition: coal/collision_data.h:443
coal::DistanceData
Distance data stores the distance request and the result given by distance algorithm.
Definition: coal/broadphase/default_broadphase_callbacks.h:76
coal::CollisionCallBackCollect::init
void init()
Reset the callback.
Definition: default_broadphase_callbacks.cpp:112
coal::CollisionCallBackCollect::CollisionPair
std::pair< CollisionObject *, CollisionObject * > CollisionPair
Definition: coal/broadphase/default_broadphase_callbacks.h:224
data
data
coal::DistanceCallBackDefault::distance
bool distance(CollisionObject *o1, CollisionObject *o2, CoalScalar &dist)
Distance evaluation between two objects in collision. This callback will cause the broadphase evaluat...
Definition: default_broadphase_callbacks.cpp:87
coal
Main namespace.
Definition: coal/broadphase/broadphase_bruteforce.h:44
coal::CollisionCallBackDefault::data
CollisionData data
Definition: coal/broadphase/default_broadphase_callbacks.h:203
coal::distance
COAL_DLLAPI CoalScalar distance(const Matrix3s &R0, const Vec3s &T0, const kIOS &b1, const kIOS &b2, Vec3s *P=NULL, Vec3s *Q=NULL)
Approximate distance between two kIOS bounding volumes.
Definition: kIOS.cpp:180
default_broadphase_callbacks.h
coal::CollisionCallBackCollect::exist
bool exist(const CollisionPair &pair) const
Check whether a collision pair exists.
Definition: default_broadphase_callbacks.cpp:119
coal::DistanceResult::min_distance
CoalScalar min_distance
minimum distance between two objects. If two objects are in collision and DistanceRequest::enable_sig...
Definition: coal/collision_data.h:1058
coal::CollisionCallBackCollect::numCollisionPairs
size_t numCollisionPairs() const
Returns the number of registered collision pairs.
Definition: default_broadphase_callbacks.cpp:103
coal::DistanceRequest
request to the distance computation
Definition: coal/collision_data.h:985
coal::defaultCollisionFunction
bool defaultCollisionFunction(CollisionObject *o1, CollisionObject *o2, void *data)
Provides a simple callback for the collision query in the BroadPhaseCollisionManager....
Definition: default_broadphase_callbacks.cpp:42
coal::CollisionCallBackCollect::collision_pairs
std::vector< CollisionPair > collision_pairs
Definition: coal/broadphase/default_broadphase_callbacks.h:246
coal::CollisionResult
collision result
Definition: coal/collision_data.h:390
coal::CollisionCallBackCollect::CollisionCallBackCollect
CollisionCallBackCollect(const size_t max_size)
Default constructor.
Definition: default_broadphase_callbacks.cpp:92
coal::CollisionRequest
request to the collision algorithm
Definition: coal/collision_data.h:311
coal::DistanceResult
distance result
Definition: coal/collision_data.h:1051
coal::CollisionObject
the object for collision or distance computation, contains the geometry and the transform information
Definition: coal/collision_object.h:214
coal::DistanceCallBackDefault::data
DistanceData data
Definition: coal/broadphase/default_broadphase_callbacks.h:217
coal::defaultDistanceFunction
bool defaultDistanceFunction(CollisionObject *o1, CollisionObject *o2, void *data, CoalScalar &dist)
Collision data for use with the DefaultContinuousCollisionFunction. It stores the collision request a...
Definition: default_broadphase_callbacks.cpp:66
coal::CollisionRequest::num_max_contacts
size_t num_max_contacts
The maximum number of contacts that can be returned.
Definition: coal/collision_data.h:313
coal::CollisionCallBackCollect::max_size
size_t max_size
Definition: coal/broadphase/default_broadphase_callbacks.h:250
coal::collide
COAL_DLLAPI std::size_t collide(const CollisionObject *o1, const CollisionObject *o2, const CollisionRequest &request, CollisionResult &result)
Main collision interface: given two collision objects, and the requirements for contacts,...
Definition: src/collision.cpp:61
coal::CollisionData
Collision data stores the collision request and the result given by collision algorithm.
Definition: coal/broadphase/default_broadphase_callbacks.h:55
coal::CollisionCallBackCollect::collide
bool collide(CollisionObject *o1, CollisionObject *o2)
Collision evaluation between two objects in collision. This callback will cause the broadphase evalua...
Definition: default_broadphase_callbacks.cpp:97
coal::CoalScalar
double CoalScalar
Definition: coal/data_types.h:76
coal::CollisionCallBackDefault::collide
bool collide(CollisionObject *o1, CollisionObject *o2)
Collision evaluation between two objects in collision. This callback will cause the broadphase evalua...
Definition: default_broadphase_callbacks.cpp:61
coal::CollisionResult::numContacts
size_t numContacts() const
number of contacts found
Definition: coal/collision_data.h:446


hpp-fcl
Author(s):
autogenerated on Sat Nov 23 2024 03:44:57