FCL  0.6.0
Flexible Collision Library
mesh_distance_traversal_node.h
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_MESHDISTANCETRAVERSALNODE_H
39 #define FCL_TRAVERSAL_MESHDISTANCETRAVERSALNODE_H
40 
41 #include "fcl/narrowphase/detail/primitive_shape_algorithm/triangle_distance.h"
42 #include "fcl/math/bv/RSS.h"
43 #include "fcl/math/bv/OBBRSS.h"
44 #include "fcl/math/bv/kIOS.h"
45 #include "fcl/narrowphase/detail/traversal/distance/bvh_distance_traversal_node.h"
46 
47 namespace fcl
48 {
49 
50 namespace detail
51 {
52 
54 template <typename BV>
56 {
57 public:
58 
59  using S = typename BV::S;
60 
62 
64  void leafTesting(int b1, int b2) const;
65 
67  bool canStop(S c) const;
68 
69  Vector3<S>* vertices1;
70  Vector3<S>* vertices2;
71 
72  Triangle* tri_indices1;
73  Triangle* tri_indices2;
74 
77  S abs_err;
78 };
79 
82 template <typename BV>
83 bool initialize(
86  Transform3<typename BV::S>& tf1,
88  Transform3<typename BV::S>& tf2,
91  bool use_refit = false, bool refit_bottomup = false);
92 
94 template <typename S>
96  : public MeshDistanceTraversalNode<RSS<S>>
97 {
98 public:
100 
101  void preprocess();
102 
103  void postprocess();
104 
105  S BVTesting(int b1, int b2) const
106  {
107  if (this->enable_statistics) this->num_bv_tests++;
108 
109  return distance(tf.linear(), tf.translation(), this->model1->getBV(b1).bv, this->model2->getBV(b2).bv);
110  }
111 
112  void leafTesting(int b1, int b2) const;
113 
114  Transform3<S> tf;
115 
116  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
117 };
118 
121 
124 template <typename S>
125 bool initialize(
127  const BVHModel<RSS<S>>& model1,
128  const Transform3<S>& tf1,
129  const BVHModel<RSS<S>>& model2,
130  const Transform3<S>& tf2,
133 
134 template <typename S>
136  : public MeshDistanceTraversalNode<kIOS<S>>
137 {
138 public:
140 
141  void preprocess();
142 
143  void postprocess();
144 
145  S BVTesting(int b1, int b2) const
146  {
147  if (this->enable_statistics) this->num_bv_tests++;
148 
149  return distance(tf.linear(), tf.translation(), this->model1->getBV(b1).bv, this->model2->getBV(b2).bv);
150  }
151 
152  void leafTesting(int b1, int b2) const;
153 
154  Transform3<S> tf;
155 
156  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
157 };
158 
161 
164 template <typename S>
165 bool initialize(
167  const BVHModel<kIOS<S>>& model1,
168  const Transform3<S>& tf1,
169  const BVHModel<kIOS<S>>& model2,
170  const Transform3<S>& tf2,
171  const DistanceRequest<S>& request,
172  DistanceResult<S>& result);
173 
174 template <typename S>
176  : public MeshDistanceTraversalNode<OBBRSS<S>>
177 {
178 public:
180 
181  void preprocess();
182 
183  void postprocess();
184 
185  S BVTesting(int b1, int b2) const
186  {
187  if (this->enable_statistics) this->num_bv_tests++;
188 
189  return distance(tf.linear(), tf.translation(), this->model1->getBV(b1).bv, this->model2->getBV(b2).bv);
190  }
191 
192  void leafTesting(int b1, int b2) const;
193 
194  Transform3<S> tf;
195 
196  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
197 };
198 
201 
204 template <typename S>
205 bool initialize(
207  const BVHModel<OBBRSS<S>>& model1,
208  const Transform3<S>& tf1,
209  const BVHModel<OBBRSS<S>>& model2,
210  const Transform3<S>& tf2,
211  const DistanceRequest<S>& request,
212  DistanceResult<S>& result);
213 
214 template <typename BV>
215 FCL_DEPRECATED
216 void meshDistanceOrientedNodeLeafTesting(
217  int b1,
218  int b2,
219  const BVHModel<BV>* model1,
220  const BVHModel<BV>* model2,
221  Vector3<typename BV::S>* vertices1,
222  Vector3<typename BV::S>* vertices2,
223  Triangle* tri_indices1,
224  Triangle* tri_indices2,
225  const Matrix3<typename BV::S>& R,
226  const Vector3<typename BV::S>& T,
227  bool enable_statistics,
228  int& num_leaf_tests,
229  const DistanceRequest<typename BV::S>& request,
231 
232 template <typename BV>
233 void meshDistanceOrientedNodeLeafTesting(
234  int b1,
235  int b2,
236  const BVHModel<BV>* model1,
237  const BVHModel<BV>* model2,
238  Vector3<typename BV::S>* vertices1,
239  Vector3<typename BV::S>* vertices2,
240  Triangle* tri_indices1,
241  Triangle* tri_indices2,
242  const Transform3<typename BV::S>& tf,
243  bool enable_statistics,
244  int& num_leaf_tests,
245  const DistanceRequest<typename BV::S>& request,
247 
248 template <typename BV>
249 void distancePreprocessOrientedNode(
250  const BVHModel<BV>* model1,
251  const BVHModel<BV>* model2,
252  const Vector3<typename BV::S>* vertices1,
253  Vector3<typename BV::S>* vertices2,
254  Triangle* tri_indices1,
255  Triangle* tri_indices2,
256  int init_tri_id1,
257  int init_tri_id2,
258  const Matrix3<typename BV::S>& R,
259  const Vector3<typename BV::S>& T,
260  const DistanceRequest<typename BV::S>& request,
262 
263 template <typename BV>
264 void distancePreprocessOrientedNode(
265  const BVHModel<BV>* model1,
266  const BVHModel<BV>* model2,
267  const Vector3<typename BV::S>* vertices1,
268  Vector3<typename BV::S>* vertices2,
269  Triangle* tri_indices1,
270  Triangle* tri_indices2,
271  int init_tri_id1,
272  int init_tri_id2,
273  const Transform3<typename BV::S>& tf,
274  const DistanceRequest<typename BV::S>& request,
276 
277 template <typename BV>
278 void distancePostprocessOrientedNode(
279  const BVHModel<BV>* model1,
280  const BVHModel<BV>* model2,
281  const Transform3<typename BV::S>& tf1,
282  const DistanceRequest<typename BV::S>& request,
284 
285 } // namespace detail
286 } // namespace fcl
287 
288 #include "fcl/narrowphase/detail/traversal/distance/mesh_distance_traversal_node-inl.h"
289 
290 #endif
const BVHModel< BV > * model1
The first BVH model.
Definition: bvh_distance_traversal_node.h:87
bool canStop(S c) const
Whether the traversal process can stop early.
Definition: mesh_distance_traversal_node-inl.h:148
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
S rel_err
relative and absolute error, default value is 0.01 for both terms
Definition: mesh_distance_traversal_node.h:76
S BVTesting(int b1, int b2) const
BV test between b1 and b2.
Definition: mesh_distance_traversal_node.h:145
distance result
Definition: distance_request.h:48
Definition: mesh_distance_traversal_node.h:135
Transform3< BV::S > tf2
configuration of second object
Definition: traversal_node_base.h:88
void leafTesting(int b1, int b2) const
Distance testing between leaves (two triangles)
Definition: mesh_distance_traversal_node-inl.h:109
Traversal node for distance computation between BVH models.
Definition: bvh_distance_traversal_node.h:53
Triangle with 3 indices for points.
Definition: triangle.h:47
int num_bv_tests
statistical information
Definition: bvh_distance_traversal_node.h:92
DistanceRequest< BV::S > request
request setting for distance
Definition: distance_traversal_node_base.h:73
A class describing the bounding hierarchy of a mesh model or a point cloud model (which is viewed as ...
Definition: BVH_model.h:57
const BVHModel< BV > * model2
The second BVH model.
Definition: bvh_distance_traversal_node.h:89
DistanceResult< BV::S > * result
distance result kept during the traversal iteration
Definition: distance_traversal_node_base.h:76
Transform3< BV::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 BVTesting(int b1, int b2) const
BV test between b1 and b2.
Definition: mesh_distance_traversal_node.h:105
Traversal node for distance computation between two meshes if their underlying BVH node is oriented n...
Definition: mesh_distance_traversal_node.h:95
request to the distance computation
Definition: distance_request.h:52
bool enable_statistics
Whether stores statistics.
Definition: distance_traversal_node_base.h:79
S BVTesting(int b1, int b2) const
BV test between b1 and b2.
Definition: mesh_distance_traversal_node.h:185
Traversal node for distance computation between two meshes.
Definition: mesh_distance_traversal_node.h:55
Definition: mesh_distance_traversal_node.h:175