38 #ifndef FCL_TRAVERSAL_SHAPEMESHCONSERVATIVEADVANCEMENTTRAVERSALNODE_INL_H 39 #define FCL_TRAVERSAL_SHAPEMESHCONSERVATIVEADVANCEMENTTRAVERSALNODE_INL_H 41 #include "fcl/narrowphase/detail/traversal/distance/shape_mesh_conservative_advancement_traversal_node.h" 50 template <
typename Shape,
typename BV,
typename NarrowPhaseSolver>
51 ShapeMeshConservativeAdvancementTraversalNode<Shape, BV, NarrowPhaseSolver>::
52 ShapeMeshConservativeAdvancementTraversalNode(S w_)
53 : ShapeMeshDistanceTraversalNode<Shape, BV, NarrowPhaseSolver>()
66 template <
typename Shape,
typename BV,
typename NarrowPhaseSolver>
73 S d = this->model1_bv.distance(this->model2->getBV(b2).bv, &P1, &P2);
75 stack.emplace_back(P1, P2, b1, b2, d);
81 template <
typename Shape,
typename BV,
typename NarrowPhaseSolver>
86 const BVNode<BV>& node = this->model2->getBV(b2);
90 const Triangle& tri_id = this->tri_indices[primitive_id];
92 const Vector3<S>& p1 = this->vertices[tri_id[0]];
93 const Vector3<S>& p2 = this->vertices[tri_id[1]];
94 const Vector3<S>& p3 = this->vertices[tri_id[2]];
98 this->nsolver->shapeTriangleDistance(*(this->model1), this->
tf1, p1, p2, p3, &d, &P1, &P2);
100 if(d < this->min_distance)
102 this->min_distance = d;
107 last_tri_id = primitive_id;
110 Vector3<S> n = P2 - this->
tf1 * p1; n.normalize();
114 S bound1 = motion1->computeMotionBound(mb_visitor1);
115 S bound2 = motion2->computeMotionBound(mb_visitor2);
117 S bound = bound1 + bound2;
120 if(bound <= d) cur_delta_t = 1;
121 else cur_delta_t = d / bound;
123 if(cur_delta_t < delta_t)
124 delta_t = cur_delta_t;
128 template <
typename Shape,
typename BV,
typename NarrowPhaseSolver>
132 if((c >= w * (this->min_distance - this->abs_err)) && (c * (1 + this->rel_err) >= w * this->min_distance))
134 const auto& data = stack.back();
136 Vector3<S> n = data.P2 - this->
tf1 * data.P1; n.normalize();
141 S bound1 = motion1->computeMotionBound(mb_visitor1);
142 S bound2 = motion2->computeMotionBound(mb_visitor2);
144 S bound = bound1 + bound2;
147 if(bound < c) cur_delta_t = 1;
148 else cur_delta_t = c / bound;
150 if(cur_delta_t < delta_t)
151 delta_t = cur_delta_t;
166 template <
typename Shape,
typename BV,
typename NarrowPhaseSolver>
170 const Transform3<typename BV::S>&
tf1,
172 const Transform3<typename BV::S>&
tf2,
173 const NarrowPhaseSolver* nsolver,
178 using S =
typename BV::S;
180 std::vector<Vector3<S>> vertices_transformed(model2.
num_vertices);
184 Vector3<S> new_v = tf2 * p;
185 vertices_transformed[i] = new_v;
192 node.model1 = &model1;
193 node.model2 = &model2;
201 node.nsolver = nsolver;
204 computeBV(model1, Transform3<S>::Identity(), node.model1_bv);
210 template <
typename Shape,
typename NarrowPhaseSolver>
213 typename Shape::S w_)
221 template <
typename Shape,
typename NarrowPhaseSolver>
226 using S =
typename Shape::S;
230 S d =
distance(this->tf2.linear(), this->tf2.translation(), this->model2->
getBV(b2).bv, this->model1_bv, &P2, &P1);
232 this->stack.emplace_back(P1, P2, b1, b2, d);
238 template <
typename Shape,
typename NarrowPhaseSolver>
242 detail::meshShapeConservativeAdvancementOrientedNodeLeafTesting(
261 this->num_leaf_tests);
265 template <
typename Shape,
typename NarrowPhaseSolver>
267 canStop(
typename Shape::S c)
const 269 return detail::meshShapeConservativeAdvancementOrientedNodeCanStop(
285 template <
typename Shape,
typename NarrowPhaseSolver>
289 const Transform3<typename Shape::S>& tf1,
290 const BVHModel<RSS<typename Shape::S>>& model2,
291 const Transform3<typename Shape::S>& tf2,
292 const NarrowPhaseSolver* nsolver,
295 using S =
typename Shape::S;
297 node.model1 = &model1;
299 node.model2 = &model2;
301 node.nsolver = nsolver;
305 computeBV(model1, Transform3<S>::Identity(), node.model1_bv);
311 template <
typename Shape,
typename NarrowPhaseSolver>
314 typename Shape::S w_)
321 template <
typename Shape,
typename NarrowPhaseSolver>
326 using S =
typename Shape::S;
330 S d =
distance(this->tf2.linear(), this->tf2.translation(), this->model2->
getBV(b2).bv, this->model1_bv, &P2, &P1);
332 this->stack.emplace_back(P1, P2, b1, b2, d);
338 template <
typename Shape,
typename NarrowPhaseSolver>
342 detail::meshShapeConservativeAdvancementOrientedNodeLeafTesting(
361 this->num_leaf_tests);
365 template <
typename Shape,
typename NarrowPhaseSolver>
367 canStop(
typename Shape::S c)
const 369 return detail::meshShapeConservativeAdvancementOrientedNodeCanStop(
385 template <
typename Shape,
typename NarrowPhaseSolver>
389 const Transform3<typename Shape::S>& tf1,
390 const BVHModel<OBBRSS<typename Shape::S>>& model2,
391 const Transform3<typename Shape::S>& tf2,
392 const NarrowPhaseSolver* nsolver,
395 using S =
typename Shape::S;
397 node.model1 = &model1;
399 node.model2 = &model2;
401 node.nsolver = nsolver;
405 computeBV(model1, Transform3<S>::Identity(), node.model1_bv);
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
bool canStop(S c) const
Whether the traversal process can stop early.
Definition: shape_mesh_conservative_advancement_traversal_node-inl.h:130
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
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
Vector3< S > * vertices
Geometry point data.
Definition: BVH_model.h:162
int num_vertices
Number of points.
Definition: BVH_model.h:174
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
S BVTesting(int b1, int b2) const
BV culling test in one BVTT node.
Definition: shape_mesh_conservative_advancement_traversal_node-inl.h:69
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
void leafTesting(int b1, int b2) const
Conservative advancement testing between leaves (one triangle and one shape)
Definition: shape_mesh_conservative_advancement_traversal_node-inl.h:82
A class describing the bounding hierarchy of a mesh model or a point cloud model (which is viewed as ...
Definition: BVH_model.h:57
S w
CA controlling variable: early stop for the early iterations of CA.
Definition: shape_mesh_conservative_advancement_traversal_node.h:77
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
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
Definition: shape_mesh_conservative_advancement_traversal_node.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