mesh_continuous_collision_traversal_node-inl.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011-2014, Willow Garage, Inc.
5  * Copyright (c) 2014-2016, Open Source Robotics Foundation
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of Open Source Robotics Foundation nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
38 #ifndef FCL_TRAVERSAL_MESHCONTINUOUSCOLLISIONTRAVERSALNODE_INL_H
39 #define FCL_TRAVERSAL_MESHCONTINUOUSCOLLISIONTRAVERSALNODE_INL_H
40 
42 
44 
45 namespace fcl
46 {
47 
48 namespace detail
49 {
50 
51 //==============================================================================
52 extern template
53 struct BVHContinuousCollisionPair<double>;
54 
55 //==============================================================================
56 template <typename S>
58 {
59  // Do nothing
60 }
61 
62 //==============================================================================
63 template <typename S>
65  int id1_, int id2_, S time)
66  : id1(id1_), id2(id2_), collision_time(time)
67 {
68  // Do nothing
69 }
70 
71 //==============================================================================
72 template <typename BV>
75 {
76  vertices1 = nullptr;
77  vertices2 = nullptr;
78  tri_indices1 = nullptr;
79  tri_indices2 = nullptr;
80  prev_vertices1 = nullptr;
81  prev_vertices2 = nullptr;
82 
83  num_vf_tests = 0;
84  num_ee_tests = 0;
85  time_of_contact = 1;
86 }
87 
88 //==============================================================================
89 template <typename BV>
91 {
92  if(this->enable_statistics) this->num_leaf_tests++;
93 
94  const BVNode<BV>& node1 = this->model1->getBV(b1);
95  const BVNode<BV>& node2 = this->model2->getBV(b2);
96 
97  S collision_time = 2;
98  Vector3<S> collision_pos;
99 
100  int primitive_id1 = node1.primitiveId();
101  int primitive_id2 = node2.primitiveId();
102 
103  const Triangle& tri_id1 = tri_indices1[primitive_id1];
104  const Triangle& tri_id2 = tri_indices2[primitive_id2];
105 
106  Vector3<S>* S0[3];
107  Vector3<S>* S1[3];
108  Vector3<S>* T0[3];
109  Vector3<S>* T1[3];
110 
111  for(int i = 0; i < 3; ++i)
112  {
113  S0[i] = prev_vertices1 + tri_id1[i];
114  S1[i] = vertices1 + tri_id1[i];
115  T0[i] = prev_vertices2 + tri_id2[i];
116  T1[i] = vertices2 + tri_id2[i];
117  }
118 
119  S tmp;
120  Vector3<S> tmpv;
121 
122  // 6 VF checks
123  for(int i = 0; i < 3; ++i)
124  {
125  if(this->enable_statistics) num_vf_tests++;
126  if(Intersect<S>::intersect_VF(*(S0[0]), *(S0[1]), *(S0[2]), *(T0[i]), *(S1[0]), *(S1[1]), *(S1[2]), *(T1[i]), &tmp, &tmpv))
127  {
128  if(collision_time > tmp)
129  {
130  collision_time = tmp; collision_pos = tmpv;
131  }
132  }
133 
134  if(this->enable_statistics) num_vf_tests++;
135  if(Intersect<S>::intersect_VF(*(T0[0]), *(T0[1]), *(T0[2]), *(S0[i]), *(T1[0]), *(T1[1]), *(T1[2]), *(S1[i]), &tmp, &tmpv))
136  {
137  if(collision_time > tmp)
138  {
139  collision_time = tmp; collision_pos = tmpv;
140  }
141  }
142  }
143 
144  // 9 EE checks
145  for(int i = 0; i < 3; ++i)
146  {
147  int S_id1 = i;
148  int S_id2 = i + 1;
149  if(S_id2 == 3) S_id2 = 0;
150  for(int j = 0; j < 3; ++j)
151  {
152  int T_id1 = j;
153  int T_id2 = j + 1;
154  if(T_id2 == 3) T_id2 = 0;
155 
156  num_ee_tests++;
157  if(Intersect<S>::intersect_EE(*(S0[S_id1]), *(S0[S_id2]), *(T0[T_id1]), *(T0[T_id2]), *(S1[S_id1]), *(S1[S_id2]), *(T1[T_id1]), *(T1[T_id2]), &tmp, &tmpv))
158  {
159  if(collision_time > tmp)
160  {
161  collision_time = tmp; collision_pos = tmpv;
162  }
163  }
164  }
165  }
166 
167  if(!(collision_time > 1)) // collision happens
168  {
169  pairs.emplace_back(primitive_id1, primitive_id2, collision_time);
170  time_of_contact = std::min(time_of_contact, collision_time);
171  }
172 }
173 
174 //==============================================================================
175 template <typename BV>
177 {
178  return (pairs.size() > 0) && (this->request.num_max_contacts <= pairs.size());
179 }
180 
181 //==============================================================================
182 template <typename BV>
185  const BVHModel<BV>& model1,
186  const Transform3<typename BV::S>& tf1,
187  const BVHModel<BV>& model2,
188  const Transform3<typename BV::S>& tf2,
189  const CollisionRequest<typename BV::S>& request)
190 {
191  node.model1 = &model1;
192  node.tf1 = tf1;
193  node.model2 = &model2;
194  node.tf2 = tf2;
195 
196  node.vertices1 = model1.vertices;
197  node.vertices2 = model2.vertices;
198 
199  node.tri_indices1 = model1.tri_indices;
200  node.tri_indices2 = model2.tri_indices;
201 
202  node.prev_vertices1 = model1.prev_vertices;
203  node.prev_vertices2 = model2.prev_vertices;
204 
205  node.request = request;
206 
207  return true;
208 }
209 
210 } // namespace detail
211 } // namespace fcl
212 
213 #endif
fcl::Transform3
Eigen::Transform< S, 3, Eigen::Isometry > Transform3
Definition: types.h:91
fcl::detail::MeshContinuousCollisionTraversalNode
Traversal node for continuous collision between meshes.
Definition: mesh_continuous_collision_traversal_node.h:69
fcl::BVHModel::vertices
Vector3< S > * vertices
Geometry point data.
Definition: BVH_model.h:162
mesh_continuous_collision_traversal_node.h
fcl::detail::MeshContinuousCollisionTraversalNode::tri_indices2
Triangle * tri_indices2
Definition: mesh_continuous_collision_traversal_node.h:88
fcl::detail::MeshContinuousCollisionTraversalNode::prev_vertices2
Vector3< S > * prev_vertices2
Definition: mesh_continuous_collision_traversal_node.h:91
fcl::detail::MeshContinuousCollisionTraversalNode::tri_indices1
Triangle * tri_indices1
Definition: mesh_continuous_collision_traversal_node.h:87
fcl::detail::CollisionTraversalNodeBase< BV::S >::request
CollisionRequest< BV::S > request
request setting for collision
Definition: collision_traversal_node_base.h:72
fcl::detail::TraversalNodeBase< BV::S >::tf1
Transform3< BV::S > tf1
configuation of first object
Definition: traversal_node_base.h:85
fcl::detail::MeshContinuousCollisionTraversalNode::num_vf_tests
int num_vf_tests
Definition: mesh_continuous_collision_traversal_node.h:93
fcl::Triangle
Triangle with 3 indices for points.
Definition: triangle.h:48
fcl::detail::MeshContinuousCollisionTraversalNode::leafTesting
void leafTesting(int b1, int b2) const
Intersection testing between leaves (two triangles)
Definition: mesh_continuous_collision_traversal_node-inl.h:90
fcl::detail::Intersect
CCD intersect kernel among primitives.
Definition: intersect.h:54
fcl::detail::BVHCollisionTraversalNode::model2
const BVHModel< BV > * model2
The second BVH model.
Definition: bvh_collision_traversal_node.h:89
fcl::Vector3
Eigen::Matrix< S, 3, 1 > Vector3
Definition: types.h:70
fcl::detail::MeshContinuousCollisionTraversalNode::S
typename BV::S S
Definition: mesh_continuous_collision_traversal_node.h:74
fcl::detail::MeshContinuousCollisionTraversalNode::num_ee_tests
int num_ee_tests
Definition: mesh_continuous_collision_traversal_node.h:94
fcl::BVHModel::tri_indices
Triangle * tri_indices
Geometry triangle index data, will be nullptr for point clouds.
Definition: BVH_model.h:165
fcl::detail::MeshContinuousCollisionTraversalNode::MeshContinuousCollisionTraversalNode
MeshContinuousCollisionTraversalNode()
Definition: mesh_continuous_collision_traversal_node-inl.h:73
fcl::detail::BVHCollisionTraversalNode::model1
const BVHModel< BV > * model1
The first BVH model.
Definition: bvh_collision_traversal_node.h:86
fcl::BVNode
A class describing a bounding volume node. It includes the tree structure providing in BVNodeBase and...
Definition: BV_node.h:52
fcl::detail::MeshContinuousCollisionTraversalNode::prev_vertices1
Vector3< S > * prev_vertices1
Definition: mesh_continuous_collision_traversal_node.h:90
fcl::detail::MeshContinuousCollisionTraversalNode::time_of_contact
S time_of_contact
Definition: mesh_continuous_collision_traversal_node.h:98
fcl::CollisionRequest
Parameters for performing collision request.
Definition: collision_request.h:52
fcl::detail::initialize
template bool initialize(MeshCollisionTraversalNodeOBB< double > &node, const BVHModel< OBB< double >> &model1, const Transform3< double > &tf1, const BVHModel< OBB< double >> &model2, const Transform3< double > &tf2, const CollisionRequest< double > &request, CollisionResult< double > &result)
fcl::BVHModel::prev_vertices
Vector3< S > * prev_vertices
Geometry point data in previous frame.
Definition: BVH_model.h:168
fcl::detail::MeshContinuousCollisionTraversalNode::canStop
bool canStop() const
Whether the traversal process can stop early.
Definition: mesh_continuous_collision_traversal_node-inl.h:176
fcl::BVHModel
A class describing the bounding hierarchy of a mesh model or a point cloud model (which is viewed as ...
Definition: BVH_model.h:57
fcl::detail::MeshContinuousCollisionTraversalNode::vertices1
Vector3< S > * vertices1
Definition: mesh_continuous_collision_traversal_node.h:84
fcl::detail::BVHContinuousCollisionPair::BVHContinuousCollisionPair
BVHContinuousCollisionPair()
Definition: mesh_continuous_collision_traversal_node-inl.h:57
fcl::detail::MeshContinuousCollisionTraversalNode::vertices2
Vector3< S > * vertices2
Definition: mesh_continuous_collision_traversal_node.h:85
fcl::detail::BVHCollisionTraversalNode
Traversal node for collision between BVH models.
Definition: bvh_collision_traversal_node.h:52
min
static T min(T x, T y)
Definition: svm.cpp:49
fcl::detail::TraversalNodeBase< BV::S >::tf2
Transform3< BV::S > tf2
configuration of second object
Definition: traversal_node_base.h:88
intersect.h
fcl
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
fcl::BVNodeBase::primitiveId
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


fcl
Author(s):
autogenerated on Tue Dec 5 2023 03:40:48