38 #ifndef FCL_TRAVERSAL_SHAPEMESHCOLLISIONTRAVERSALNODE_INL_H 39 #define FCL_TRAVERSAL_SHAPEMESHCOLLISIONTRAVERSALNODE_INL_H 41 #include "fcl/narrowphase/detail/traversal/collision/shape_mesh_collision_traversal_node.h" 50 template <
typename Shape,
typename BV,
typename NarrowPhaseSolver>
51 ShapeMeshCollisionTraversalNode<Shape, BV, NarrowPhaseSolver>::ShapeMeshCollisionTraversalNode()
52 : ShapeBVHCollisionTraversalNode<Shape, BV>()
55 tri_indices =
nullptr;
61 template <
typename Shape,
typename BV,
typename NarrowPhaseSolver>
64 using S =
typename BV::S;
67 const BVNode<BV>& node = this->model2->getBV(b2);
71 const Triangle& tri_id = tri_indices[primitive_id];
73 const Vector3<S>& p1 = vertices[tri_id[0]];
74 const Vector3<S>& p2 = vertices[tri_id[1]];
75 const Vector3<S>& p3 = vertices[tri_id[2]];
77 if(this->model1->isOccupied() && this->model2->isOccupied())
79 bool is_intersect =
false;
83 if(nsolver->shapeTriangleIntersect(*(this->model1), this->tf1, p1, p2, p3,
nullptr,
nullptr,
nullptr))
96 if(nsolver->shapeTriangleIntersect(*(this->model1), this->tf1, p1, p2, p3, &contactp, &penetration, &normal))
113 else if((!this->model1->isFree() && !this->model2->isFree()) && this->
request.
enable_cost)
115 if(nsolver->shapeTriangleIntersect(*(this->model1), this->tf1, p1, p2, p3,
nullptr,
nullptr,
nullptr))
127 template <
typename Shape,
typename BV,
typename NarrowPhaseSolver>
134 template <
typename Shape,
typename BV,
typename NarrowPhaseSolver>
138 const Transform3<typename BV::S>&
tf1,
140 Transform3<typename BV::S>&
tf2,
141 const NarrowPhaseSolver* nsolver,
147 using S =
typename BV::S;
152 if(!tf2.matrix().isIdentity())
154 std::vector<Vector3<S>> vertices_transformed(model2.
num_vertices);
158 Vector3<S> new_v = tf2 * p;
159 vertices_transformed[i] = new_v;
169 node.model1 = &model1;
171 node.model2 = &model2;
173 node.nsolver = nsolver;
183 node.cost_density = model1.cost_density * model2.
cost_density;
189 template <
typename Shape,
typename NarrowPhaseSolver>
195 template <
typename Shape,
typename NarrowPhaseSolver>
199 return !
overlap(this->tf2.linear(), this->tf2.translation(), this->model1_bv, this->model2->
getBV(b2).bv);
203 template <
typename Shape,
typename NarrowPhaseSolver>
206 detail::meshShapeCollisionOrientedNodeLeafTesting(b2, b1, *(this->model2), this->model1, this->vertices, this->tri_indices,
207 this->tf2, this->tf1, this->nsolver, this->
enable_statistics, this->cost_density, this->num_leaf_tests, this->request, *(this->request));
213 template <
typename Shape,
typename NarrowPhaseSolver>
219 template <
typename Shape,
typename NarrowPhaseSolver>
223 return !
overlap(this->tf2.linear(), this->tf2.translation(), this->model1_bv, this->model2->
getBV(b2).bv);
227 template <
typename Shape,
typename NarrowPhaseSolver>
230 detail::meshShapeCollisionOrientedNodeLeafTesting(b2, b1, *(this->model2), this->model1, this->vertices, this->tri_indices,
231 this->tf2, this->tf1, this->nsolver, this->
enable_statistics, this->cost_density, this->num_leaf_tests, this->request, *(this->request));
237 template <
typename Shape,
typename NarrowPhaseSolver>
243 template <
typename Shape,
typename NarrowPhaseSolver>
247 return !
overlap(this->tf2.linear(), this->tf2.translation(), this->model1_bv, this->model2->
getBV(b2).bv);
251 template <
typename Shape,
typename NarrowPhaseSolver>
254 detail::meshShapeCollisionOrientedNodeLeafTesting(b2, b1, *(this->model2), this->model1, this->vertices, this->tri_indices,
255 this->tf2, this->tf1, this->nsolver, this->
enable_statistics, this->cost_density, this->num_leaf_tests, this->request, *(this->request));
261 template <
typename Shape,
typename NarrowPhaseSolver>
267 template <
typename Shape,
typename NarrowPhaseSolver>
271 return !
overlap(this->tf2.linear(), this->tf2.translation(), this->model1_bv, this->model2->
getBV(b2).bv);
275 template <
typename Shape,
typename NarrowPhaseSolver>
278 detail::meshShapeCollisionOrientedNodeLeafTesting(b2, b1, *(this->model2), this->model1, this->vertices, this->tri_indices,
279 this->tf2, this->tf1, this->nsolver, this->
enable_statistics, this->cost_density, this->num_leaf_tests, this->request, *(this->request));
284 template <
typename Shape,
typename BV,
typename NarrowPhaseSolver,
template <
typename,
typename>
class OrientedNode>
285 static bool setupShapeMeshCollisionOrientedNode(OrientedNode<Shape, NarrowPhaseSolver>& node,
286 const Shape& model1,
const Transform3<typename BV::S>& tf1,
287 const BVHModel<BV>& model2,
const Transform3<typename BV::S>& tf2,
288 const NarrowPhaseSolver* nsolver,
295 node.model1 = &model1;
297 node.model2 = &model2;
299 node.nsolver = nsolver;
309 node.cost_density = model1.cost_density * model2.
cost_density;
315 template <
typename Shape,
typename NarrowPhaseSolver>
319 const Transform3<typename Shape::S>& tf1,
321 const Transform3<typename Shape::S>& tf2,
322 const NarrowPhaseSolver* nsolver,
326 return detail::setupShapeMeshCollisionOrientedNode(
327 node, model1, tf1, model2, tf2, nsolver, request, result);
331 template <
typename Shape,
typename NarrowPhaseSolver>
335 const Transform3<typename Shape::S>& tf1,
337 const Transform3<typename Shape::S>& tf2,
338 const NarrowPhaseSolver* nsolver,
342 return detail::setupShapeMeshCollisionOrientedNode(
343 node, model1, tf1, model2, tf2, nsolver, request, result);
347 template <
typename Shape,
typename NarrowPhaseSolver>
351 const Transform3<typename Shape::S>& tf1,
353 const Transform3<typename Shape::S>& tf2,
354 const NarrowPhaseSolver* nsolver,
358 return detail::setupShapeMeshCollisionOrientedNode(
359 node, model1, tf1, model2, tf2, nsolver, request, result);
363 template <
typename Shape,
typename NarrowPhaseSolver>
367 const Transform3<typename Shape::S>& tf1,
369 const Transform3<typename Shape::S>& tf2,
370 const NarrowPhaseSolver* nsolver,
374 return detail::setupShapeMeshCollisionOrientedNode(
375 node, model1, tf1, model2, tf2, nsolver, request, result);
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
Transform3< Shape1::S > tf2
configuration of second object
Definition: traversal_node_base.h:88
void leafTesting(int b1, int b2) const
Intersection testing between leaves (one shape and one triangle)
Definition: shape_mesh_collision_traversal_node-inl.h:62
Vector3< S > * vertices
Geometry point data.
Definition: BVH_model.h:162
void leafTesting(int b1, int b2) const
Leaf test between node b1 and b2, if they are both leafs.
Definition: shape_mesh_collision_traversal_node-inl.h:252
int num_vertices
Number of points.
Definition: BVH_model.h:174
CollisionRequest< Shape1::S > request
request setting for collision
Definition: collision_traversal_node_base.h:72
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
bool enable_contact
whether the contact information (normal, penetration depth and contact position) will return ...
Definition: collision_request.h:58
Traversal node for collision between shape and mesh.
Definition: shape_mesh_collision_traversal_node.h:52
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
bool BVTesting(int b1, int b2) const
BV test between b1 and b2.
Definition: shape_mesh_collision_traversal_node-inl.h:196
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< Shape1::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< Shape1::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
void leafTesting(int b1, int b2) const
Leaf test between node b1 and b2, if they are both leafs.
Definition: shape_mesh_collision_traversal_node-inl.h:204
bool canStop() const
Whether the traversal process can stop early.
Definition: shape_mesh_collision_traversal_node-inl.h:128
Definition: shape_mesh_collision_traversal_node.h:142
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 BVTesting(int b1, int b2) const
BV test between b1 and b2.
Definition: shape_mesh_collision_traversal_node-inl.h:244
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
Traversal node for shape and mesh, when mesh BVH is one of the oriented node (OBB, RSS, OBBRSS, kIOS)
Definition: shape_mesh_collision_traversal_node.h:90