38 #ifndef FCL_TRAVERSAL_MESHDISTANCETRAVERSALNODE_INL_H 39 #define FCL_TRAVERSAL_MESHDISTANCETRAVERSALNODE_INL_H 41 #include "fcl/narrowphase/detail/traversal/distance/mesh_distance_traversal_node.h" 51 class MeshDistanceTraversalNodeRSS<double>;
56 MeshDistanceTraversalNodeRSS<double>& node,
57 const BVHModel<RSS<double>>& model1,
58 const Transform3<double>& tf1,
59 const BVHModel<RSS<double>>& model2,
60 const Transform3<double>& tf2,
61 const DistanceRequest<double>& request,
62 DistanceResult<double>& result);
66 class MeshDistanceTraversalNodekIOS<double>;
71 MeshDistanceTraversalNodekIOS<double>& node,
72 const BVHModel<kIOS<double>>& model1,
73 const Transform3<double>& tf1,
74 const BVHModel<kIOS<double>>& model2,
75 const Transform3<double>& tf2,
76 const DistanceRequest<double>& request,
77 DistanceResult<double>& result);
81 class MeshDistanceTraversalNodeOBBRSS<double>;
86 MeshDistanceTraversalNodeOBBRSS<double>& node,
87 const BVHModel<OBBRSS<double>>& model1,
88 const Transform3<double>& tf1,
89 const BVHModel<OBBRSS<double>>& model2,
90 const Transform3<double>& tf2,
91 const DistanceRequest<double>& request,
92 DistanceResult<double>& result);
95 template <
typename BV>
96 MeshDistanceTraversalNode<BV>::MeshDistanceTraversalNode() : BVHDistanceTraversalNode<BV>()
100 tri_indices1 =
nullptr;
101 tri_indices2 =
nullptr;
104 abs_err = this->
request.abs_err;
108 template <
typename BV>
119 const Triangle& tri_id1 = tri_indices1[primitive_id1];
120 const Triangle& tri_id2 = tri_indices2[primitive_id2];
122 const Vector3<S>& t11 = vertices1[tri_id1[0]];
123 const Vector3<S>& t12 = vertices1[tri_id1[1]];
124 const Vector3<S>& t13 = vertices1[tri_id1[2]];
126 const Vector3<S>& t21 = vertices2[tri_id2[0]];
127 const Vector3<S>& t22 = vertices2[tri_id2[1]];
128 const Vector3<S>& t23 = vertices2[tri_id2[2]];
147 template <
typename BV>
156 template <
typename BV>
160 Transform3<typename BV::S>&
tf1,
162 Transform3<typename BV::S>&
tf2,
168 using S =
typename BV::S;
173 if(!tf1.matrix().isIdentity())
175 std::vector<Vector3<S>> vertices_transformed1(model1.
num_vertices);
179 Vector3<S> new_v = tf1 * p;
180 vertices_transformed1[i] = new_v;
190 if(!tf2.matrix().isIdentity())
192 std::vector<Vector3<S>> vertices_transformed2(model2.
num_vertices);
196 Vector3<S> new_v = tf2 * p;
197 vertices_transformed2[i] = new_v;
225 template <
typename S>
228 tf(Transform3<S>::Identity())
233 template <
typename S>
236 detail::distancePreprocessOrientedNode(
251 template <
typename S>
254 detail::distancePostprocessOrientedNode(
263 template <
typename S>
266 detail::meshDistanceOrientedNodeLeafTesting(
277 this->num_leaf_tests,
283 template <
typename S>
286 tf(Transform3<S>::Identity())
292 template <
typename S>
295 detail::distancePreprocessOrientedNode(
310 template <
typename S>
313 detail::distancePostprocessOrientedNode(
322 template <
typename S>
325 detail::meshDistanceOrientedNodeLeafTesting(
336 this->num_leaf_tests,
342 template <
typename S>
345 tf(Transform3<S>::Identity())
351 template <
typename S>
354 detail::distancePreprocessOrientedNode(
369 template <
typename S>
372 detail::distancePostprocessOrientedNode(
381 template <
typename S>
384 detail::meshDistanceOrientedNodeLeafTesting(
395 this->num_leaf_tests,
401 template <
typename BV>
402 void meshDistanceOrientedNodeLeafTesting(
int b1,
406 Vector3<typename BV::S>* vertices1,
407 Vector3<typename BV::S>* vertices2,
410 const Matrix3<typename BV::S>& R,
411 const Vector3<typename BV::S>& T,
417 using S =
typename BV::S;
419 if(enable_statistics) num_leaf_tests++;
427 const Triangle& tri_id1 = tri_indices1[primitive_id1];
428 const Triangle& tri_id2 = tri_indices2[primitive_id2];
430 const Vector3<S>& t11 = vertices1[tri_id1[0]];
431 const Vector3<S>& t12 = vertices1[tri_id1[1]];
432 const Vector3<S>& t13 = vertices1[tri_id1[2]];
434 const Vector3<S>& t21 = vertices2[tri_id2[0]];
435 const Vector3<S>& t22 = vertices2[tri_id2[1]];
436 const Vector3<S>& t23 = vertices2[tri_id2[2]];
446 result.
update(d, model1, model2, primitive_id1, primitive_id2, P1, P2);
448 result.
update(d, model1, model2, primitive_id1, primitive_id2);
452 template <
typename BV>
453 void meshDistanceOrientedNodeLeafTesting(
458 Vector3<typename BV::S>* vertices1,
459 Vector3<typename BV::S>* vertices2,
462 const Transform3<typename BV::S>& tf,
463 bool enable_statistics,
468 using S =
typename BV::S;
470 if(enable_statistics) num_leaf_tests++;
478 const Triangle& tri_id1 = tri_indices1[primitive_id1];
479 const Triangle& tri_id2 = tri_indices2[primitive_id2];
481 const Vector3<S>& t11 = vertices1[tri_id1[0]];
482 const Vector3<S>& t12 = vertices1[tri_id1[1]];
483 const Vector3<S>& t13 = vertices1[tri_id1[2]];
485 const Vector3<S>& t21 = vertices2[tri_id2[0]];
486 const Vector3<S>& t22 = vertices2[tri_id2[1]];
487 const Vector3<S>& t23 = vertices2[tri_id2[2]];
493 t11, t12, t13, t21, t22, t23, tf, P1, P2);
496 result.
update(d, model1, model2, primitive_id1, primitive_id2, P1, P2);
498 result.
update(d, model1, model2, primitive_id1, primitive_id2);
502 template <
typename BV>
503 void distancePreprocessOrientedNode(
506 const Vector3<typename BV::S>* vertices1,
507 Vector3<typename BV::S>* vertices2,
512 const Matrix3<typename BV::S>& R,
513 const Vector3<typename BV::S>& T,
517 using S =
typename BV::S;
519 const Triangle& init_tri1 = tri_indices1[init_tri_id1];
520 const Triangle& init_tri2 = tri_indices2[init_tri_id2];
522 Vector3<S> init_tri1_points[3];
523 Vector3<S> init_tri2_points[3];
525 init_tri1_points[0] = vertices1[init_tri1[0]];
526 init_tri1_points[1] = vertices1[init_tri1[1]];
527 init_tri1_points[2] = vertices1[init_tri1[2]];
529 init_tri2_points[0] = vertices2[init_tri2[0]];
530 init_tri2_points[1] = vertices2[init_tri2[1]];
531 init_tri2_points[2] = vertices2[init_tri2[2]];
535 init_tri2_points[0], init_tri2_points[1], init_tri2_points[2],
539 result.
update(distance, model1, model2, init_tri_id1, init_tri_id2, p1, p2);
541 result.
update(distance, model1, model2, init_tri_id1, init_tri_id2);
545 template <
typename BV>
546 void distancePreprocessOrientedNode(
549 const Vector3<typename BV::S>* vertices1,
550 Vector3<typename BV::S>* vertices2,
555 const Transform3<typename BV::S>& tf,
559 using S =
typename BV::S;
561 const Triangle& init_tri1 = tri_indices1[init_tri_id1];
562 const Triangle& init_tri2 = tri_indices2[init_tri_id2];
564 Vector3<S> init_tri1_points[3];
565 Vector3<S> init_tri2_points[3];
567 init_tri1_points[0] = vertices1[init_tri1[0]];
568 init_tri1_points[1] = vertices1[init_tri1[1]];
569 init_tri1_points[2] = vertices1[init_tri1[2]];
571 init_tri2_points[0] = vertices2[init_tri2[0]];
572 init_tri2_points[1] = vertices2[init_tri2[1]];
573 init_tri2_points[2] = vertices2[init_tri2[2]];
578 init_tri1_points[0], init_tri1_points[1], init_tri1_points[2],
579 init_tri2_points[0], init_tri2_points[1], init_tri2_points[2],
583 result.
update(distance, model1, model2, init_tri_id1, init_tri_id2, p1, p2);
585 result.
update(distance, model1, model2, init_tri_id1, init_tri_id2);
589 template <
typename BV>
590 void distancePostprocessOrientedNode(
593 const Transform3<typename BV::S>& tf1,
605 template <
typename BV,
typename OrientedNode>
606 static bool setupMeshDistanceOrientedNode(
608 const BVHModel<BV>& model1,
const Transform3<typename BV::S>& tf1,
609 const BVHModel<BV>& model2,
const Transform3<typename BV::S>& tf2,
630 node.tf = tf1.inverse(Eigen::Isometry) *
tf2;
636 template <
typename S>
640 const Transform3<S>& tf1,
642 const Transform3<S>& tf2,
646 return detail::setupMeshDistanceOrientedNode(
647 node, model1, tf1, model2, tf2, request, result);
651 template <
typename S>
655 const Transform3<S>& tf1,
657 const Transform3<S>& tf2,
661 return detail::setupMeshDistanceOrientedNode(
662 node, model1, tf1, model2, tf2, request, result);
666 template <
typename S>
670 const Transform3<S>& tf1,
672 const Transform3<S>& tf2,
676 return detail::setupMeshDistanceOrientedNode(
677 node, model1, tf1, model2, tf2, request, result);
const BVHModel< OBBRSS< S > > * model1
The first BVH model.
Definition: bvh_distance_traversal_node.h:87
S min_distance
minimum distance between two objects. if two objects are in collision, min_distance <= 0...
Definition: distance_result.h:56
bool canStop(S c) const
Whether the traversal process can stop early.
Definition: mesh_distance_traversal_node-inl.h:148
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
S rel_err
relative and absolute error, default value is 0.01 for both terms
Definition: mesh_distance_traversal_node.h:76
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
distance result
Definition: distance_request.h:48
void update(S distance, const CollisionGeometry< S > *o1_, const CollisionGeometry< S > *o2_, int b1_, int b2_)
add distance information into the result
Definition: distance_result-inl.h:64
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
Definition: mesh_distance_traversal_node.h:135
Transform3< OBBRSS< S >::S > tf2
configuration of second object
Definition: traversal_node_base.h:88
void leafTesting(int b1, int b2) const
Distance testing between leaves (two triangles)
Definition: mesh_distance_traversal_node-inl.h:109
const CollisionGeometry< S > * o2
collision object 2
Definition: distance_result.h:65
Vector3< S > * vertices
Geometry point data.
Definition: BVH_model.h:162
int num_vertices
Number of points.
Definition: BVH_model.h:174
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
unknown model type
Definition: BVH_internal.h:78
S rel_err
error threshold for approximate distance
Definition: distance_request.h:58
bool enable_nearest_points
whether to return the nearest points
Definition: distance_request.h:55
DistanceRequest< OBBRSS< S >::S > request
request setting for distance
Definition: distance_traversal_node_base.h:73
const CollisionGeometry< S > * o1
collision object 1
Definition: distance_result.h:62
A class describing the bounding hierarchy of a mesh model or a point cloud model (which is viewed as ...
Definition: BVH_model.h:57
const BVHModel< OBBRSS< S > > * model2
The second BVH model.
Definition: bvh_distance_traversal_node.h:89
DistanceResult< OBBRSS< S >::S > * result
distance result kept during the traversal iteration
Definition: distance_traversal_node_base.h:76
A class describing a bounding volume node. It includes the tree structure providing in BVNodeBase and...
Definition: BV_node.h:52
Transform3< OBBRSS< S >::S > tf1
configuation of first object
Definition: traversal_node_base.h:85
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
void leafTesting(int b1, int b2) const
Leaf test between node b1 and b2, if they are both leafs.
Definition: mesh_distance_traversal_node-inl.h:323
Vector3< S > nearest_points[2]
nearest points
Definition: distance_result.h:59
request to the distance computation
Definition: distance_request.h:52
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
bool enable_statistics
Whether stores statistics.
Definition: distance_traversal_node_base.h:79
Traversal node for distance computation between two meshes.
Definition: mesh_distance_traversal_node.h:55
static S triDistance(const Vector3< S > T1[3], const Vector3< S > T2[3], Vector3< S > &P, Vector3< S > &Q)
Compute the closest points on two triangles given their absolute coordinate, and returns the distance...
Definition: triangle_distance-inl.h:171