38 #ifndef FCL_TRAVERSAL_MESHSHAPECOLLISIONTRAVERSALNODE_INL_H 39 #define FCL_TRAVERSAL_MESHSHAPECOLLISIONTRAVERSALNODE_INL_H 41 #include "fcl/narrowphase/detail/traversal/collision/mesh_shape_collision_traversal_node.h" 50 template <
typename BV,
typename Shape,
typename NarrowPhaseSolver>
51 MeshShapeCollisionTraversalNode<BV, Shape, NarrowPhaseSolver>::MeshShapeCollisionTraversalNode()
52 : BVHShapeCollisionTraversalNode<BV, Shape>()
55 tri_indices =
nullptr;
61 template <
typename BV,
typename Shape,
typename NarrowPhaseSolver>
69 const Triangle& tri_id = tri_indices[primitive_id];
71 const Vector3<S>& p1 = vertices[tri_id[0]];
72 const Vector3<S>& p2 = vertices[tri_id[1]];
73 const Vector3<S>& p3 = vertices[tri_id[2]];
75 if(this->
model1->isOccupied() && this->
model2->isOccupied())
77 bool is_intersect =
false;
81 if(nsolver->shapeTriangleIntersect(*(this->model2), this->tf2, p1, p2, p3,
nullptr,
nullptr,
nullptr))
94 if(nsolver->shapeTriangleIntersect(*(this->model2), this->tf2, p1, p2, p3, &contactp, &penetration, &normal))
113 if(nsolver->shapeTriangleIntersect(*(this->model2), this->tf2, p1, p2, p3,
nullptr,
nullptr,
nullptr))
125 template <
typename BV,
typename Shape,
typename NarrowPhaseSolver>
132 template <
typename BV,
typename Shape,
typename NarrowPhaseSolver>
136 Transform3<typename BV::S>&
tf1,
138 const Transform3<typename BV::S>&
tf2,
139 const NarrowPhaseSolver* nsolver,
145 using S =
typename BV::S;
150 if(!tf1.matrix().isIdentity())
152 std::vector<Vector3<S>> vertices_transformed(model1.
num_vertices);
156 Vector3<S> new_v = tf1 * p;
157 vertices_transformed[i] = new_v;
171 node.nsolver = nsolver;
181 node.cost_density = model1.
cost_density * model2.cost_density;
187 template <
typename BV,
typename Shape,
typename NarrowPhaseSolver>
188 void meshShapeCollisionOrientedNodeLeafTesting(
191 Vector3<typename BV::S>* vertices,
Triangle* tri_indices,
192 const Transform3<typename BV::S>& tf1,
193 const Transform3<typename BV::S>& tf2,
194 const NarrowPhaseSolver* nsolver,
196 typename BV::S cost_density,
201 using S =
typename BV::S;
203 if(enable_statistics) num_leaf_tests++;
208 const Triangle& tri_id = tri_indices[primitive_id];
210 const Vector3<S>& p1 = vertices[tri_id[0]];
211 const Vector3<S>& p2 = vertices[tri_id[1]];
212 const Vector3<S>& p3 = vertices[tri_id[2]];
214 if(model1->
isOccupied() && model2.isOccupied())
216 bool is_intersect =
false;
220 if(nsolver->shapeTriangleIntersect(model2, tf2, p1, p2, p3, tf1,
nullptr,
nullptr,
nullptr))
233 if(nsolver->shapeTriangleIntersect(model2, tf2, p1, p2, p3, tf1, &contactp, &penetration, &normal))
246 AABB<S>(tf1 * p1, tf1 * p2, tf1 * p3).
overlap(shape_aabb, overlap_part);
252 if(nsolver->shapeTriangleIntersect(model2, tf2, p1, p2, p3, tf1,
nullptr,
nullptr,
nullptr))
257 AABB<S>(tf1 * p1, tf1 * p2, tf1 * p3).
overlap(shape_aabb, overlap_part);
264 template <
typename Shape,
typename NarrowPhaseSolver>
272 template <
typename Shape,
typename NarrowPhaseSolver>
277 return !
overlap(this->tf1.linear(), this->tf1.translation(), this->model2_bv, this->model1->
getBV(b1).bv);
281 template <
typename Shape,
typename NarrowPhaseSolver>
284 detail::meshShapeCollisionOrientedNodeLeafTesting(b1, b2, this->model1, *(this->model2), this->vertices, this->tri_indices,
285 this->tf1, this->tf2, this->nsolver, this->enable_statistics, this->cost_density, this->num_leaf_tests, this->request, *(this->result));
289 template <
typename Shape,
typename NarrowPhaseSolver>
296 template <
typename Shape,
typename NarrowPhaseSolver>
301 return !
overlap(this->tf1.linear(), this->tf1.translation(), this->model2_bv, this->model1->
getBV(b1).bv);
305 template <
typename Shape,
typename NarrowPhaseSolver>
308 detail::meshShapeCollisionOrientedNodeLeafTesting(b1, b2, this->model1, *(this->model2), this->vertices, this->tri_indices,
309 this->tf1, this->tf2, this->nsolver, this->enable_statistics, this->cost_density, this->num_leaf_tests, this->request, *(this->result));
313 template <
typename Shape,
typename NarrowPhaseSolver>
321 template <
typename Shape,
typename NarrowPhaseSolver>
326 return !
overlap(this->tf1.linear(), this->tf1.translation(), this->model2_bv, this->model1->
getBV(b1).bv);
330 template <
typename Shape,
typename NarrowPhaseSolver>
333 detail::meshShapeCollisionOrientedNodeLeafTesting(b1, b2, this->model1, *(this->model2), this->vertices, this->tri_indices,
334 this->tf1, this->tf2, this->nsolver, this->enable_statistics, this->cost_density, this->num_leaf_tests, this->request, *(this->result));
338 template <
typename Shape,
typename NarrowPhaseSolver>
346 template <
typename Shape,
typename NarrowPhaseSolver>
350 return !
overlap(this->tf1.linear(), this->tf1.translation(), this->model2_bv, this->model1->
getBV(b1).bv);
354 template <
typename Shape,
typename NarrowPhaseSolver>
357 detail::meshShapeCollisionOrientedNodeLeafTesting(b1, b2, this->model1, *(this->model2), this->vertices, this->tri_indices,
358 this->tf1, this->tf2, this->nsolver, this->enable_statistics, this->cost_density, this->num_leaf_tests, this->request, *(this->result));
361 template <
typename BV,
typename Shape,
typename NarrowPhaseSolver,
362 template <
typename,
typename>
class OrientedNode>
363 bool setupMeshShapeCollisionOrientedNode(
364 OrientedNode<Shape, NarrowPhaseSolver>& node,
366 const Transform3<typename BV::S>& tf1,
367 const Shape& model2,
const Transform3<typename BV::S>& tf2,
368 const NarrowPhaseSolver* nsolver,
379 node.nsolver = nsolver;
389 node.cost_density = model1.
cost_density * model2.cost_density;
395 template <
typename Shape,
typename NarrowPhaseSolver>
399 const Transform3<typename Shape::S>& tf1,
401 const Transform3<typename Shape::S>& tf2,
402 const NarrowPhaseSolver* nsolver,
406 return detail::setupMeshShapeCollisionOrientedNode(
407 node, model1, tf1, model2, tf2, nsolver, request, result);
411 template <
typename Shape,
typename NarrowPhaseSolver>
415 const Transform3<typename Shape::S>& tf1,
417 const Transform3<typename Shape::S>& tf2,
418 const NarrowPhaseSolver* nsolver,
422 return detail::setupMeshShapeCollisionOrientedNode(
423 node, model1, tf1, model2, tf2, nsolver, request, result);
427 template <
typename Shape,
typename NarrowPhaseSolver>
431 const Transform3<typename Shape::S>& tf1,
433 const Transform3<typename Shape::S>& tf2,
434 const NarrowPhaseSolver* nsolver,
438 return detail::setupMeshShapeCollisionOrientedNode(
439 node, model1, tf1, model2, tf2, nsolver, request, result);
443 template <
typename Shape,
typename NarrowPhaseSolver>
447 const Transform3<typename Shape::S>& tf1,
449 const Transform3<typename Shape::S>& tf2,
450 const NarrowPhaseSolver* nsolver,
454 return detail::setupMeshShapeCollisionOrientedNode(
455 node, model1, tf1, model2, tf2, nsolver, request, result);
void leafTesting(int b1, int b2) const
Leaf test between node b1 and b2, if they are both leafs.
Definition: mesh_shape_collision_traversal_node-inl.h:282
Traversal node for collision between mesh and shape.
Definition: mesh_shape_collision_traversal_node.h:52
void leafTesting(int b1, int b2) const
Leaf test between node b1 and b2, if they are both leafs.
Definition: mesh_shape_collision_traversal_node-inl.h:331
bool enable_cost
whether the cost sources will be computed
Definition: collision_request.h:64
bool enable_statistics
Whether stores statistics.
Definition: collision_traversal_node_base.h:78
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
size_t num_max_contacts
The maximum number of contacts will return.
Definition: collision_request.h:55
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
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
void leafTesting(int b1, int b2) const
Intersection testing between leaves (one triangle and one shape)
Definition: mesh_shape_collision_traversal_node-inl.h:62
Transform3< BV::S > tf2
configuration of second object
Definition: traversal_node_base.h:88
size_t numContacts() const
number of contacts found
Definition: collision_result-inl.h:83
Vector3< S > * vertices
Geometry point data.
Definition: BVH_model.h:162
bool BVTesting(int b1, int b2) const
BV test between b1 and b2.
Definition: mesh_shape_collision_traversal_node-inl.h:273
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
bool canStop() const
Whether the traversal process can stop early.
Definition: mesh_shape_collision_traversal_node-inl.h:126
unknown model type
Definition: BVH_internal.h:78
bool enable_contact
whether the contact information (normal, penetration depth and contact position) will return ...
Definition: collision_request.h:58
Traversal node for mesh and shape, when mesh BVH is one of the oriented node (OBB, RSS, OBBRSS, kIOS)
Definition: mesh_shape_collision_traversal_node.h:108
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 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
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
int num_bv_tests
statistical information
Definition: bvh_collision_traversal_node.h:92
bool BVTesting(int b1, int b2) const
BV test between b1 and b2.
Definition: mesh_shape_collision_traversal_node-inl.h:322
Definition: mesh_shape_collision_traversal_node.h:162
bool isOccupied() const
whether the object is completely occupied
const BVHModel< BV > * model2
The second BVH model.
Definition: bvh_collision_traversal_node.h:89
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
A class describing the kIOS collision structure, which is a set of spheres.
Definition: kIOS.h:48
Oriented bounding box class.
Definition: OBB.h:51
void addContact(const Contact< S > &c)
add one contact into result structure
Definition: collision_result-inl.h:59