38 #ifndef FCL_TRAVERSAL_MESHSHAPEDISTANCETRAVERSALNODE_INL_H 39 #define FCL_TRAVERSAL_MESHSHAPEDISTANCETRAVERSALNODE_INL_H 41 #include "fcl/narrowphase/detail/traversal/distance/mesh_shape_distance_traversal_node.h" 50 template <
typename BV,
typename Shape,
typename NarrowPhaseSolver>
51 MeshShapeDistanceTraversalNode<BV, Shape, NarrowPhaseSolver>::
52 MeshShapeDistanceTraversalNode()
53 : BVHShapeDistanceTraversalNode<BV, Shape>()
56 tri_indices =
nullptr;
65 template <
typename BV,
typename Shape,
typename NarrowPhaseSolver>
75 const Triangle& tri_id = tri_indices[primitive_id];
77 const Vector3<S>& p1 = vertices[tri_id[0]];
78 const Vector3<S>& p2 = vertices[tri_id[1]];
79 const Vector3<S>& p3 = vertices[tri_id[2]];
82 Vector3<S> closest_p1, closest_p2;
83 nsolver->shapeTriangleDistance(*(this->model2), this->
tf2, p1, p2, p3, &d, &closest_p2, &closest_p1);
96 template <
typename BV,
typename Shape,
typename NarrowPhaseSolver>
100 if((c >= this->
result->
min_distance - abs_err) && (c * (1 + rel_err) >= this->result->min_distance))
106 template <
typename BV,
typename Shape,
typename NarrowPhaseSolver>
110 Transform3<typename Shape::S>&
tf1,
112 const Transform3<typename BV::S>&
tf2,
113 const NarrowPhaseSolver* nsolver,
119 using S =
typename BV::S;
124 if(!tf1.matrix().isIdentity())
126 std::vector<Vector3<S>> vertices_transformed1(model1.
num_vertices);
130 Vector3<S> new_v = tf1 * p;
131 vertices_transformed1[i] = new_v;
144 node.model1 = &model1;
146 node.model2 = &model2;
148 node.nsolver = nsolver;
159 template <
typename BV,
typename Shape,
typename NarrowPhaseSolver>
160 void meshShapeDistanceOrientedNodeLeafTesting(
163 Vector3<typename BV::S>* vertices,
Triangle* tri_indices,
164 const Transform3<typename BV::S>& tf1,
165 const Transform3<typename BV::S>& tf2,
166 const NarrowPhaseSolver* nsolver,
168 int & num_leaf_tests,
172 using S =
typename BV::S;
174 if(enable_statistics) num_leaf_tests++;
179 const Triangle& tri_id = tri_indices[primitive_id];
180 const Vector3<S>& p1 = vertices[tri_id[0]];
181 const Vector3<S>& p2 = vertices[tri_id[1]];
182 const Vector3<S>& p3 = vertices[tri_id[2]];
185 Vector3<S> closest_p1, closest_p2;
186 nsolver->shapeTriangleDistance(model2, tf2, p1, p2, p3, tf1, &distance, &closest_p2, &closest_p1);
199 template <
typename BV,
typename Shape,
typename NarrowPhaseSolver>
200 void distancePreprocessOrientedNode(
202 Vector3<typename BV::S>* vertices,
206 const Transform3<typename BV::S>& tf1,
207 const Transform3<typename BV::S>& tf2,
208 const NarrowPhaseSolver* nsolver,
212 using S =
typename BV::S;
214 const Triangle& init_tri = tri_indices[init_tri_id];
216 const Vector3<S>& p1 = vertices[init_tri[0]];
217 const Vector3<S>& p2 = vertices[init_tri[1]];
218 const Vector3<S>& p3 = vertices[init_tri[2]];
221 Vector3<S> closest_p1, closest_p2;
222 nsolver->shapeTriangleDistance(model2, tf2, p1, p2, p3, tf1, &distance, &closest_p2, &closest_p1);
235 template <
typename Shape,
typename NarrowPhaseSolver>
244 template <
typename Shape,
typename NarrowPhaseSolver>
247 detail::distancePreprocessOrientedNode(
261 template <
typename Shape,
typename NarrowPhaseSolver>
267 template <
typename Shape,
typename NarrowPhaseSolver>
270 int b1,
int b2)
const 272 if(this->enable_statistics) this->num_bv_tests++;
274 return distance(this->tf1.linear(), this->tf1.translation(), this->model2_bv, this->model1->
getBV(b1).bv);
278 template <
typename Shape,
typename NarrowPhaseSolver>
282 detail::meshShapeDistanceOrientedNodeLeafTesting(
292 this->enable_statistics,
293 this->num_leaf_tests,
299 template <
typename Shape,
typename NarrowPhaseSolver>
305 template <
typename Shape,
typename NarrowPhaseSolver>
308 detail::distancePreprocessOrientedNode(this->model1, this->vertices, this->tri_indices, 0,
309 *(this->model2), this->tf1, this->tf2, this->nsolver, this->request, *(this->result));
313 template <
typename Shape,
typename NarrowPhaseSolver>
319 template <
typename Shape,
typename NarrowPhaseSolver>
322 if(this->enable_statistics) this->num_bv_tests++;
324 return distance(this->tf1.linear(), this->tf1.translation(), this->model2_bv, this->model1->
getBV(b1).bv);
328 template <
typename Shape,
typename NarrowPhaseSolver>
331 detail::meshShapeDistanceOrientedNodeLeafTesting(b1, b2, this->model1, *(this->model2), this->vertices, this->tri_indices,
332 this->tf1, this->tf2, this->nsolver, this->enable_statistics, this->num_leaf_tests, this->request, *(this->result));
336 template <
typename Shape,
typename NarrowPhaseSolver>
342 template <
typename Shape,
typename NarrowPhaseSolver>
345 detail::distancePreprocessOrientedNode(this->model1, this->vertices, this->tri_indices, 0,
346 *(this->model2), this->tf1, this->tf2, this->nsolver, this->request, *(this->result));
350 template <
typename Shape,
typename NarrowPhaseSolver>
357 template <
typename Shape,
typename NarrowPhaseSolver>
362 if(this->enable_statistics) this->num_bv_tests++;
364 return distance(this->tf1.linear(), this->tf1.translation(), this->model2_bv, this->model1->
getBV(b1).bv);
368 template <
typename Shape,
typename NarrowPhaseSolver>
371 detail::meshShapeDistanceOrientedNodeLeafTesting(b1, b2, this->model1, *(this->model2), this->vertices, this->tri_indices,
372 this->tf1, this->tf2, this->nsolver, this->enable_statistics, this->num_leaf_tests, this->request, *(this->result));
375 template <
typename BV,
typename Shape,
typename NarrowPhaseSolver,
template <
typename,
typename>
class OrientedNode>
376 static bool setupMeshShapeDistanceOrientedNode(OrientedNode<Shape, NarrowPhaseSolver>& node,
377 const BVHModel<BV>& model1,
const Transform3<typename BV::S>& tf1,
378 const Shape& model2,
const Transform3<typename BV::S>& tf2,
379 const NarrowPhaseSolver* nsolver,
389 node.model1 = &model1;
391 node.model2 = &model2;
393 node.nsolver = nsolver;
404 template <
typename Shape,
typename NarrowPhaseSolver>
407 const BVHModel<RSS<typename Shape::S>>& model1,
const Transform3<typename Shape::S>& tf1,
408 const Shape& model2,
const Transform3<typename Shape::S>& tf2,
409 const NarrowPhaseSolver* nsolver,
413 return detail::setupMeshShapeDistanceOrientedNode(node, model1, tf1, model2, tf2, nsolver, request, result);
417 template <
typename Shape,
typename NarrowPhaseSolver>
421 const Shape& model2,
const Transform3<typename Shape::S>& tf2,
422 const NarrowPhaseSolver* nsolver,
426 return detail::setupMeshShapeDistanceOrientedNode(node, model1, tf1, model2, tf2, nsolver, request, result);
430 template <
typename Shape,
typename NarrowPhaseSolver>
434 const Shape& model2,
const Transform3<typename Shape::S>& tf2,
435 const NarrowPhaseSolver* nsolver,
439 return detail::setupMeshShapeDistanceOrientedNode(node, model1, tf1, model2, tf2, nsolver, request, result);
bool canStop(S c) const
Whether the traversal process can stop early.
Definition: mesh_shape_distance_traversal_node-inl.h:98
S min_distance
minimum distance between two objects. if two objects are in collision, min_distance <= 0...
Definition: distance_result.h:56
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
Traversal node for distance between mesh and shape.
Definition: mesh_shape_distance_traversal_node.h:52
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
Transform3< OBBRSS< Shape::S >::S > tf2
configuration of second object
Definition: traversal_node_base.h:88
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
void leafTesting(int b1, int b2) const
Leaf test between node b1 and b2, if they are both leafs.
Definition: mesh_shape_distance_traversal_node-inl.h:329
void computeBV(const Shape &s, const Transform3< typename BV::S > &tf, BV &bv)
calculate a bounding volume for a shape in a specific configuration
Definition: utility-inl.h:1049
DistanceRequest< OBBRSS< Shape::S >::S > request
request setting for distance
Definition: distance_traversal_node_base.h:73
Definition: mesh_shape_distance_traversal_node.h:151
A class describing the bounding hierarchy of a mesh model or a point cloud model (which is viewed as ...
Definition: BVH_model.h:57
void leafTesting(int b1, int b2) const
Distance testing between leaves (one triangle and one shape)
Definition: mesh_shape_distance_traversal_node-inl.h:67
DistanceResult< OBBRSS< Shape::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< Shape::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
S BVTesting(int b1, int b2) const
BV test between b1 and b2.
Definition: mesh_shape_distance_traversal_node-inl.h:320
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
A class describing the kIOS collision structure, which is a set of spheres.
Definition: kIOS.h:48