38 #ifndef FCL_TRAVERSAL_MESHSHAPECONSERVATIVEADVANCEMENTTRAVERSALNODE_INL_H 39 #define FCL_TRAVERSAL_MESHSHAPECONSERVATIVEADVANCEMENTTRAVERSALNODE_INL_H 41 #include "fcl/narrowphase/detail/traversal/distance/mesh_shape_conservative_advancement_traversal_node.h" 50 template <
typename BV,
typename Shape,
typename NarrowPhaseSolver>
51 MeshShapeConservativeAdvancementTraversalNode<BV, Shape, NarrowPhaseSolver>::
52 MeshShapeConservativeAdvancementTraversalNode(S w_) :
53 MeshShapeDistanceTraversalNode<BV, Shape, NarrowPhaseSolver>()
66 template <
typename BV,
typename Shape,
typename NarrowPhaseSolver>
73 S d = this->model2_bv.distance(this->
model1->
getBV(b1).
bv, &P2, &P1);
75 stack.emplace_back(P1, P2, b1, b2, d);
81 template <
typename BV,
typename Shape,
typename NarrowPhaseSolver>
91 const Triangle& tri_id = this->tri_indices[primitive_id];
93 const Vector3<S>& p1 = this->vertices[tri_id[0]];
94 const Vector3<S>& p2 = this->vertices[tri_id[1]];
95 const Vector3<S>& p3 = this->vertices[tri_id[2]];
99 this->nsolver->shapeTriangleDistance(*(this->
model2), this->
tf2, p1, p2, p3, &d, &P2, &P1);
101 if(d < this->min_distance)
103 this->min_distance = d;
108 last_tri_id = primitive_id;
111 Vector3<S> n = this->
tf2 * p2 - P1; n.normalize();
115 S bound1 = motion1->computeMotionBound(mb_visitor1);
116 S bound2 = motion2->computeMotionBound(mb_visitor2);
118 S bound = bound1 + bound2;
121 if(bound <= d) cur_delta_t = 1;
122 else cur_delta_t = d / bound;
124 if(cur_delta_t < delta_t)
125 delta_t = cur_delta_t;
129 template <
typename BV,
typename Shape,
typename NarrowPhaseSolver>
133 if((c >= w * (this->min_distance - this->abs_err))
134 && (c * (1 + this->
rel_err) >= w * this->min_distance))
136 const auto& data = stack.back();
138 Vector3<S> n = this->
tf2 * data.P2 - data.P1; n.normalize();
143 S bound1 = motion1->computeMotionBound(mb_visitor1);
144 S bound2 = motion2->computeMotionBound(mb_visitor2);
146 S bound = bound1 + bound2;
149 if(bound < c) cur_delta_t = 1;
150 else cur_delta_t = c / bound;
152 if(cur_delta_t < delta_t)
153 delta_t = cur_delta_t;
168 template <
typename BV,
typename Shape,
typename NarrowPhaseSolver>
172 const Transform3<typename BV::S>&
tf1,
174 const Transform3<typename BV::S>&
tf2,
175 const NarrowPhaseSolver* nsolver,
180 using S =
typename BV::S;
182 std::vector<Vector3<S>> vertices_transformed(model1.
num_vertices);
186 Vector3<S> new_v = tf1 * p;
187 vertices_transformed[i] = new_v;
203 node.nsolver = nsolver;
206 computeBV(model2, Transform3<S>::Identity(), node.model2_bv);
212 template <
typename BV,
typename Shape,
typename NarrowPhaseSolver>
213 void meshShapeConservativeAdvancementOrientedNodeLeafTesting(
219 Vector3<typename BV::S>* vertices,
221 const Transform3<typename BV::S>& tf1,
222 const Transform3<typename BV::S>& tf2,
225 const NarrowPhaseSolver* nsolver,
227 typename BV::S& min_distance,
228 Vector3<typename BV::S>& p1,
229 Vector3<typename BV::S>& p2,
231 typename BV::S& delta_t,
234 using S =
typename BV::S;
236 if(enable_statistics) num_leaf_tests++;
241 const Triangle& tri_id = tri_indices[primitive_id];
242 const Vector3<S>& t1 = vertices[tri_id[0]];
243 const Vector3<S>& t2 = vertices[tri_id[1]];
244 const Vector3<S>& t3 = vertices[tri_id[2]];
247 Vector3<S> P1 = Vector3<S>::Zero();
248 Vector3<S> P2 = Vector3<S>::Zero();
249 nsolver->shapeTriangleDistance(model2, tf2, t1, t2, t3, tf1, &distance, &P2, &P1);
251 if(distance < min_distance)
258 last_tri_id = primitive_id;
262 Vector3<S> n = P2 - P1; n.normalize();
269 S bound = bound1 + bound2;
272 if(bound <= distance) cur_delta_t = 1;
273 else cur_delta_t = distance / bound;
275 if(cur_delta_t < delta_t)
276 delta_t = cur_delta_t;
280 template <
typename BV,
typename Shape>
281 bool meshShapeConservativeAdvancementOrientedNodeCanStop(
283 typename BV::S min_distance,
284 typename BV::S abs_err,
293 typename BV::S& delta_t)
295 using S =
typename BV::S;
297 if((c >= w * (min_distance - abs_err)) && (c * (1 + rel_err) >= w * min_distance))
299 const auto& data = stack.back();
300 Vector3<S> n = data.P2 - data.P1; n.normalize();
309 S bound = bound1 + bound2;
312 if(bound <= c) cur_delta_t = 1;
313 else cur_delta_t = c / bound;
315 if(cur_delta_t < delta_t)
316 delta_t = cur_delta_t;
330 template <
typename Shape,
typename NarrowPhaseSolver>
334 RSS<S>, Shape, NarrowPhaseSolver>(w_)
340 template <
typename Shape,
typename NarrowPhaseSolver>
347 S d =
distance(this->tf1.linear(), this->tf1.translation(), this->model1->
getBV(b1).bv, this->model2_bv, &P1, &P2);
349 this->stack.emplace_back(P1, P2, b1, b2, d);
355 template <
typename Shape,
typename NarrowPhaseSolver>
360 detail::meshShapeConservativeAdvancementOrientedNodeLeafTesting(
373 this->enable_statistics,
379 this->num_leaf_tests);
383 template <
typename Shape,
typename NarrowPhaseSolver>
386 canStop(
typename Shape::S c)
const 388 return detail::meshShapeConservativeAdvancementOrientedNodeCanStop(
404 template <
typename Shape,
typename NarrowPhaseSolver>
408 const Transform3<typename Shape::S>& tf1,
410 const Transform3<typename Shape::S>& tf2,
411 const NarrowPhaseSolver* nsolver,
414 using S =
typename Shape::S;
420 node.nsolver = nsolver;
424 computeBV(model2, Transform3<S>::Identity(), node.model2_bv);
430 template <
typename Shape,
typename NarrowPhaseSolver>
433 typename Shape::S w_)
441 template <
typename Shape,
typename NarrowPhaseSolver>
448 S d =
distance(this->tf1.linear(), this->tf1.translation(), this->model1->
getBV(b1).bv, this->model2_bv, &P1, &P2);
450 this->stack.emplace_back(P1, P2, b1, b2, d);
456 template <
typename Shape,
typename NarrowPhaseSolver>
461 detail::meshShapeConservativeAdvancementOrientedNodeLeafTesting(
474 this->enable_statistics,
480 this->num_leaf_tests);
484 template <
typename Shape,
typename NarrowPhaseSolver>
487 canStop(
typename Shape::S c)
const 489 return detail::meshShapeConservativeAdvancementOrientedNodeCanStop(
505 template <
typename Shape,
typename NarrowPhaseSolver>
509 const Transform3<typename Shape::S>& tf1,
511 const Transform3<typename Shape::S>& tf2,
512 const NarrowPhaseSolver* nsolver,
515 using S =
typename Shape::S;
521 node.nsolver = nsolver;
525 computeBV(model2, Transform3<S>::Identity(), node.model2_bv);
const BVHModel< OBBRSS< S > > * model1
The first BVH model.
Definition: bvh_distance_traversal_node.h:87
Definition: motion_base.h:52
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
virtual S computeMotionBound(const BVMotionBoundVisitor< S > &mb_visitor) const =0
Compute the motion bound for a bounding volume, given the closest direction n between two query objec...
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
S BVTesting(int b1, int b2) const
BV culling test in one BVTT node.
Definition: mesh_shape_conservative_advancement_traversal_node-inl.h:69
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< 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
Traversal node for conservative advancement computation between BVH and shape.
Definition: mesh_shape_conservative_advancement_traversal_node.h:52
Definition: tbv_motion_bound_visitor.h:65
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
int num_bv_tests
statistical information
Definition: bvh_distance_traversal_node.h:92
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 canStop(S c) const
Whether the traversal process can stop early.
Definition: mesh_shape_conservative_advancement_traversal_node-inl.h:131
void leafTesting(int b1, int b2) const
Conservative advancement testing between leaves (one triangle and one shape)
Definition: mesh_shape_conservative_advancement_traversal_node-inl.h:83
Definition: bv_motion_bound_visitor.h:45
Definition: conservative_advancement_stack_data.h:50
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 bv
bounding volume storing the geometry
Definition: BV_node.h:57
const BVHModel< OBBRSS< S > > * model2
The second BVH model.
Definition: bvh_distance_traversal_node.h:89
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
S w
CA controlling variable: early stop for the early iterations of CA.
Definition: mesh_shape_conservative_advancement_traversal_node.h:77
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