38 #ifndef COAL_TRAVERSAL_NODE_SETUP_H
39 #define COAL_TRAVERSAL_NODE_SETUP_H
52 #ifdef COAL_HAS_OCTOMAP
60 #ifdef COAL_HAS_OCTOMAP
61 inline bool initialize(OcTreeCollisionTraversalNode& node,
const OcTree& model1,
64 const Transform3s&
tf1,
const OcTree& model2,
65 const Transform3s&
tf2,
const OcTreeSolver* otsolver,
66 CollisionResult& result) {
67 node.result = &result;
69 node.model1 = &model1;
70 node.model2 = &model2;
72 node.otsolver = otsolver;
82 inline bool initialize(OcTreeDistanceTraversalNode& node,
const OcTree& model1,
83 const Transform3s&
tf1,
const OcTree& model2,
84 const Transform3s&
tf2,
const OcTreeSolver* otsolver,
85 const DistanceRequest& request, DistanceResult& result)
88 node.request = request;
89 node.result = &result;
91 node.model1 = &model1;
92 node.model2 = &model2;
94 node.otsolver = otsolver;
104 template <
typename S>
105 bool initialize(ShapeOcTreeCollisionTraversalNode<S>& node,
const S& model1,
106 const Transform3s&
tf1,
const OcTree& model2,
107 const Transform3s&
tf2,
const OcTreeSolver* otsolver,
108 CollisionResult& result) {
109 node.result = &result;
111 node.model1 = &model1;
112 node.model2 = &model2;
114 node.otsolver = otsolver;
124 template <
typename S>
125 bool initialize(OcTreeShapeCollisionTraversalNode<S>& node,
126 const OcTree& model1,
const Transform3s&
tf1,
const S& model2,
127 const Transform3s&
tf2,
const OcTreeSolver* otsolver,
128 CollisionResult& result) {
129 node.result = &result;
131 node.model1 = &model1;
132 node.model2 = &model2;
134 node.otsolver = otsolver;
144 template <
typename S>
145 bool initialize(ShapeOcTreeDistanceTraversalNode<S>& node,
const S& model1,
146 const Transform3s&
tf1,
const OcTree& model2,
147 const Transform3s&
tf2,
const OcTreeSolver* otsolver,
148 const DistanceRequest& request, DistanceResult& result) {
149 node.request = request;
150 node.result = &result;
152 node.model1 = &model1;
153 node.model2 = &model2;
155 node.otsolver = otsolver;
165 template <
typename S>
166 bool initialize(OcTreeShapeDistanceTraversalNode<S>& node,
const OcTree& model1,
167 const Transform3s&
tf1,
const S& model2,
const Transform3s&
tf2,
168 const OcTreeSolver* otsolver,
const DistanceRequest& request,
169 DistanceResult& result) {
170 node.request = request;
171 node.result = &result;
173 node.model1 = &model1;
174 node.model2 = &model2;
176 node.otsolver = otsolver;
186 template <
typename BV>
187 bool initialize(MeshOcTreeCollisionTraversalNode<BV>& node,
188 const BVHModel<BV>& model1,
const Transform3s&
tf1,
189 const OcTree& model2,
const Transform3s&
tf2,
190 const OcTreeSolver* otsolver, CollisionResult& result) {
191 node.result = &result;
193 node.model1 = &model1;
194 node.model2 = &model2;
196 node.otsolver = otsolver;
206 template <
typename BV>
207 bool initialize(OcTreeMeshCollisionTraversalNode<BV>& node,
208 const OcTree& model1,
const Transform3s&
tf1,
209 const BVHModel<BV>& model2,
const Transform3s&
tf2,
210 const OcTreeSolver* otsolver, CollisionResult& result) {
211 node.result = &result;
213 node.model1 = &model1;
214 node.model2 = &model2;
216 node.otsolver = otsolver;
226 template <
typename BV>
227 bool initialize(OcTreeHeightFieldCollisionTraversalNode<BV>& node,
228 const OcTree& model1,
const Transform3s&
tf1,
229 const HeightField<BV>& model2,
const Transform3s&
tf2,
230 const OcTreeSolver* otsolver, CollisionResult& result) {
231 node.result = &result;
233 node.model1 = &model1;
234 node.model2 = &model2;
236 node.otsolver = otsolver;
246 template <
typename BV>
247 bool initialize(HeightFieldOcTreeCollisionTraversalNode<BV>& node,
248 const HeightField<BV>& model1,
const Transform3s&
tf1,
249 const OcTree& model2,
const Transform3s&
tf2,
250 const OcTreeSolver* otsolver, CollisionResult& result) {
251 node.result = &result;
253 node.model1 = &model1;
254 node.model2 = &model2;
256 node.otsolver = otsolver;
266 template <
typename BV>
267 bool initialize(MeshOcTreeDistanceTraversalNode<BV>& node,
268 const BVHModel<BV>& model1,
const Transform3s&
tf1,
269 const OcTree& model2,
const Transform3s&
tf2,
270 const OcTreeSolver* otsolver,
const DistanceRequest& request,
271 DistanceResult& result) {
272 node.request = request;
273 node.result = &result;
275 node.model1 = &model1;
276 node.model2 = &model2;
278 node.otsolver = otsolver;
288 template <
typename BV>
289 bool initialize(OcTreeMeshDistanceTraversalNode<BV>& node,
const OcTree& model1,
290 const Transform3s&
tf1,
const BVHModel<BV>& model2,
291 const Transform3s&
tf2,
const OcTreeSolver* otsolver,
292 const DistanceRequest& request, DistanceResult& result) {
293 node.request = request;
294 node.result = &result;
296 node.model1 = &model1;
297 node.model2 = &model2;
299 node.otsolver = otsolver;
311 template <
typename S1,
typename S2>
312 bool initialize(ShapeCollisionTraversalNode<S1, S2>& node,
const S1& shape1,
313 const Transform3s&
tf1,
const S2& shape2,
314 const Transform3s&
tf2,
const GJKSolver* nsolver,
315 CollisionResult& result) {
316 node.model1 = &shape1;
318 node.model2 = &shape2;
320 node.nsolver = nsolver;
322 node.result = &result;
329 template <
typename BV,
typename S>
330 bool initialize(MeshShapeCollisionTraversalNode<BV, S>& node,
331 BVHModel<BV>& model1, Transform3s&
tf1,
const S& model2,
332 const Transform3s&
tf2,
const GJKSolver* nsolver,
333 CollisionResult& result,
bool use_refit =
false,
334 bool refit_bottomup =
false) {
337 "model1 should be of type BVHModelType::BVH_MODEL_TRIANGLES.",
338 std::invalid_argument)
340 if (!
tf1.isIdentity() &&
341 model1.vertices.get())
343 std::vector<Vec3s> vertices_transformed(model1.num_vertices);
344 const std::vector<Vec3s>& model1_vertices_ = *(model1.vertices);
345 for (
unsigned int i = 0; i < model1.num_vertices; ++i) {
346 const Vec3s& p = model1_vertices_[i];
348 vertices_transformed[i] = new_v;
351 model1.beginReplaceModel();
352 model1.replaceSubModel(vertices_transformed);
353 model1.endReplaceModel(use_refit, refit_bottomup);
358 node.model1 = &model1;
360 node.model2 = &model2;
362 node.nsolver = nsolver;
366 node.vertices = model1.vertices.get() ? model1.vertices->data() : NULL;
368 model1.tri_indices.get() ? model1.tri_indices->data() : NULL;
370 node.result = &result;
377 template <
typename BV,
typename S>
378 bool initialize(MeshShapeCollisionTraversalNode<BV, S, 0>& node,
379 const BVHModel<BV>& model1,
const Transform3s&
tf1,
380 const S& model2,
const Transform3s&
tf2,
381 const GJKSolver* nsolver, CollisionResult& result) {
384 "model1 should be of type BVHModelType::BVH_MODEL_TRIANGLES.",
385 std::invalid_argument)
387 node.model1 = &model1;
389 node.model2 = &model2;
391 node.nsolver = nsolver;
395 node.vertices = model1.vertices.get() ? model1.vertices->data() : NULL;
397 model1.tri_indices.get() ? model1.tri_indices->data() : NULL;
399 node.result = &result;
406 template <
typename BV,
typename S>
407 bool initialize(HeightFieldShapeCollisionTraversalNode<BV, S>& node,
408 HeightField<BV>& model1, Transform3s&
tf1,
const S& model2,
409 const Transform3s&
tf2,
const GJKSolver* nsolver,
410 CollisionResult& result,
bool use_refit =
false,
411 bool refit_bottomup =
false);
415 template <
typename BV,
typename S>
416 bool initialize(HeightFieldShapeCollisionTraversalNode<BV, S, 0>& node,
417 const HeightField<BV>& model1,
const Transform3s&
tf1,
418 const S& model2,
const Transform3s&
tf2,
419 const GJKSolver* nsolver, CollisionResult& result) {
420 node.model1 = &model1;
422 node.model2 = &model2;
424 node.nsolver = nsolver;
428 node.result = &result;
435 template <
typename S,
typename BV,
template <
typename>
class OrientedNode>
436 static inline bool setupShapeMeshCollisionOrientedNode(
437 OrientedNode<S>& node,
const S& model1,
const Transform3s&
tf1,
438 const BVHModel<BV>& model2,
const Transform3s&
tf2,
439 const GJKSolver* nsolver, CollisionResult& result) {
442 "model2 should be of type BVHModelType::BVH_MODEL_TRIANGLES.",
443 std::invalid_argument)
445 node.model1 = &model1;
447 node.model2 = &model2;
449 node.nsolver = nsolver;
453 node.vertices = model2.vertices.get() ? model2.vertices->data() : NULL;
455 model2.tri_indices.get() ? model2.tri_indices->data() : NULL;
457 node.result = &result;
466 template <
typename BV>
468 MeshCollisionTraversalNode<BV, RelativeTransformationIsIdentity>& node,
469 BVHModel<BV>& model1, Transform3s&
tf1, BVHModel<BV>& model2,
470 Transform3s&
tf2, CollisionResult& result,
bool use_refit =
false,
471 bool refit_bottomup =
false) {
474 "model1 should be of type BVHModelType::BVH_MODEL_TRIANGLES.",
475 std::invalid_argument)
478 "model2 should be of type BVHModelType::BVH_MODEL_TRIANGLES.",
479 std::invalid_argument)
481 if (!
tf1.isIdentity() && model1.vertices.get()) {
482 std::vector<Vec3s> vertices_transformed1(model1.num_vertices);
483 const std::vector<Vec3s>& model1_vertices_ = *(model1.vertices);
484 for (
unsigned int i = 0; i < model1.num_vertices; ++i) {
485 const Vec3s& p = model1_vertices_[i];
487 vertices_transformed1[i] = new_v;
490 model1.beginReplaceModel();
491 model1.replaceSubModel(vertices_transformed1);
492 model1.endReplaceModel(use_refit, refit_bottomup);
497 if (!
tf2.isIdentity() && model2.vertices.get()) {
498 std::vector<Vec3s> vertices_transformed2(model2.num_vertices);
499 const std::vector<Vec3s>& model2_vertices_ = *(model2.vertices);
500 for (
unsigned int i = 0; i < model2.num_vertices; ++i) {
501 const Vec3s& p = model2_vertices_[i];
503 vertices_transformed2[i] = new_v;
506 model2.beginReplaceModel();
507 model2.replaceSubModel(vertices_transformed2);
508 model2.endReplaceModel(use_refit, refit_bottomup);
513 node.model1 = &model1;
515 node.model2 = &model2;
518 node.vertices1 = model1.vertices.get() ? model1.vertices->data() : NULL;
519 node.vertices2 = model2.vertices.get() ? model2.vertices->data() : NULL;
522 model1.tri_indices.get() ? model1.tri_indices->data() : NULL;
524 model2.tri_indices.get() ? model2.tri_indices->data() : NULL;
526 node.result = &result;
531 template <
typename BV>
533 const BVHModel<BV>& model1,
const Transform3s&
tf1,
534 const BVHModel<BV>& model2,
const Transform3s&
tf2,
535 CollisionResult& result) {
538 "model1 should be of type BVHModelType::BVH_MODEL_TRIANGLES.",
539 std::invalid_argument)
542 "model2 should be of type BVHModelType::BVH_MODEL_TRIANGLES.",
543 std::invalid_argument)
545 node.vertices1 = model1.vertices ? model1.vertices->data() : NULL;
546 node.vertices2 = model2.vertices ? model2.vertices->data() : NULL;
549 model1.tri_indices.get() ? model1.tri_indices->data() : NULL;
551 model2.tri_indices.get() ? model2.tri_indices->data() : NULL;
553 node.model1 = &model1;
555 node.model2 = &model2;
558 node.result = &result;
560 node.RT.R.noalias() =
tf1.getRotation().transpose() *
tf2.getRotation();
561 node.RT.T.noalias() =
tf1.getRotation().transpose() *
562 (
tf2.getTranslation() -
tf1.getTranslation());
568 template <
typename S1,
typename S2>
569 bool initialize(ShapeDistanceTraversalNode<S1, S2>& node,
const S1& shape1,
570 const Transform3s&
tf1,
const S2& shape2,
571 const Transform3s&
tf2,
const GJKSolver* nsolver,
572 const DistanceRequest& request, DistanceResult& result) {
573 node.request = request;
574 node.result = &result;
576 node.model1 = &shape1;
578 node.model2 = &shape2;
580 node.nsolver = nsolver;
587 template <
typename BV>
589 MeshDistanceTraversalNode<BV, RelativeTransformationIsIdentity>& node,
590 BVHModel<BV>& model1, Transform3s&
tf1, BVHModel<BV>& model2,
591 Transform3s&
tf2,
const DistanceRequest& request, DistanceResult& result,
592 bool use_refit =
false,
bool refit_bottomup =
false) {
595 "model1 should be of type BVHModelType::BVH_MODEL_TRIANGLES.",
596 std::invalid_argument)
599 "model2 should be of type BVHModelType::BVH_MODEL_TRIANGLES.",
600 std::invalid_argument)
602 if (!
tf1.isIdentity() && model1.vertices.get()) {
603 std::vector<Vec3s> vertices_transformed1(model1.num_vertices);
604 const std::vector<Vec3s>& model1_vertices_ = *(model1.vertices);
605 for (
unsigned int i = 0; i < model1.num_vertices; ++i) {
606 const Vec3s& p = model1_vertices_[i];
608 vertices_transformed1[i] = new_v;
611 model1.beginReplaceModel();
612 model1.replaceSubModel(vertices_transformed1);
613 model1.endReplaceModel(use_refit, refit_bottomup);
618 if (!
tf2.isIdentity() && model2.vertices.get()) {
619 std::vector<Vec3s> vertices_transformed2(model2.num_vertices);
620 const std::vector<Vec3s>& model2_vertices_ = *(model2.vertices);
621 for (
unsigned int i = 0; i < model2.num_vertices; ++i) {
622 const Vec3s& p = model2_vertices_[i];
624 vertices_transformed2[i] = new_v;
627 model2.beginReplaceModel();
628 model2.replaceSubModel(vertices_transformed2);
629 model2.endReplaceModel(use_refit, refit_bottomup);
634 node.request = request;
635 node.result = &result;
637 node.model1 = &model1;
639 node.model2 = &model2;
642 node.vertices1 = model1.vertices.get() ? model1.vertices->data() : NULL;
643 node.vertices2 = model2.vertices.get() ? model2.vertices->data() : NULL;
646 model1.tri_indices.get() ? model1.tri_indices->data() : NULL;
648 model2.tri_indices.get() ? model2.tri_indices->data() : NULL;
654 template <
typename BV>
656 const BVHModel<BV>& model1,
const Transform3s&
tf1,
657 const BVHModel<BV>& model2,
const Transform3s&
tf2,
658 const DistanceRequest& request, DistanceResult& result) {
661 "model1 should be of type BVHModelType::BVH_MODEL_TRIANGLES.",
662 std::invalid_argument)
665 "model2 should be of type BVHModelType::BVH_MODEL_TRIANGLES.",
666 std::invalid_argument)
668 node.request = request;
669 node.result = &result;
671 node.model1 = &model1;
673 node.model2 = &model2;
676 node.vertices1 = model1.vertices.get() ? model1.vertices->data() : NULL;
677 node.vertices2 = model2.vertices.get() ? model2.vertices->data() : NULL;
680 model1.tri_indices.get() ? model1.tri_indices->data() : NULL;
682 model2.tri_indices.get() ? model2.tri_indices->data() : NULL;
688 tf2.getTranslation(), node.RT.R, node.RT.T);
697 template <
typename BV,
typename S>
699 BVHModel<BV>& model1, Transform3s&
tf1,
const S& model2,
700 const Transform3s&
tf2,
const GJKSolver* nsolver,
701 const DistanceRequest& request, DistanceResult& result,
702 bool use_refit =
false,
bool refit_bottomup =
false) {
705 "model1 should be of type BVHModelType::BVH_MODEL_TRIANGLES.",
706 std::invalid_argument)
708 if (!
tf1.isIdentity() && model1.vertices.get()) {
709 const std::vector<Vec3s>& model1_vertices_ = *(model1.vertices);
710 std::vector<Vec3s> vertices_transformed1(model1.num_vertices);
711 for (
unsigned int i = 0; i < model1.num_vertices; ++i) {
712 const Vec3s& p = model1_vertices_[i];
714 vertices_transformed1[i] = new_v;
717 model1.beginReplaceModel();
718 model1.replaceSubModel(vertices_transformed1);
719 model1.endReplaceModel(use_refit, refit_bottomup);
724 node.request = request;
725 node.result = &result;
727 node.model1 = &model1;
729 node.model2 = &model2;
731 node.nsolver = nsolver;
733 node.vertices = model1.vertices.get() ? model1.vertices->data() : NULL;
735 model1.tri_indices.get() ? model1.tri_indices->data() : NULL;
745 template <
typename BV,
typename S,
template <
typename>
class OrientedNode>
746 static inline bool setupMeshShapeDistanceOrientedNode(
747 OrientedNode<S>& node,
const BVHModel<BV>& model1,
const Transform3s&
tf1,
748 const S& model2,
const Transform3s&
tf2,
const GJKSolver* nsolver,
749 const DistanceRequest& request, DistanceResult& result) {
752 "model1 should be of type BVHModelType::BVH_MODEL_TRIANGLES.",
753 std::invalid_argument)
755 node.request = request;
756 node.result = &result;
758 node.model1 = &model1;
760 node.model2 = &model2;
762 node.nsolver = nsolver;
766 node.vertices = model1.vertices.get() ? model1.vertices->data() : NULL;
768 model1.tri_indices.get() ? model1.tri_indices->data() : NULL;
777 template <
typename S>
779 const BVHModel<RSS>& model1,
const Transform3s&
tf1,
780 const S& model2,
const Transform3s&
tf2,
781 const GJKSolver* nsolver,
const DistanceRequest& request,
782 DistanceResult& result) {
783 return details::setupMeshShapeDistanceOrientedNode(
784 node, model1,
tf1, model2,
tf2, nsolver, request, result);
789 template <
typename S>
791 const BVHModel<kIOS>& model1,
const Transform3s&
tf1,
792 const S& model2,
const Transform3s&
tf2,
793 const GJKSolver* nsolver,
const DistanceRequest& request,
794 DistanceResult& result) {
795 return details::setupMeshShapeDistanceOrientedNode(
796 node, model1,
tf1, model2,
tf2, nsolver, request, result);
801 template <
typename S>
803 const BVHModel<OBBRSS>& model1,
const Transform3s&
tf1,
804 const S& model2,
const Transform3s&
tf2,
805 const GJKSolver* nsolver,
const DistanceRequest& request,
806 DistanceResult& result) {
807 return details::setupMeshShapeDistanceOrientedNode(
808 node, model1,
tf1, model2,
tf2, nsolver, request, result);