38 #ifndef FCL_BROAD_PHASE_SSAP_INL_H 39 #define FCL_BROAD_PHASE_SSAP_INL_H 41 #include "fcl/broadphase/broadphase_SSaP.h" 48 class SSaPCollisionManager<double>;
96 void computeLocalAABB() {}
100 template <
typename S>
107 auto pos_start1 = objs_x.begin();
108 auto pos_end1 = std::upper_bound(pos_start1, objs_x.end(), &dummyHigh,
SortByXLow<S>());
110 while(pos_start1 < pos_end1)
112 if(*pos_start1 == obj)
114 objs_x.erase(pos_start1);
120 auto pos_start2 = objs_y.begin();
121 auto pos_end2 = std::upper_bound(pos_start2, objs_y.end(), &dummyHigh,
SortByYLow<S>());
123 while(pos_start2 < pos_end2)
125 if(*pos_start2 == obj)
127 objs_y.erase(pos_start2);
133 auto pos_start3 = objs_z.begin();
134 auto pos_end3 = std::upper_bound(pos_start3, objs_z.end(), &dummyHigh,
SortByZLow<S>());
136 while(pos_start3 < pos_end3)
138 if(*pos_start3 == obj)
140 objs_z.erase(pos_start3);
148 template <
typename S>
155 template <
typename S>
158 objs_x.push_back(obj);
159 objs_y.push_back(obj);
160 objs_z.push_back(obj);
165 template <
typename S>
178 template <
typename S>
186 template <
typename S>
196 template <
typename S>
199 objs.resize(objs_x.size());
200 std::copy(objs_x.begin(), objs_x.end(), objs.begin());
204 template <
typename S>
208 while(pos_start < pos_end)
210 if(*pos_start != obj)
212 if((*pos_start)->getAABB().overlap(obj->
getAABB()))
214 if(callback(*pos_start, obj, cdata))
224 template <
typename S>
227 while(pos_start < pos_end)
229 if(*pos_start != obj)
231 if((*pos_start)->getAABB().distance(obj->
getAABB()) < min_dist)
233 if(callback(*pos_start, obj, cdata, min_dist))
244 template <
typename S>
247 if(size() == 0)
return;
249 collide_(obj, cdata, callback);
253 template <
typename S>
256 static const unsigned int CUTOFF = 100;
259 bool coll_res =
false;
261 const auto pos_start1 = objs_x.begin();
262 const auto pos_end1 = std::upper_bound(pos_start1, objs_x.end(), &dummyHigh,
SortByXLow<S>());
263 unsigned int d1 = pos_end1 - pos_start1;
267 const auto pos_start2 = objs_y.begin();
268 const auto pos_end2 = std::upper_bound(pos_start2, objs_y.end(), &dummyHigh,
SortByYLow<S>());
269 unsigned int d2 = pos_end2 - pos_start2;
273 const auto pos_start3 = objs_z.begin();
274 const auto pos_end3 = std::upper_bound(pos_start3, objs_z.end(), &dummyHigh,
SortByZLow<S>());
275 unsigned int d3 = pos_end3 - pos_start3;
279 if(d3 <= d2 && d3 <= d1)
280 coll_res = checkColl(pos_start3, pos_end3, obj, cdata, callback);
283 if(d2 <= d3 && d2 <= d1)
284 coll_res = checkColl(pos_start2, pos_end2, obj, cdata, callback);
286 coll_res = checkColl(pos_start1, pos_end1, obj, cdata, callback);
290 coll_res = checkColl(pos_start3, pos_end3, obj, cdata, callback);
293 coll_res = checkColl(pos_start2, pos_end2, obj, cdata, callback);
296 coll_res = checkColl(pos_start1, pos_end1, obj, cdata, callback);
302 template <
typename S>
305 if(size() == 0)
return;
307 S min_dist = std::numeric_limits<S>::max();
308 distance_(obj, cdata, callback, min_dist);
312 template <
typename S>
315 static const unsigned int CUTOFF = 100;
318 if(min_dist < std::numeric_limits<S>::max())
319 dummy_vector += Vector3<S>(min_dist, min_dist, min_dist);
321 typename std::vector<CollisionObject<S>*>::const_iterator pos_start1 = objs_x.begin();
322 typename std::vector<CollisionObject<S>*>::const_iterator pos_start2 = objs_y.begin();
323 typename std::vector<CollisionObject<S>*>::const_iterator pos_start3 = objs_z.begin();
324 typename std::vector<CollisionObject<S>*>::const_iterator pos_end1 = objs_x.end();
325 typename std::vector<CollisionObject<S>*>::const_iterator pos_end2 = objs_y.end();
326 typename std::vector<CollisionObject<S>*>::const_iterator pos_end3 = objs_z.end();
333 old_min_distance = min_dist;
336 pos_end1 = std::upper_bound(pos_start1, objs_x.end(), &dummyHigh,
SortByXLow<S>());
337 unsigned int d1 = pos_end1 - pos_start1;
339 bool dist_res =
false;
343 pos_end2 = std::upper_bound(pos_start2, objs_y.end(), &dummyHigh,
SortByYLow<S>());
344 unsigned int d2 = pos_end2 - pos_start2;
348 pos_end3 = std::upper_bound(pos_start3, objs_z.end(), &dummyHigh,
SortByZLow<S>());
349 unsigned int d3 = pos_end3 - pos_start3;
353 if(d3 <= d2 && d3 <= d1)
354 dist_res = checkDis(pos_start3, pos_end3, obj, cdata, callback, min_dist);
357 if(d2 <= d3 && d2 <= d1)
358 dist_res = checkDis(pos_start2, pos_end2, obj, cdata, callback, min_dist);
360 dist_res = checkDis(pos_start1, pos_end1, obj, cdata, callback, min_dist);
364 dist_res = checkDis(pos_start3, pos_end3, obj, cdata, callback, min_dist);
367 dist_res = checkDis(pos_start2, pos_end2, obj, cdata, callback, min_dist);
371 dist_res = checkDis(pos_start1, pos_end1, obj, cdata, callback, min_dist);
374 if(dist_res)
return true;
378 if(old_min_distance < std::numeric_limits<S>::max())
384 if(min_dist < old_min_distance)
386 dummy_vector = obj->
getAABB().
max_ + Vector3<S>(min_dist, min_dist, min_dist);
391 if(dummy_vector.isApprox(obj->
getAABB().
max_, std::numeric_limits<S>::epsilon() * 100))
392 dummy_vector = dummy_vector + delta;
394 dummy_vector = dummy_vector * 2 - obj->
getAABB().
max_;
411 template <
typename S>
420 S delta_x = (objs_x[objs_x.size() - 1])->getAABB().min_[0] - (objs_x[0])->getAABB().min_[0];
421 S delta_y = (objs_x[objs_y.size() - 1])->getAABB().min_[1] - (objs_y[0])->getAABB().min_[1];
422 S delta_z = (objs_z[objs_z.size() - 1])->getAABB().min_[2] - (objs_z[0])->getAABB().min_[2];
425 if(delta_y > delta_x && delta_y > delta_z)
427 else if(delta_z > delta_y && delta_z > delta_x)
433 it_beg = objs_x.begin();
434 it_end = objs_x.end();
437 it_beg = objs_y.begin();
438 it_end = objs_y.end();
441 it_beg = objs_z.begin();
442 it_end = objs_z.end();
450 template <
typename S>
453 if(size() == 0)
return;
455 typename std::vector<CollisionObject<S>*>::const_iterator pos, run_pos, pos_end;
456 size_t axis = selectOptimalAxis(objs_x, objs_y, objs_z,
458 size_t axis2 = (axis + 1 > 2) ? 0 : (axis + 1);
459 size_t axis3 = (axis2 + 1 > 2) ? 0 : (axis2 + 1);
463 while((run_pos < pos_end) && (pos < pos_end))
469 if((*run_pos)->getAABB().min_[axis] < obj->
getAABB().
min_[axis])
472 if(run_pos == pos_end)
break;
482 if(run_pos < pos_end)
484 typename std::vector<CollisionObject<S>*>::const_iterator run_pos2 = run_pos;
486 while((*run_pos2)->getAABB().min_[axis] <= obj->
getAABB().
max_[axis])
495 if(callback(obj, obj2, cdata))
500 if(run_pos2 == pos_end)
break;
507 template <
typename S>
510 if(size() == 0)
return;
512 typename std::vector<CollisionObject<S>*>::const_iterator it, it_end;
513 selectOptimalAxis(objs_x, objs_y, objs_z, it, it_end);
515 S min_dist = std::numeric_limits<S>::max();
516 for(; it != it_end; ++it)
518 if(distance_(*it, cdata, callback, min_dist))
524 template <
typename S>
529 if((size() == 0) || (other_manager->
size() == 0))
return;
531 if(
this == other_manager)
533 collide(cdata, callback);
538 typename std::vector<CollisionObject<S>*>::const_iterator it, end;
539 if(this->size() < other_manager->
size())
541 for(it = objs_x.begin(), end = objs_x.end(); it != end; ++it)
542 if(other_manager->collide_(*it, cdata, callback))
return;
546 for(it = other_manager->
objs_x.begin(), end = other_manager->
objs_x.end(); it != end; ++it)
547 if(collide_(*it, cdata, callback))
return;
552 template <
typename S>
557 if((size() == 0) || (other_manager->
size() == 0))
return;
559 if(
this == other_manager)
565 S min_dist = std::numeric_limits<S>::max();
566 typename std::vector<CollisionObject<S>*>::const_iterator it, end;
567 if(this->size() < other_manager->
size())
569 for(it = objs_x.begin(), end = objs_x.end(); it != end; ++it)
570 if(other_manager->distance_(*it, cdata, callback, min_dist))
return;
574 for(it = other_manager->
objs_x.begin(), end = other_manager->
objs_x.end(); it != end; ++it)
575 if(distance_(*it, cdata, callback, min_dist))
return;
580 template <
typename S>
583 return objs_x.empty();
587 template <
typename S>
590 return objs_x.size();
void distance(CollisionObject< S > *obj, void *cdata, DistanceCallBack< S > callback) const
perform distance computation between one object and all the objects belonging to the manager ...
Definition: broadphase_SSaP-inl.h:303
void collide(CollisionObject< S > *obj, void *cdata, CollisionCallBack< S > callback) const
perform collision test between one object and all the objects belonging to the manager ...
Definition: broadphase_SSaP-inl.h:245
size_t size() const
the number of objects managed by the manager
Definition: broadphase_SSaP-inl.h:588
void getObjects(std::vector< CollisionObject< S > * > &objs) const
return the objects managed by the manager
Definition: broadphase_SSaP-inl.h:197
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
void unregisterObject(CollisionObject< S > *obj)
add one object to the manager
Definition: broadphase_SSaP-inl.h:101
std::vector< CollisionObject< S > * > objs_x
Objects sorted according to lower x value.
Definition: broadphase_SSaP.h:117
static size_t selectOptimalAxis(const std::vector< CollisionObject< S > * > &objs_x, const std::vector< CollisionObject< S > * > &objs_y, const std::vector< CollisionObject< S > * > &objs_z, typename std::vector< CollisionObject< S > * >::const_iterator &it_beg, typename std::vector< CollisionObject< S > * >::const_iterator &it_end)
Definition: broadphase_SSaP-inl.h:412
Functor sorting objects according to the AABB<S> lower x bound.
Definition: broadphase_SSaP-inl.h:52
bool checkColl(typename std::vector< CollisionObject< S > * >::const_iterator pos_start, typename std::vector< CollisionObject< S > * >::const_iterator pos_end, CollisionObject< S > *obj, void *cdata, CollisionCallBack< S > callback) const
check collision between one object and a list of objects, return value is whether stop is possible ...
Definition: broadphase_SSaP-inl.h:205
Vector3< S > max_
The max point in the AABB.
Definition: AABB.h:59
bool(*)(CollisionObject< S > *o1, CollisionObject< S > *o2, void *cdata) CollisionCallBack
Callback for collision between two objects. Return value is whether can stop now. ...
Definition: broadphase_collision_manager.h:53
Dummy collision object with a point AABB<S>
Definition: broadphase_SSaP-inl.h:88
bool(*)(CollisionObject< S > *o1, CollisionObject< S > *o2, void *cdata, S &dist) DistanceCallBack
Callback for distance between two objects, Return value is whether can stop now, also return the mini...
Definition: broadphase_collision_manager.h:60
bool empty() const
whether the manager is empty
Definition: broadphase_SSaP-inl.h:581
Functor sorting objects according to the AABB<S> lower z bound.
Definition: broadphase_SSaP-inl.h:76
void clear()
clear the manager
Definition: broadphase_SSaP-inl.h:187
Functor sorting objects according to the AABB<S> lower y bound.
Definition: broadphase_SSaP-inl.h:64
Simple SAP collision manager.
Definition: broadphase_SSaP.h:49
Vector3< S > min_
The min point in the AABB.
Definition: AABB.h:56
bool checkDis(typename std::vector< CollisionObject< S > * >::const_iterator pos_start, typename std::vector< CollisionObject< S > * >::const_iterator pos_end, CollisionObject< S > *obj, void *cdata, DistanceCallBack< S > callback, S &min_dist) const
check distance between one object and a list of objects, return value is whether stop is possible ...
Definition: broadphase_SSaP-inl.h:225
void update()
update the condition of manager
Definition: broadphase_SSaP-inl.h:179
const AABB< S > & getAABB() const
get the AABB in world space
Definition: collision_object-inl.h:111
the object for collision or distance computation, contains the geometry and the transform information...
Definition: collision_object.h:51
S distance(const Eigen::MatrixBase< DerivedA > &R0, const Eigen::MatrixBase< DerivedB > &T0, const kIOS< S > &b1, const kIOS< S > &b2, Vector3< S > *P, Vector3< S > *Q)
Approximate distance between two kIOS bounding volumes.
Definition: kIOS-inl.h:266
Base class for broad phase collision. It helps to accelerate the collision/distance between N objects...
Definition: broadphase_collision_manager.h:66
void setup()
initialize the manager, related with the specific type of manager
Definition: broadphase_SSaP-inl.h:166
void registerObject(CollisionObject< S > *obj)
remove one object from the manager
Definition: broadphase_SSaP-inl.h:156