52 auto end1 = std::upper_bound(start1,
endpoints[0].end(), p);
55 size_t start_id = (size_t)(start1 -
endpoints[0].begin());
56 size_t end_id = (size_t)(end1 -
endpoints[0].begin());
57 size_t cur_id = (size_t)(start_id);
59 for (
size_t i = start_id; i < end_id; ++i) {
75 auto end2 = std::upper_bound(start2,
endpoints[1].end(), p);
78 size_t start_id = (size_t)(start2 -
endpoints[1].begin());
79 size_t end_id = (size_t)(end2 -
endpoints[1].begin());
80 size_t cur_id = (size_t)(start_id);
82 for (
size_t i = start_id; i < end_id; ++i) {
98 auto end3 = std::upper_bound(start3,
endpoints[2].end(), p);
101 size_t start_id = (size_t)(start3 -
endpoints[2].begin());
102 size_t end_id = (size_t)(end3 -
endpoints[2].begin());
103 size_t cur_id = (size_t)(start_id);
105 for (
size_t i = start_id; i < end_id; ++i) {
239 for (
int i = 0; i < 3; ++i) {
242 old_aabb.
min_[i] = it->second->low;
243 old_aabb.
max_[i] = it->second->high;
244 it->second->low = new_aabb.
min_[i];
245 it->second->high = new_aabb.
max_[i];
250 typename std::vector<EndPoint>::iterator it;
251 for (
int i = 0; i < 3; ++i) {
255 if (it->obj == updated_obj && it->minmax == 0) {
256 it->value = new_aabb.
min_[i];
264 if (it->obj == updated_obj && it->minmax == 0) {
265 it->value = new_aabb.
max_[i];
276 const std::vector<CollisionObject*>& updated_objs) {
277 for (
size_t i = 0; i < updated_objs.size(); ++i)
update(updated_objs[i]);
293 for (
int i = 0; i < 3; ++i) {
308 std::vector<CollisionObject*>& objs)
const {
323 if (
size() == 0)
return;
330 static const unsigned int CUTOFF = 100;
332 std::deque<detail::SimpleInterval*> results0, results1, results2;
336 if (results0.size() > CUTOFF) {
339 if (results1.size() > CUTOFF) {
342 if (results2.size() > CUTOFF) {
343 size_t d1 = results0.size();
344 size_t d2 = results1.size();
345 size_t d3 = results2.size();
347 if (d1 >= d2 && d1 >= d3)
349 else if (d2 >= d1 && d2 >= d3)
365 if (
size() == 0)
return;
366 FCL_REAL min_dist = (std::numeric_limits<FCL_REAL>::max)();
374 static const unsigned int CUTOFF = 100;
378 if (min_dist < (std::numeric_limits<FCL_REAL>::max)()) {
379 Vec3f min_dist_delta(min_dist, min_dist, min_dist);
380 aabb.
expand(min_dist_delta);
387 bool dist_res =
false;
389 old_min_distance = min_dist;
391 std::deque<detail::SimpleInterval*> results0, results1, results2;
394 if (results0.size() > CUTOFF) {
396 if (results1.size() > CUTOFF) {
398 if (results2.size() > CUTOFF) {
399 size_t d1 = results0.size();
400 size_t d2 = results1.size();
401 size_t d3 = results2.size();
403 if (d1 >= d2 && d1 >= d3)
404 dist_res =
checkDist(results0.begin(), results0.end(), obj,
406 else if (d2 >= d1 && d2 >= d3)
407 dist_res =
checkDist(results1.begin(), results1.end(), obj,
410 dist_res =
checkDist(results2.begin(), results2.end(), obj,
422 if (dist_res)
return true;
429 if (old_min_distance < (std::numeric_limits<FCL_REAL>::max)())
432 if (min_dist < old_min_distance) {
433 Vec3f min_dist_delta(min_dist, min_dist, min_dist);
443 }
else if (status == 0)
454 if (
size() == 0)
return;
456 std::set<CollisionObject*> active;
457 std::set<std::pair<CollisionObject*, CollisionObject*> >
overlap;
464 if (diff_y > diff_x && diff_y > diff_z)
466 else if (diff_z > diff_y && diff_z > diff_x)
469 for (
unsigned int i = 0; i < n; ++i) {
472 if (endpoint.
minmax == 0) {
473 auto iter = active.begin();
474 auto end = active.end();
475 for (; iter != end; ++iter) {
480 int axis2 = (axis + 1) % 3;
481 int axis3 = (axis + 2) % 3;
485 CollisionObject*> >::iterator,
488 if (active_index < index)
489 insert_res = overlap.insert(std::make_pair(active_index, index));
491 insert_res = overlap.insert(std::make_pair(index, active_index));
493 if (insert_res.second) {
494 if ((*callback)(active_index, index))
return;
498 active.insert(index);
508 if (
size() == 0)
return;
512 FCL_REAL min_dist = (std::numeric_limits<FCL_REAL>::max)();
514 for (
size_t i = 0; i <
endpoints[0].size(); ++i)
529 if ((
size() == 0) || (other_manager->
size() == 0))
return;
531 if (
this == other_manager) {
536 if (this->
size() < other_manager->
size()) {
553 if ((
size() == 0) || (other_manager->
size() == 0))
return;
555 if (
this == other_manager) {
560 FCL_REAL min_dist = (std::numeric_limits<FCL_REAL>::max)();
562 if (this->
size() < other_manager->
size()) {
585 typename std::deque<detail::SimpleInterval*>::const_iterator pos_start,
586 typename std::deque<detail::SimpleInterval*>::const_iterator pos_end,
588 while (pos_start < pos_end) {
590 if (ivl->
obj != obj) {
592 if ((*callback)(ivl->
obj, obj))
return true;
604 typename std::deque<detail::SimpleInterval*>::const_iterator pos_start,
605 typename std::deque<detail::SimpleInterval*>::const_iterator pos_end,
608 while (pos_start < pos_end) {
610 if (ivl->
obj != obj) {
613 if ((*callback)(ivl->
obj, obj, min_dist))
return true;
618 if ((*callback)(ivl->
obj, obj, min_dist))
return true;
642 : detail::SimpleInterval() {
bool collide_(CollisionObject *obj, CollisionCallBackBase *callback) const
Extention interval tree's interval to SAP interval, adding more information.
virtual void init()
Initialization of the callback before running the collision broadphase manager.
bool operator<(const EndPoint &p) const
std::map< CollisionObject *, SAPInterval * > obj_interval_maps[3]
SAPInterval(FCL_REAL low_, FCL_REAL high_, CollisionObject *obj_)
IntervalTreeNode * insert(SimpleInterval *new_interval)
Insert one node of the interval tree.
Collision manager based on interval tree.
void collide(CollisionObject *obj, CollisionCallBackBase *callback) const
perform collision test between one object and all the objects belonging to the manager ...
Vec3f min_
The min point in the AABB.
bool overlap(const AABB &other) const
Check whether two AABB are overlap.
Base class for broad phase collision. It helps to accelerate the collision/distance between N objects...
void distance(CollisionObject *obj, DistanceCallBackBase *callback) const
perform distance computation between one object and all the objects belonging to the manager ...
IntervalTreeCollisionManager()
FCL_REAL low
interval is defined as [low, high]
detail::IntervalTree * interval_trees[3]
interval tree manages the intervals
Base callback class for collision queries. This class can be supersed by child classes to provide des...
void clear()
clear the manager
FCL_REAL value
end point value
virtual void init()
Initialization of the callback before running the collision broadphase manager.
virtual void update()
update the condition of manager
size_t size() const
the number of objects managed by the manager
void unregisterObject(CollisionObject *obj)
add one object to the manager
void setup()
initialize the manager, related with the specific type of manager
char minmax
tag for whether it is a lower bound or higher bound of an interval, 0 for lo, and 1 for hi ...
CollisionObject * obj
object related with the end point
virtual std::vector< CollisionObject * > getObjects() const
return the objects managed by the manager
void minmax(FCL_REAL a, FCL_REAL b, FCL_REAL &minv, FCL_REAL &maxv)
Find the smaller and larger one of two values.
bool distance_(CollisionObject *obj, DistanceCallBackBase *callback, FCL_REAL &min_dist) const
bool empty() const
whether the manager is empty
void insertTestedSet(CollisionObject *a, CollisionObject *b) const
A class describing the AABB collision structure, which is a box in 3D space determined by two diagona...
Vec3f max_
The max point in the AABB.
bool checkColl(typename std::deque< detail::SimpleInterval *>::const_iterator pos_start, typename std::deque< detail::SimpleInterval *>::const_iterator pos_end, CollisionObject *obj, CollisionCallBackBase *callback) const
FCL_REAL distance(const AABB &other) const
Distance between two AABBs.
bool setup_
tag for whether the interval tree is maintained suitably
SimpleInterval * deleteNode(IntervalTreeNode *node)
Delete one node of the interval tree.
HPP_FCL_DLLAPI bool overlap(const Matrix3f &R0, const Vec3f &T0, const AABB &b1, const AABB &b2)
Check collision between two aabbs, b1 is in configuration (R0, T0) and b2 is in identity.
const AABB & getAABB() const
get the AABB in world space
std::deque< SimpleInterval * > query(FCL_REAL low, FCL_REAL high)
Return result for a given query.
void registerObject(CollisionObject *obj)
remove one object from the manager
AABB & expand(const Vec3f &delta)
expand the half size of the AABB by delta, and keep the center unchanged.
std::set< std::pair< CollisionObject *, CollisionObject * > > tested_set
tools help to avoid repeating collision or distance callback for the pairs of objects tested before...
Eigen::Matrix< FCL_REAL, 3, 1 > Vec3f
the object for collision or distance computation, contains the geometry and the transform information...
Base callback class for distance queries. This class can be supersed by child classes to provide desi...
bool axisOverlap(const AABB &other, int axis_id) const
Check whether two AABB are overlapped along specific axis.
~IntervalTreeCollisionManager()
bool inTestedSet(CollisionObject *a, CollisionObject *b) const
std::vector< EndPoint > endpoints[3]
vector stores all the end points
bool checkDist(typename std::deque< detail::SimpleInterval *>::const_iterator pos_start, typename std::deque< detail::SimpleInterval *>::const_iterator pos_end, CollisionObject *obj, DistanceCallBackBase *callback, FCL_REAL &min_dist) const