38 #ifndef FCL_TRAVERSAL_SHAPEMESHDISTANCETRAVERSALNODE_INL_H 39 #define FCL_TRAVERSAL_SHAPEMESHDISTANCETRAVERSALNODE_INL_H 41 #include "fcl/narrowphase/detail/traversal/distance/shape_mesh_distance_traversal_node.h" 50 template <
typename Shape,
typename BV,
typename NarrowPhaseSolver>
51 ShapeMeshDistanceTraversalNode<Shape, BV, NarrowPhaseSolver>::
52 ShapeMeshDistanceTraversalNode()
53 : ShapeBVHDistanceTraversalNode<Shape, BV>()
56 tri_indices =
nullptr;
65 template <
typename Shape,
typename BV,
typename NarrowPhaseSolver>
68 using S =
typename BV::S;
76 const Triangle& tri_id = tri_indices[primitive_id];
78 const Vector3<S>& p1 = vertices[tri_id[0]];
79 const Vector3<S>& p2 = vertices[tri_id[1]];
80 const Vector3<S>& p3 = vertices[tri_id[2]];
83 Vector3<S> closest_p1, closest_p2;
84 nsolver->shapeTriangleDistance(*(this->model1), this->
tf1, p1, p2, p3, &distance, &closest_p1, &closest_p2);
97 template <
typename Shape,
typename BV,
typename NarrowPhaseSolver>
100 if((c >= this->
result->
min_distance - abs_err) && (c * (1 + rel_err) >= this->result->min_distance))
106 template <
typename Shape,
typename BV,
typename NarrowPhaseSolver>
110 const Transform3<typename BV::S>&
tf1,
112 Transform3<typename BV::S>&
tf2,
113 const NarrowPhaseSolver* nsolver,
119 using S =
typename BV::S;
124 if(!tf2.matrix().isIdentity())
126 std::vector<Vector3<S>> vertices_transformed(model2.
num_vertices);
130 Vector3<S> new_v = tf2 * p;
131 vertices_transformed[i] = new_v;
144 node.model1 = &model1;
146 node.model2 = &model2;
148 node.nsolver = nsolver;
159 template <
typename Shape,
typename NarrowPhaseSolver>
166 template <
typename Shape,
typename NarrowPhaseSolver>
169 detail::distancePreprocessOrientedNode(
170 this->model2, this->vertices, this->tri_indices, 0,
171 *(this->model1), this->tf2, this->tf1, this->nsolver, this->request, *(this->result));
175 template <
typename Shape,
typename NarrowPhaseSolver>
181 template <
typename Shape,
typename NarrowPhaseSolver>
187 return distance(this->tf2.linear(), this->tf2.translation(), this->model1_bv, this->model2->
getBV(b2).bv);
191 template <
typename Shape,
typename NarrowPhaseSolver>
195 detail::meshShapeDistanceOrientedNodeLeafTesting(b2, b1, this->model2, *(this->model1), this->vertices, this->tri_indices,
196 this->tf2, this->tf1, this->nsolver, this->
enable_statistics, this->num_leaf_tests, this->request, *(this->result));
200 template <
typename Shape,
typename NarrowPhaseSolver>
208 template <
typename Shape,
typename NarrowPhaseSolver>
211 detail::distancePreprocessOrientedNode(
224 template <
typename Shape,
typename NarrowPhaseSolver>
230 template <
typename Shape,
typename NarrowPhaseSolver>
236 return distance(this->tf2.linear(), this->tf2.translation(), this->model1_bv, this->model2->
getBV(b2).bv);
240 template <
typename Shape,
typename NarrowPhaseSolver>
244 detail::meshShapeDistanceOrientedNodeLeafTesting(b2, b1, this->model2, *(this->model1), this->vertices, this->tri_indices,
245 this->tf2, this->tf1, this->nsolver, this->
enable_statistics, this->num_leaf_tests, this->request, *(this->result));
249 template <
typename Shape,
typename NarrowPhaseSolver>
256 template <
typename Shape,
typename NarrowPhaseSolver>
259 detail::distancePreprocessOrientedNode(
272 template <
typename Shape,
typename NarrowPhaseSolver>
279 template <
typename Shape,
typename NarrowPhaseSolver>
285 return distance(this->tf2.linear(), this->tf2.translation(), this->model1_bv, this->model2->
getBV(b2).bv);
289 template <
typename Shape,
typename NarrowPhaseSolver>
293 detail::meshShapeDistanceOrientedNodeLeafTesting(
304 this->num_leaf_tests,
309 template <
typename Shape,
typename BV,
typename NarrowPhaseSolver,
template <
typename,
typename>
class OrientedNode>
310 static bool setupShapeMeshDistanceOrientedNode(OrientedNode<Shape, NarrowPhaseSolver>& node,
311 const Shape& model1,
const Transform3<typename BV::S>& tf1,
312 const BVHModel<BV>& model2,
const Transform3<typename BV::S>& tf2,
313 const NarrowPhaseSolver* nsolver,
323 node.model1 = &model1;
325 node.model2 = &model2;
327 node.nsolver = nsolver;
333 node.R = tf2.linear();
334 node.T = tf2.translation();
340 template <
typename Shape,
typename NarrowPhaseSolver>
342 const Shape& model1,
const Transform3<typename Shape::S>& tf1,
344 const NarrowPhaseSolver* nsolver,
348 return detail::setupShapeMeshDistanceOrientedNode(node, model1, tf1, model2, tf2, nsolver, request, result);
352 template <
typename Shape,
typename NarrowPhaseSolver>
354 const Shape& model1,
const Transform3<typename Shape::S>& tf1,
356 const NarrowPhaseSolver* nsolver,
360 return detail::setupShapeMeshDistanceOrientedNode(node, model1, tf1, model2, tf2, nsolver, request, result);
364 template <
typename Shape,
typename NarrowPhaseSolver>
366 const Shape& model1,
const Transform3<typename Shape::S>& tf1,
368 const NarrowPhaseSolver* nsolver,
372 return detail::setupShapeMeshDistanceOrientedNode(node, model1, tf1, model2, tf2, nsolver, request, result);
Traversal node for distance between shape and mesh.
Definition: shape_mesh_distance_traversal_node.h:52
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
Definition: shape_mesh_distance_traversal_node.h:126
S BVTesting(int b1, int b2) const
BV test between b1 and b2.
Definition: shape_mesh_distance_traversal_node-inl.h:233
void leafTesting(int b1, int b2) const
Leaf test between node b1 and b2, if they are both leafs.
Definition: shape_mesh_distance_traversal_node-inl.h:242
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
bool canStop(S c) const
Whether the traversal process can stop early.
Definition: shape_mesh_distance_traversal_node-inl.h:98
unknown model type
Definition: BVH_internal.h:78
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
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 shape and one triangle)
Definition: shape_mesh_distance_traversal_node-inl.h:66
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
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