38 #ifndef FCL_TRAVERSAL_RECURSE_INL_H 39 #define FCL_TRAVERSAL_RECURSE_INL_H 41 #include "fcl/narrowphase/detail/traversal/traversal_recurse.h" 53 void collisionRecurse(CollisionTraversalNodeBase<double>* node,
int b1,
int b2, BVHFrontList* front_list);
57 void collisionRecurse(MeshCollisionTraversalNodeOBB<double>* node,
int b1,
int b2,
const Matrix3<double>& R,
const Vector3<double>& T, BVHFrontList* front_list);
61 void collisionRecurse(MeshCollisionTraversalNodeRSS<double>* node,
int b1,
int b2,
const Matrix3<double>& R,
const Vector3<double>& T, BVHFrontList* front_list);
65 void selfCollisionRecurse(CollisionTraversalNodeBase<double>* node,
int b, BVHFrontList* front_list);
69 void distanceRecurse(DistanceTraversalNodeBase<double>* node,
int b1,
int b2, BVHFrontList* front_list);
73 void distanceQueueRecurse(DistanceTraversalNodeBase<double>* node,
int b1,
int b2, BVHFrontList* front_list,
int qsize);
77 void propagateBVHFrontListCollisionRecurse(CollisionTraversalNodeBase<double>* node, BVHFrontList* front_list);
81 void collisionRecurse(CollisionTraversalNodeBase<S>* node,
int b1,
int b2, BVHFrontList* front_list)
83 bool l1 = node->isFirstNodeLeaf(b1);
84 bool l2 = node->isSecondNodeLeaf(b2);
88 updateFrontList(front_list, b1, b2);
90 if(node->BVTesting(b1, b2))
return;
92 node->leafTesting(b1, b2);
96 if(node->BVTesting(b1, b2))
98 updateFrontList(front_list, b1, b2);
102 if(node->firstOverSecond(b1, b2))
104 int c1 = node->getFirstLeftChild(b1);
105 int c2 = node->getFirstRightChild(b1);
107 collisionRecurse(node, c1, b2, front_list);
110 if(node->canStop() && !front_list)
return;
112 collisionRecurse(node, c2, b2, front_list);
116 int c1 = node->getSecondLeftChild(b2);
117 int c2 = node->getSecondRightChild(b2);
119 collisionRecurse(node, b1, c1, front_list);
122 if(node->canStop() && !front_list)
return;
124 collisionRecurse(node, b1, c2, front_list);
129 template <
typename S>
130 void collisionRecurse(MeshCollisionTraversalNodeOBB<S>* node,
int b1,
int b2,
const Matrix3<S>& R,
const Vector3<S>& T, BVHFrontList* front_list)
132 bool l1 = node->isFirstNodeLeaf(b1);
133 bool l2 = node->isSecondNodeLeaf(b2);
137 updateFrontList(front_list, b1, b2);
139 if(node->BVTesting(b1, b2, R, T))
return;
141 node->leafTesting(b1, b2, R, T);
145 if(node->BVTesting(b1, b2, R, T))
147 updateFrontList(front_list, b1, b2);
153 if(node->firstOverSecond(b1, b2))
155 int c1 = node->getFirstLeftChild(b1);
156 int c2 = node->getFirstRightChild(b1);
158 const OBB<S>& bv1 = node->model1->getBV(c1).bv;
160 Matrix3<S> Rc = R.transpose() * bv1.axis;
162 Vector3<S> Tc = temp.transpose() * bv1.axis;
164 collisionRecurse(node, c1, b2, Rc, Tc, front_list);
167 if(node->canStop() && !front_list)
return;
169 const OBB<S>& bv2 = node->model1->getBV(c2).bv;
171 Rc.noalias() = R.transpose() * bv2.axis;
173 Tc[0] = bv2.axis.col(0).dot(temp);
174 Tc[1] = bv2.axis.col(1).dot(temp);
175 Tc[2] = bv2.axis.col(2).dot(temp);
177 collisionRecurse(node, c2, b2, Rc, Tc, front_list);
181 int c1 = node->getSecondLeftChild(b2);
182 int c2 = node->getSecondRightChild(b2);
184 const OBB<S>& bv1 = node->model2->getBV(c1).bv;
186 temp.noalias() = R * bv1.axis.col(0);
187 Rc(0, 0) = temp[0]; Rc(1, 0) = temp[1]; Rc(2, 0) = temp[2];
188 temp.noalias() = R * bv1.axis.col(1);
189 Rc(0, 1) = temp[0]; Rc(1, 1) = temp[1]; Rc(2, 1) = temp[2];
190 temp.noalias() = R * bv1.axis.col(2);
191 Rc(0, 2) = temp[0]; Rc(1, 2) = temp[1]; Rc(2, 2) = temp[2];
192 Vector3<S> Tc = R * bv1.To + T;
194 collisionRecurse(node, b1, c1, Rc, Tc, front_list);
197 if(node->canStop() && !front_list)
return;
199 const OBB<S>& bv2 = node->model2->getBV(c2).bv;
200 temp.noalias() = R * bv2.axis.col(0);
201 Rc(0, 0) = temp[0]; Rc(1, 0) = temp[1]; Rc(2, 0) = temp[2];
202 temp.noalias() = R * bv2.axis.col(1);
203 Rc(0, 1) = temp[0]; Rc(1, 1) = temp[1]; Rc(2, 1) = temp[2];
204 temp.noalias() = R * bv2.axis.col(2);
205 Rc(0, 2) = temp[0]; Rc(1, 2) = temp[1]; Rc(2, 2) = temp[2];
207 Tc.noalias() += R * bv2.To;
209 collisionRecurse(node, b1, c2, Rc, Tc, front_list);
214 template <
typename S>
215 void collisionRecurse(MeshCollisionTraversalNodeRSS<S>* node,
int b1,
int b2,
const Matrix3<S>& R,
const Vector3<S>& T, BVHFrontList* front_list)
224 template <
typename S>
225 void selfCollisionRecurse(CollisionTraversalNodeBase<S>* node,
int b, BVHFrontList* front_list)
227 bool l = node->isFirstNodeLeaf(b);
231 int c1 = node->getFirstLeftChild(b);
232 int c2 = node->getFirstRightChild(b);
234 selfCollisionRecurse(node, c1, front_list);
235 if(node->canStop() && !front_list)
return;
237 selfCollisionRecurse(node, c2, front_list);
238 if(node->canStop() && !front_list)
return;
240 collisionRecurse(node, c1, c2, front_list);
244 template <
typename S>
245 void distanceRecurse(DistanceTraversalNodeBase<S>* node,
int b1,
int b2, BVHFrontList* front_list)
247 bool l1 = node->isFirstNodeLeaf(b1);
248 bool l2 = node->isSecondNodeLeaf(b2);
252 updateFrontList(front_list, b1, b2);
254 node->leafTesting(b1, b2);
260 if(node->firstOverSecond(b1, b2))
262 a1 = node->getFirstLeftChild(b1);
264 c1 = node->getFirstRightChild(b1);
270 a2 = node->getSecondLeftChild(b2);
272 c2 = node->getSecondRightChild(b2);
275 S d1 = node->BVTesting(a1, a2);
276 S d2 = node->BVTesting(c1, c2);
280 if(!node->canStop(d2))
281 distanceRecurse(node, c1, c2, front_list);
283 updateFrontList(front_list, c1, c2);
285 if(!node->canStop(d1))
286 distanceRecurse(node, a1, a2, front_list);
288 updateFrontList(front_list, a1, a2);
292 if(!node->canStop(d1))
293 distanceRecurse(node, a1, a2, front_list);
295 updateFrontList(front_list, a1, a2);
297 if(!node->canStop(d2))
298 distanceRecurse(node, c1, c2, front_list);
300 updateFrontList(front_list, c1, c2);
306 template <
typename S>
318 template <
typename S>
321 bool operator() (
const BVT<S>& lhs,
const BVT<S>& rhs)
const 323 return lhs.
d > rhs.
d;
328 template <
typename S>
348 void push(
const BVT<S>& x)
360 return (pq.size() + 1 >=
qsize);
370 template <
typename S>
387 updateFrontList(front_list, min_test.
b1, min_test.b2);
395 distanceQueueRecurse(node, min_test.
b1, min_test.b2, front_list, qsize);
407 bvt1.b2 = min_test.b2;
411 bvt2.b2 = min_test.b2;
418 bvt1.
b1 = min_test.
b1;
422 bvt2.
b1 = min_test.
b1;
435 min_test = bvtq.top();
440 updateFrontList(front_list, min_test.
b1, min_test.b2);
448 template <
typename S>
451 BVHFrontList::iterator front_iter;
453 for(front_iter = front_list->begin(); front_iter != front_list->end(); ++front_iter)
455 int b1 = front_iter->left;
456 int b2 = front_iter->right;
462 front_iter->valid =
false;
463 collisionRecurse(node, b1, b2, &append);
469 front_iter->valid =
false;
476 collisionRecurse(node, c1, b2, front_list);
477 collisionRecurse(node, c2, b2, front_list);
484 collisionRecurse(node, b1, c1, front_list);
485 collisionRecurse(node, b1, c2, front_list);
493 for(front_iter = front_list->begin(); front_iter != front_list->end();)
495 if(!front_iter->valid)
496 front_iter = front_list->erase(front_iter);
501 for(front_iter = append.begin(); front_iter != append.end(); ++front_iter)
503 front_list->push_back(*front_iter);
virtual S BVTesting(int b1, int b2) const
BV test between b1 and b2.
Definition: distance_traversal_node_base-inl.h:70
int b1
bv indices for a pair of bvs in two models
Definition: traversal_recurse-inl.h:313
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
virtual bool BVTesting(int b1, int b2) const
BV test between b1 and b2.
Definition: collision_traversal_node_base-inl.h:70
Bounding volume test structure.
Definition: traversal_recurse-inl.h:307
S d
distance between bvs
Definition: traversal_recurse-inl.h:310
virtual bool isFirstNodeLeaf(int b) const
Whether b is a leaf node in the first BVH tree.
Definition: traversal_node_base-inl.h:76
Comparer between two BVT.
Definition: traversal_recurse-inl.h:319
virtual bool firstOverSecond(int b1, int b2) const
Traverse the subtree of the node in the first tree first.
Definition: traversal_node_base-inl.h:90
Node structure encoding the information required for collision traversal.
Definition: collision_traversal_node_base.h:52
Node structure encoding the information required for distance traversal.
Definition: distance_traversal_node_base.h:53
virtual bool canStop(S c) const
Check whether the traversal can stop.
Definition: distance_traversal_node_base-inl.h:84
virtual int getFirstRightChild(int b) const
Get the right child of the node b in the first tree.
Definition: traversal_node_base-inl.h:104
virtual void leafTesting(int b1, int b2) const
Leaf test between node b1 and b2, if they are both leafs.
Definition: distance_traversal_node_base-inl.h:77
virtual bool isSecondNodeLeaf(int b) const
Whether b is a leaf node in the second BVH tree.
Definition: traversal_node_base-inl.h:83
virtual int getSecondLeftChild(int b) const
Get the left child of the node b in the second tree.
Definition: traversal_node_base-inl.h:111
virtual int getSecondRightChild(int b) const
Get the right child of the node b in the second tree.
Definition: traversal_node_base-inl.h:118
virtual int getFirstLeftChild(int b) const
Get the left child of the node b in the first tree.
Definition: traversal_node_base-inl.h:97
unsigned int qsize
Queue size.
Definition: traversal_recurse-inl.h:366
Definition: traversal_recurse-inl.h:329