broadphase_bruteforce.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011-2014, Willow Garage, Inc.
5  * Copyright (c) 2014-2016, Open Source Robotics Foundation
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 Open Source Robotics Foundation 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 
39 
40 #include <iterator>
41 #include <algorithm>
42 
43 namespace coal {
44 
45 //==============================================================================
47  // Do nothing
48 }
49 
50 //==============================================================================
52  const std::vector<CollisionObject*>& other_objs) {
53  std::copy(other_objs.begin(), other_objs.end(), std::back_inserter(objs));
54 }
55 
56 //==============================================================================
58  objs.remove(obj);
59 }
60 
61 //==============================================================================
63  objs.push_back(obj);
64 }
65 
66 //==============================================================================
68  // Do nothing
69 }
70 
71 //==============================================================================
73  // Do nothing
74 }
75 
76 //==============================================================================
78 
79 //==============================================================================
81  std::vector<CollisionObject*>& objs_) const {
82  objs_.resize(objs.size());
83  std::copy(objs.begin(), objs.end(), objs_.begin());
84 }
85 
86 //==============================================================================
89  callback->init();
90  if (size() == 0) return;
91 
92  for (auto* obj2 : objs) {
93  if ((*callback)(obj, obj2)) return;
94  }
95 }
96 
97 //==============================================================================
100  callback->init();
101  if (size() == 0) return;
102 
103  CoalScalar min_dist = (std::numeric_limits<CoalScalar>::max)();
104  for (auto* obj2 : objs) {
105  if (obj->getAABB().distance(obj2->getAABB()) < min_dist) {
106  if ((*callback)(obj, obj2, min_dist)) return;
107  }
108  }
109 }
110 
111 //==============================================================================
113  callback->init();
114  if (size() == 0) return;
115 
116  for (typename std::list<CollisionObject*>::const_iterator it1 = objs.begin(),
117  end = objs.end();
118  it1 != end; ++it1) {
119  typename std::list<CollisionObject*>::const_iterator it2 = it1;
120  it2++;
121  for (; it2 != end; ++it2) {
122  if ((*it1)->getAABB().overlap((*it2)->getAABB())) {
123  if ((*callback)(*it1, *it2)) return;
124  }
125  }
126  }
127 }
128 
129 //==============================================================================
131  callback->init();
132  if (size() == 0) return;
133 
134  CoalScalar min_dist = (std::numeric_limits<CoalScalar>::max)();
135  for (typename std::list<CollisionObject*>::const_iterator it1 = objs.begin(),
136  end = objs.end();
137  it1 != end; ++it1) {
138  typename std::list<CollisionObject*>::const_iterator it2 = it1;
139  it2++;
140  for (; it2 != end; ++it2) {
141  if ((*it1)->getAABB().distance((*it2)->getAABB()) < min_dist) {
142  if ((*callback)(*it1, *it2, min_dist)) return;
143  }
144  }
145  }
146 }
147 
148 //==============================================================================
151  callback->init();
152  NaiveCollisionManager* other_manager =
153  static_cast<NaiveCollisionManager*>(other_manager_);
154 
155  if ((size() == 0) || (other_manager->size() == 0)) return;
156 
157  if (this == other_manager) {
158  collide(callback);
159  return;
160  }
161 
162  for (auto* obj1 : objs) {
163  for (auto* obj2 : other_manager->objs) {
164  if (obj1->getAABB().overlap(obj2->getAABB())) {
165  if ((*callback)(obj1, obj2)) return;
166  }
167  }
168  }
169 }
170 
171 //==============================================================================
174  callback->init();
175  NaiveCollisionManager* other_manager =
176  static_cast<NaiveCollisionManager*>(other_manager_);
177 
178  if ((size() == 0) || (other_manager->size() == 0)) return;
179 
180  if (this == other_manager) {
182  return;
183  }
184 
185  CoalScalar min_dist = (std::numeric_limits<CoalScalar>::max)();
186  for (auto* obj1 : objs) {
187  for (auto* obj2 : other_manager->objs) {
188  if (obj1->getAABB().distance(obj2->getAABB()) < min_dist) {
189  if ((*callback)(obj1, obj2, min_dist)) return;
190  }
191  }
192  }
193 }
194 
195 //==============================================================================
196 bool NaiveCollisionManager::empty() const { return objs.empty(); }
197 
198 //==============================================================================
199 size_t NaiveCollisionManager::size() const { return objs.size(); }
200 
201 } // namespace coal
coal::NaiveCollisionManager::objs
std::list< CollisionObject * > objs
objects belonging to the manager are stored in a list structure
Definition: coal/broadphase/broadphase_bruteforce.h:107
coal::NaiveCollisionManager::registerObject
void registerObject(CollisionObject *obj)
add one object to the manager
Definition: broadphase_bruteforce.cpp:62
coal::NaiveCollisionManager::update
virtual void update()
update the condition of manager
Definition: broadphase_bruteforce.cpp:72
coal::NaiveCollisionManager::setup
void setup()
initialize the manager, related with the specific type of manager
Definition: broadphase_bruteforce.cpp:67
collision_manager.callback
callback
Definition: collision_manager.py:27
coal::AABB::distance
CoalScalar distance(const AABB &other) const
Distance between two AABBs.
Definition: AABB.cpp:114
coal::BroadPhaseCollisionManager
Base class for broad phase collision. It helps to accelerate the collision/distance between N objects...
Definition: coal/broadphase/broadphase_collision_manager.h:53
coal::NaiveCollisionManager::unregisterObject
void unregisterObject(CollisionObject *obj)
remove one object from the manager
Definition: broadphase_bruteforce.cpp:57
coal::NaiveCollisionManager::empty
bool empty() const
whether the manager is empty
Definition: broadphase_bruteforce.cpp:196
coal
Main namespace.
Definition: coal/broadphase/broadphase_bruteforce.h:44
coal::BroadPhaseCollisionManager::getObjects
virtual std::vector< CollisionObject * > getObjects() const
return the objects managed by the manager
Definition: coal/broadphase/broadphase_collision_manager.h:87
coal::NaiveCollisionManager::collide
void collide(CollisionObject *obj, CollisionCallBackBase *callback) const
perform collision test between one object and all the objects belonging to the manager
Definition: broadphase_bruteforce.cpp:87
coal::NaiveCollisionManager::NaiveCollisionManager
NaiveCollisionManager()
Definition: broadphase_bruteforce.cpp:46
coal::NaiveCollisionManager::distance
void distance(CollisionObject *obj, DistanceCallBackBase *callback) const
perform distance computation between one object and all the objects belonging to the manager
Definition: broadphase_bruteforce.cpp:98
coal::NaiveCollisionManager
Brute force N-body collision manager.
Definition: coal/broadphase/broadphase_bruteforce.h:47
coal::NaiveCollisionManager::clear
void clear()
clear the manager
Definition: broadphase_bruteforce.cpp:77
coal::DistanceCallBackBase
Base callback class for distance queries. This class can be supersed by child classes to provide desi...
Definition: coal/broadphase/broadphase_callbacks.h:72
coal::CollisionObject
the object for collision or distance computation, contains the geometry and the transform information
Definition: coal/collision_object.h:214
coal::CollisionObject::getAABB
const AABB & getAABB() const
get the AABB in world space
Definition: coal/collision_object.h:252
broadphase_bruteforce.h
coal::NaiveCollisionManager::size
size_t size() const
the number of objects managed by the manager
Definition: broadphase_bruteforce.cpp:199
coal::CollisionCallBackBase
Base callback class for collision queries. This class can be supersed by child classes to provide des...
Definition: coal/broadphase/broadphase_callbacks.h:49
coal::CoalScalar
double CoalScalar
Definition: coal/data_types.h:76
coal::NaiveCollisionManager::registerObjects
void registerObjects(const std::vector< CollisionObject * > &other_objs)
add objects to the manager
Definition: broadphase_bruteforce.cpp:51


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