FCL  0.6.0
Flexible Collision Library
mesh_collision_traversal_node-inl.h
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 
38 #ifndef FCL_TRAVERSAL_MESHCOLLISIONTRAVERSALNODE_INL_H
39 #define FCL_TRAVERSAL_MESHCOLLISIONTRAVERSALNODE_INL_H
40 
41 #include "fcl/narrowphase/detail/traversal/collision/mesh_collision_traversal_node.h"
42 
43 #include "fcl/narrowphase/collision_result.h"
44 
45 namespace fcl
46 {
47 
48 namespace detail
49 {
50 
51 //==============================================================================
52 extern template
53 class MeshCollisionTraversalNodeOBB<double>;
54 
55 //==============================================================================
56 extern template
57 bool initialize(
58  MeshCollisionTraversalNodeOBB<double>& node,
59  const BVHModel<OBB<double>>& model1,
60  const Transform3<double>& tf1,
61  const BVHModel<OBB<double>>& model2,
62  const Transform3<double>& tf2,
63  const CollisionRequest<double>& request,
64  CollisionResult<double>& result);
65 
66 //==============================================================================
67 extern template
68 class MeshCollisionTraversalNodeRSS<double>;
69 
70 //==============================================================================
71 extern template
72 bool initialize(
73  MeshCollisionTraversalNodeRSS<double>& node,
74  const BVHModel<RSS<double>>& model1,
75  const Transform3<double>& tf1,
76  const BVHModel<RSS<double>>& model2,
77  const Transform3<double>& tf2,
78  const CollisionRequest<double>& request,
79  CollisionResult<double>& result);
80 
81 //==============================================================================
82 extern template
83 class MeshCollisionTraversalNodekIOS<double>;
84 
85 //==============================================================================
86 extern template
87 bool initialize(
88  MeshCollisionTraversalNodekIOS<double>& node,
89  const BVHModel<kIOS<double>>& model1,
90  const Transform3<double>& tf1,
91  const BVHModel<kIOS<double>>& model2,
92  const Transform3<double>& tf2,
93  const CollisionRequest<double>& request,
94  CollisionResult<double>& result);
95 
96 //==============================================================================
97 extern template
98 class MeshCollisionTraversalNodeOBBRSS<double>;
99 
100 //==============================================================================
101 extern template
102 bool initialize(
103  MeshCollisionTraversalNodeOBBRSS<double>& node,
104  const BVHModel<OBBRSS<double>>& model1,
105  const Transform3<double>& tf1,
106  const BVHModel<OBBRSS<double>>& model2,
107  const Transform3<double>& tf2,
108  const CollisionRequest<double>& request,
109  CollisionResult<double>& result);
110 
111 //==============================================================================
112 template <typename BV>
113 MeshCollisionTraversalNode<BV>::MeshCollisionTraversalNode()
114  : BVHCollisionTraversalNode<BV>()
115 {
116  vertices1 = nullptr;
117  vertices2 = nullptr;
118  tri_indices1 = nullptr;
119  tri_indices2 = nullptr;
120 }
121 
122 //==============================================================================
123 template <typename BV>
125 {
126  if(this->enable_statistics) this->num_leaf_tests++;
127 
128  const BVNode<BV>& node1 = this->model1->getBV(b1);
129  const BVNode<BV>& node2 = this->model2->getBV(b2);
130 
131  int primitive_id1 = node1.primitiveId();
132  int primitive_id2 = node2.primitiveId();
133 
134  const Triangle& tri_id1 = tri_indices1[primitive_id1];
135  const Triangle& tri_id2 = tri_indices2[primitive_id2];
136 
137  const Vector3<S>& p1 = vertices1[tri_id1[0]];
138  const Vector3<S>& p2 = vertices1[tri_id1[1]];
139  const Vector3<S>& p3 = vertices1[tri_id1[2]];
140  const Vector3<S>& q1 = vertices2[tri_id2[0]];
141  const Vector3<S>& q2 = vertices2[tri_id2[1]];
142  const Vector3<S>& q3 = vertices2[tri_id2[2]];
143 
144  if(this->model1->isOccupied() && this->model2->isOccupied())
145  {
146  bool is_intersect = false;
147 
148  if(!this->request.enable_contact) // only interested in collision or not
149  {
150  if(Intersect<S>::intersect_Triangle(p1, p2, p3, q1, q2, q3))
151  {
152  is_intersect = true;
153  if(this->result->numContacts() < this->request.num_max_contacts)
154  this->result->addContact(Contact<S>(this->model1, this->model2, primitive_id1, primitive_id2));
155  }
156  }
157  else // need compute the contact information
158  {
159  S penetration;
160  Vector3<S> normal;
161  unsigned int n_contacts;
162  Vector3<S> contacts[2];
163 
164  if(Intersect<S>::intersect_Triangle(p1, p2, p3, q1, q2, q3,
165  contacts,
166  &n_contacts,
167  &penetration,
168  &normal))
169  {
170  is_intersect = true;
171 
172  if(this->request.num_max_contacts < n_contacts + this->result->numContacts())
173  n_contacts = (this->request.num_max_contacts >= this->result->numContacts()) ? (this->request.num_max_contacts - this->result->numContacts()) : 0;
174 
175  for(unsigned int i = 0; i < n_contacts; ++i)
176  {
177  this->result->addContact(Contact<S>(this->model1, this->model2, primitive_id1, primitive_id2, contacts[i], normal, penetration));
178  }
179  }
180  }
181 
182  if(is_intersect && this->request.enable_cost)
183  {
184  AABB<S> overlap_part;
185  AABB<S>(p1, p2, p3).overlap(AABB<S>(q1, q2, q3), overlap_part);
186  this->result->addCostSource(CostSource<S>(overlap_part, cost_density), this->request.num_max_cost_sources);
187  }
188  }
189  else if((!this->model1->isFree() && !this->model2->isFree()) && this->request.enable_cost)
190  {
191  if(Intersect<S>::intersect_Triangle(p1, p2, p3, q1, q2, q3))
192  {
193  AABB<S> overlap_part;
194  AABB<S>(p1, p2, p3).overlap(AABB<S>(q1, q2, q3), overlap_part);
195  this->result->addCostSource(CostSource<S>(overlap_part, cost_density), this->request.num_max_cost_sources);
196  }
197  }
198 }
199 
200 //==============================================================================
201 template <typename BV>
203 {
204  return this->request.isSatisfied(*(this->result));
205 }
206 
207 //==============================================================================
208 template <typename BV>
209 bool initialize(
211  BVHModel<BV>& model1,
212  Transform3<typename BV::S>& tf1,
213  BVHModel<BV>& model2,
214  Transform3<typename BV::S>& tf2,
215  const CollisionRequest<typename BV::S>& request,
217  bool use_refit,
218  bool refit_bottomup)
219 {
220  using S = typename BV::S;
221 
222  if(model1.getModelType() != BVH_MODEL_TRIANGLES
223  || model2.getModelType() != BVH_MODEL_TRIANGLES)
224  return false;
225 
226  if(!tf1.matrix().isIdentity())
227  {
228  std::vector<Vector3<S>> vertices_transformed1(model1.num_vertices);
229  for(int i = 0; i < model1.num_vertices; ++i)
230  {
231  Vector3<S>& p = model1.vertices[i];
232  Vector3<S> new_v = tf1 * p;
233  vertices_transformed1[i] = new_v;
234  }
235 
236  model1.beginReplaceModel();
237  model1.replaceSubModel(vertices_transformed1);
238  model1.endReplaceModel(use_refit, refit_bottomup);
239 
240  tf1.setIdentity();
241  }
242 
243  if(!tf2.matrix().isIdentity())
244  {
245  std::vector<Vector3<S>> vertices_transformed2(model2.num_vertices);
246  for(int i = 0; i < model2.num_vertices; ++i)
247  {
248  Vector3<S>& p = model2.vertices[i];
249  Vector3<S> new_v = tf2 * p;
250  vertices_transformed2[i] = new_v;
251  }
252 
253  model2.beginReplaceModel();
254  model2.replaceSubModel(vertices_transformed2);
255  model2.endReplaceModel(use_refit, refit_bottomup);
256 
257  tf2.setIdentity();
258  }
259 
260  node.model1 = &model1;
261  node.tf1 = tf1;
262  node.model2 = &model2;
263  node.tf2 = tf2;
264 
265  node.vertices1 = model1.vertices;
266  node.vertices2 = model2.vertices;
267 
268  node.tri_indices1 = model1.tri_indices;
269  node.tri_indices2 = model2.tri_indices;
270 
271  node.request = request;
272  node.result = &result;
273 
274  node.cost_density = model1.cost_density * model2.cost_density;
275 
276  return true;
277 }
278 
279 //==============================================================================
280 template <typename S>
283  R(Matrix3<S>::Identity())
284 {
285  // Do nothing
286 }
287 
288 //==============================================================================
289 template <typename S>
291 {
292  if(this->enable_statistics) this->num_bv_tests++;
293 
294  return !overlap(R, T, this->model1->getBV(b1).bv, this->model2->getBV(b2).bv);
295 }
296 
297 //==============================================================================
298 template <typename S>
300 {
301  detail::meshCollisionOrientedNodeLeafTesting(
302  b1,
303  b2,
304  this->model1,
305  this->model2,
306  this->vertices1,
307  this->vertices2,
308  this->tri_indices1,
309  this->tri_indices2,
310  R,
311  T,
312  this->tf1,
313  this->tf2,
314  this->enable_statistics,
315  this->cost_density,
316  this->num_leaf_tests,
317  this->request,
318  *this->result);
319 }
320 
321 //==============================================================================
322 template <typename S>
324  int b1, int b2, const Matrix3<S>& Rc, const Vector3<S>& Tc) const
325 {
326  if(this->enable_statistics) this->num_bv_tests++;
327 
328  return obbDisjoint(
329  Rc, Tc,
330  this->model1->getBV(b1).bv.extent,
331  this->model2->getBV(b2).bv.extent);
332 }
333 
334 //==============================================================================
335 template <typename S>
337  int b1, int b2, const Transform3<S>& tf) const
338 {
339  if(this->enable_statistics) this->num_bv_tests++;
340 
341  return obbDisjoint(tf,
342  this->model1->getBV(b1).bv.extent,
343  this->model2->getBV(b2).bv.extent);
344 }
345 
346 //==============================================================================
347 template <typename S>
349  int b1, int b2, const Matrix3<S>& Rc, const Vector3<S>& Tc) const
350 {
351  detail::meshCollisionOrientedNodeLeafTesting(
352  b1,
353  b2,
354  this->model1,
355  this->model2,
356  this->vertices1,
357  this->vertices2,
358  this->tri_indices1,
359  this->tri_indices2,
360  R,
361  T,
362  this->tf1,
363  this->tf2,
364  this->enable_statistics,
365  this->cost_density,
366  this->num_leaf_tests,
367  this->request,
368  *this->result);
369 }
370 
371 //==============================================================================
372 template <typename S>
374  int b1, int b2, const Transform3<S>& tf) const
375 {
376  detail::meshCollisionOrientedNodeLeafTesting(
377  b1,
378  b2,
379  this->model1,
380  this->model2,
381  this->vertices1,
382  this->vertices2,
383  this->tri_indices1,
384  this->tri_indices2,
385  tf,
386  this->tf1,
387  this->tf2,
388  this->enable_statistics,
389  this->cost_density,
390  this->num_leaf_tests,
391  this->request,
392  *this->result);
393 }
394 
395 //==============================================================================
396 template <typename S>
399  R(Matrix3<S>::Identity())
400 {
401  // Do nothing
402 }
403 
404 //==============================================================================
405 template <typename S>
407 {
408  if(this->enable_statistics) this->num_bv_tests++;
409 
410  return !overlap(R, T, this->model1->getBV(b1).bv, this->model2->getBV(b2).bv);
411 }
412 
413 //==============================================================================
414 template <typename S>
416 {
417  detail::meshCollisionOrientedNodeLeafTesting(
418  b1,
419  b2,
420  this->model1,
421  this->model2,
422  this->vertices1,
423  this->vertices2,
424  this->tri_indices1,
425  this->tri_indices2,
426  R,
427  T,
428  this->tf1,
429  this->tf2,
430  this->enable_statistics,
431  this->cost_density,
432  this->num_leaf_tests,
433  this->request,
434  *this->result);
435 }
436 
437 //==============================================================================
438 template <typename S>
441  R(Matrix3<S>::Identity())
442 {
443  // Do nothing
444 }
445 
446 //==============================================================================
447 template <typename S>
449 {
450  if(this->enable_statistics) this->num_bv_tests++;
451 
452  return !overlap(R, T, this->model1->getBV(b1).bv, this->model2->getBV(b2).bv);
453 }
454 
455 //==============================================================================
456 template <typename S>
458 {
459  detail::meshCollisionOrientedNodeLeafTesting(
460  b1,
461  b2,
462  this->model1,
463  this->model2,
464  this->vertices1,
465  this->vertices2,
466  this->tri_indices1,
467  this->tri_indices2,
468  R,
469  T,
470  this->tf1,
471  this->tf2,
472  this->enable_statistics,
473  this->cost_density,
474  this->num_leaf_tests,
475  this->request,
476  *this->result);
477 }
478 
479 //==============================================================================
480 template <typename S>
483  R(Matrix3<S>::Identity())
484 {
485  // Do nothing
486 }
487 
488 //==============================================================================
489 template <typename S>
491 {
492  if(this->enable_statistics) this->num_bv_tests++;
493 
494  return !overlap(R, T, this->model1->getBV(b1).bv, this->model2->getBV(b2).bv);
495 }
496 
497 //==============================================================================
498 template <typename S>
500 {
501  detail::meshCollisionOrientedNodeLeafTesting(
502  b1,
503  b2,
504  this->model1,
505  this->model2,
506  this->vertices1,
507  this->vertices2,
508  this->tri_indices1,
509  this->tri_indices2,
510  R,
511  T,
512  this->tf1,
513  this->tf2,
514  this->enable_statistics,
515  this->cost_density,
516  this->num_leaf_tests,
517  this->request,
518  *this->result);
519 }
520 
521 template <typename BV>
522 void meshCollisionOrientedNodeLeafTesting(
523  int b1, int b2,
524  const BVHModel<BV>* model1,
525  const BVHModel<BV>* model2,
526  Vector3<typename BV::S>* vertices1,
527  Vector3<typename BV::S>* vertices2,
528  Triangle* tri_indices1,
529  Triangle* tri_indices2,
530  const Matrix3<typename BV::S>& R,
531  const Vector3<typename BV::S>& T,
532  const Transform3<typename BV::S>& tf1,
533  const Transform3<typename BV::S>& tf2,
534  bool enable_statistics,
535  typename BV::S cost_density,
536  int& num_leaf_tests,
537  const CollisionRequest<typename BV::S>& request,
539 {
540  using S = typename BV::S;
541 
542  if(enable_statistics) num_leaf_tests++;
543 
544  const BVNode<BV>& node1 = model1->getBV(b1);
545  const BVNode<BV>& node2 = model2->getBV(b2);
546 
547  int primitive_id1 = node1.primitiveId();
548  int primitive_id2 = node2.primitiveId();
549 
550  const Triangle& tri_id1 = tri_indices1[primitive_id1];
551  const Triangle& tri_id2 = tri_indices2[primitive_id2];
552 
553  const Vector3<S>& p1 = vertices1[tri_id1[0]];
554  const Vector3<S>& p2 = vertices1[tri_id1[1]];
555  const Vector3<S>& p3 = vertices1[tri_id1[2]];
556  const Vector3<S>& q1 = vertices2[tri_id2[0]];
557  const Vector3<S>& q2 = vertices2[tri_id2[1]];
558  const Vector3<S>& q3 = vertices2[tri_id2[2]];
559 
560  if(model1->isOccupied() && model2->isOccupied())
561  {
562  bool is_intersect = false;
563 
564  if(!request.enable_contact) // only interested in collision or not
565  {
566  if(Intersect<S>::intersect_Triangle(p1, p2, p3, q1, q2, q3, R, T))
567  {
568  is_intersect = true;
569  if(result.numContacts() < request.num_max_contacts)
570  result.addContact(Contact<S>(model1, model2, primitive_id1, primitive_id2));
571  }
572  }
573  else // need compute the contact information
574  {
575  S penetration;
576  Vector3<S> normal;
577  unsigned int n_contacts;
578  Vector3<S> contacts[2];
579 
580  if(Intersect<S>::intersect_Triangle(p1, p2, p3, q1, q2, q3,
581  R, T,
582  contacts,
583  &n_contacts,
584  &penetration,
585  &normal))
586  {
587  is_intersect = true;
588 
589  if(request.num_max_contacts < result.numContacts() + n_contacts)
590  n_contacts = (request.num_max_contacts > result.numContacts()) ? (request.num_max_contacts - result.numContacts()) : 0;
591 
592  for(unsigned int i = 0; i < n_contacts; ++i)
593  {
594  result.addContact(Contact<S>(model1, model2, primitive_id1, primitive_id2, tf1 * contacts[i], tf1.linear() * normal, penetration));
595  }
596  }
597  }
598 
599  if(is_intersect && request.enable_cost)
600  {
601  AABB<S> overlap_part;
602  AABB<S>(tf1 * p1, tf1 * p2, tf1 * p3).overlap(AABB<S>(tf2 * q1, tf2 * q2, tf2 * q3), overlap_part);
603  result.addCostSource(CostSource<S>(overlap_part, cost_density), request.num_max_cost_sources);
604  }
605  }
606  else if((!model1->isFree() && !model2->isFree()) && request.enable_cost)
607  {
608  if(Intersect<S>::intersect_Triangle(p1, p2, p3, q1, q2, q3, R, T))
609  {
610  AABB<S> overlap_part;
611  AABB<S>(tf1 * p1, tf1 * p2, tf1 * p3).overlap(AABB<S>(tf2 * q1, tf2 * q2, tf2 * q3), overlap_part);
612  result.addCostSource(CostSource<S>(overlap_part, cost_density), request.num_max_cost_sources);
613  }
614  }
615 }
616 
617 //==============================================================================
618 template <typename BV>
619 void meshCollisionOrientedNodeLeafTesting(
620  int b1,
621  int b2,
622  const BVHModel<BV>* model1,
623  const BVHModel<BV>* model2,
624  Vector3<typename BV::S>* vertices1,
625  Vector3<typename BV::S>* vertices2,
626  Triangle* tri_indices1,
627  Triangle* tri_indices2,
628  const Transform3<typename BV::S>& tf,
629  const Transform3<typename BV::S>& tf1,
630  const Transform3<typename BV::S>& tf2,
631  bool enable_statistics,
632  typename BV::S cost_density,
633  int& num_leaf_tests,
634  const CollisionRequest<typename BV::S>& request,
636 {
637  using S = typename BV::S;
638 
639  if(enable_statistics) num_leaf_tests++;
640 
641  const BVNode<BV>& node1 = model1->getBV(b1);
642  const BVNode<BV>& node2 = model2->getBV(b2);
643 
644  int primitive_id1 = node1.primitiveId();
645  int primitive_id2 = node2.primitiveId();
646 
647  const Triangle& tri_id1 = tri_indices1[primitive_id1];
648  const Triangle& tri_id2 = tri_indices2[primitive_id2];
649 
650  const Vector3<S>& p1 = vertices1[tri_id1[0]];
651  const Vector3<S>& p2 = vertices1[tri_id1[1]];
652  const Vector3<S>& p3 = vertices1[tri_id1[2]];
653  const Vector3<S>& q1 = vertices2[tri_id2[0]];
654  const Vector3<S>& q2 = vertices2[tri_id2[1]];
655  const Vector3<S>& q3 = vertices2[tri_id2[2]];
656 
657  if(model1->isOccupied() && model2->isOccupied())
658  {
659  bool is_intersect = false;
660 
661  if(!request.enable_contact) // only interested in collision or not
662  {
663  if(Intersect<S>::intersect_Triangle(p1, p2, p3, q1, q2, q3, tf))
664  {
665  is_intersect = true;
666  if(result.numContacts() < request.num_max_contacts)
667  result.addContact(Contact<S>(model1, model2, primitive_id1, primitive_id2));
668  }
669  }
670  else // need compute the contact information
671  {
672  S penetration;
673  Vector3<S> normal;
674  unsigned int n_contacts;
675  Vector3<S> contacts[2];
676 
678  p1, p2, p3, q1, q2, q3, tf, contacts, &n_contacts, &penetration, &normal))
679  {
680  is_intersect = true;
681 
682  if(request.num_max_contacts < result.numContacts() + n_contacts)
683  n_contacts = (request.num_max_contacts > result.numContacts()) ? (request.num_max_contacts - result.numContacts()) : 0;
684 
685  for(unsigned int i = 0; i < n_contacts; ++i)
686  {
687  result.addContact(Contact<S>(model1, model2, primitive_id1, primitive_id2, tf1 * contacts[i], tf1.linear() * normal, penetration));
688  }
689  }
690  }
691 
692  if(is_intersect && request.enable_cost)
693  {
694  AABB<S> overlap_part;
695  AABB<S>(tf1 * p1, tf1 * p2, tf1 * p3).overlap(AABB<S>(tf2 * q1, tf2 * q2, tf2 * q3), overlap_part);
696  result.addCostSource(CostSource<S>(overlap_part, cost_density), request.num_max_cost_sources);
697  }
698  }
699  else if((!model1->isFree() && !model2->isFree()) && request.enable_cost)
700  {
701  if(Intersect<S>::intersect_Triangle(p1, p2, p3, q1, q2, q3, tf))
702  {
703  AABB<S> overlap_part;
704  AABB<S>(tf1 * p1, tf1 * p2, tf1 * p3).overlap(AABB<S>(tf2 * q1, tf2 * q2, tf2 * q3), overlap_part);
705  result.addCostSource(CostSource<S>(overlap_part, cost_density), request.num_max_cost_sources);
706  }
707  }
708 }
709 
710 template<typename BV, typename OrientedNode>
711 bool setupMeshCollisionOrientedNode(
712  OrientedNode& node,
713  const BVHModel<BV>& model1, const Transform3<typename BV::S>& tf1,
714  const BVHModel<BV>& model2, const Transform3<typename BV::S>& tf2,
715  const CollisionRequest<typename BV::S>& request,
717 {
719  return false;
720 
721  node.vertices1 = model1.vertices;
722  node.vertices2 = model2.vertices;
723 
724  node.tri_indices1 = model1.tri_indices;
725  node.tri_indices2 = model2.tri_indices;
726 
727  node.model1 = &model1;
728  node.tf1 = tf1;
729  node.model2 = &model2;
730  node.tf2 = tf2;
731 
732  node.request = request;
733  node.result = &result;
734 
735  node.cost_density = model1.cost_density * model2.cost_density;
736 
737  relativeTransform(tf1.linear(), tf1.translation(), tf2.linear(), tf2.translation(), node.R, node.T);
738 
739  return true;
740 }
741 
742 //==============================================================================
743 template <typename S>
744 bool initialize(
746  const BVHModel<OBB<S>>& model1,
747  const Transform3<S>& tf1,
748  const BVHModel<OBB<S>>& model2,
749  const Transform3<S>& tf2,
750  const CollisionRequest<S>& request,
751  CollisionResult<S>& result)
752 {
753  return detail::setupMeshCollisionOrientedNode(
754  node, model1, tf1, model2, tf2, request, result);
755 }
756 
757 //==============================================================================
758 template <typename S>
759 bool initialize(
761  const BVHModel<RSS<S>>& model1,
762  const Transform3<S>& tf1,
763  const BVHModel<RSS<S>>& model2,
764  const Transform3<S>& tf2,
765  const CollisionRequest<S>& request,
766  CollisionResult<S>& result)
767 {
768  return detail::setupMeshCollisionOrientedNode(
769  node, model1, tf1, model2, tf2, request, result);
770 }
771 
772 //==============================================================================
773 template <typename S>
774 bool initialize(
776  const BVHModel<kIOS<S>>& model1,
777  const Transform3<S>& tf1,
778  const BVHModel<kIOS<S>>& model2,
779  const Transform3<S>& tf2,
780  const CollisionRequest<S>& request,
781  CollisionResult<S>& result)
782 {
783  return detail::setupMeshCollisionOrientedNode(
784  node, model1, tf1, model2, tf2, request, result);
785 }
786 
787 //==============================================================================
788 template <typename S>
789 bool initialize(
791  const BVHModel<OBBRSS<S>>& model1,
792  const Transform3<S>& tf1,
793  const BVHModel<OBBRSS<S>>& model2,
794  const Transform3<S>& tf2,
795  const CollisionRequest<S>& request,
796  CollisionResult<S>& result)
797 {
798  return detail::setupMeshCollisionOrientedNode(
799  node, model1, tf1, model2, tf2, request, result);
800 }
801 
802 } // namespace detail
803 } // namespace fcl
804 
805 #endif
bool enable_cost
whether the cost sources will be computed
Definition: collision_request.h:64
void addCostSource(const CostSource< S > &c, std::size_t num_max_cost_sources)
add one cost source into result structure
Definition: collision_result-inl.h:66
Definition: mesh_collision_traversal_node.h:209
size_t num_max_contacts
The maximum number of contacts will return.
Definition: collision_request.h:55
bool BVTesting(int b1, int b2) const
BV test between b1 and b2.
Definition: mesh_collision_traversal_node-inl.h:406
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
int replaceSubModel(const std::vector< Vector3< S >> &ps)
Replace a set of points in the old BVH model.
Definition: BVH_model-inl.h:559
collision result
Definition: collision_request.h:48
int beginReplaceModel()
Replace the geometry information of current frame (i.e. should have the same mesh topology with the p...
Definition: BVH_model-inl.h:508
BVHModelType getModelType() const
Model type described by the instance.
Definition: BVH_model-inl.h:48
Definition: mesh_collision_traversal_node.h:137
void leafTesting(int b1, int b2) const
Intersection testing between leaves (two triangles)
Definition: mesh_collision_traversal_node-inl.h:124
bool overlap(const Eigen::MatrixBase< DerivedA > &R0, const Eigen::MatrixBase< DerivedB > &T0, const kIOS< S > &b1, const kIOS< S > &b2)
Check collision between two kIOSs, b1 is in configuration (R0, T0) and b2 is in identity.
Definition: kIOS-inl.h:249
const BVNode< BV > & getBV(int id) const
We provide getBV() and getNumBVs() because BVH may be compressed (in future), so we must provide some...
Definition: BVH_model-inl.h:160
Transform3< BV::S > tf2
configuration of second object
Definition: traversal_node_base.h:88
Contact information returned by collision.
Definition: contact.h:48
size_t numContacts() const
number of contacts found
Definition: collision_result-inl.h:83
bool BVTesting(int b1, int b2) const
BV test between b1 and b2.
Definition: mesh_collision_traversal_node-inl.h:290
Vector3< S > * vertices
Geometry point data.
Definition: BVH_model.h:162
int num_vertices
Number of points.
Definition: BVH_model.h:174
CollisionRequest< BV::S > request
request setting for collision
Definition: collision_traversal_node_base.h:72
const BVHModel< BV > * model1
The first BVH model.
Definition: bvh_collision_traversal_node.h:86
bool isFree() const
whether the object is completely free
int primitiveId() const
Return the primitive index. The index is referred to the original data (i.e. vertices or tri_indices)...
Definition: BV_node_base.cpp:50
Triangle * tri_indices
Geometry triangle index data, will be nullptr for point clouds.
Definition: BVH_model.h:165
Triangle with 3 indices for points.
Definition: triangle.h:47
Definition: mesh_collision_traversal_node.h:178
bool BVTesting(int b1, int b2) const
BV test between b1 and b2.
Definition: mesh_collision_traversal_node-inl.h:490
void leafTesting(int b1, int b2) const
Leaf test between node b1 and b2, if they are both leafs.
Definition: mesh_collision_traversal_node-inl.h:457
unknown model type
Definition: BVH_internal.h:78
void leafTesting(int b1, int b2) const
Leaf test between node b1 and b2, if they are both leafs.
Definition: mesh_collision_traversal_node-inl.h:415
bool enable_contact
whether the contact information (normal, penetration depth and contact position) will return ...
Definition: collision_request.h:58
request to the collision algorithm
Definition: collision_request.h:52
size_t num_max_cost_sources
The maximum number of cost sources will return.
Definition: collision_request.h:61
void leafTesting(int b1, int b2) const
Leaf test between node b1 and b2, if they are both leafs.
Definition: mesh_collision_traversal_node-inl.h:499
Traversal node for collision between two meshes.
Definition: mesh_collision_traversal_node.h:58
A class describing the bounding hierarchy of a mesh model or a point cloud model (which is viewed as ...
Definition: BVH_model.h:57
BV::S cost_density
collision cost for unit volume
Definition: collision_geometry.h:103
CollisionResult< BV::S > * result
collision result kept during the traversal iteration
Definition: collision_traversal_node_base.h:75
A class describing a bounding volume node. It includes the tree structure providing in BVNodeBase and...
Definition: BV_node.h:52
Transform3< BV::S > tf1
configuation of first object
Definition: traversal_node_base.h:85
Cost source describes an area with a cost. The area is described by an AABB<S> region.
Definition: cost_source.h:49
bool BVTesting(int b1, int b2) const
BV test between b1 and b2.
Definition: mesh_collision_traversal_node-inl.h:448
bool canStop() const
Whether the traversal process can stop early.
Definition: mesh_collision_traversal_node-inl.h:202
bool isOccupied() const
whether the object is completely occupied
CCD intersect kernel among primitives.
Definition: intersect.h:54
const BVHModel< BV > * model2
The second BVH model.
Definition: bvh_collision_traversal_node.h:89
void leafTesting(int b1, int b2) const
Leaf test between node b1 and b2, if they are both leafs.
Definition: mesh_collision_traversal_node-inl.h:299
int endReplaceModel(bool refit=true, bool bottomup=true)
End BVH model replacement, will also refit or rebuild the bounding volume hierarchy.
Definition: BVH_model-inl.h:577
Traversal node for collision between two meshes if their underlying BVH node is oriented node (OBB...
Definition: mesh_collision_traversal_node.h:98
void addContact(const Contact< S > &c)
add one contact into result structure
Definition: collision_result-inl.h:59