FCL  0.6.0
Flexible Collision Library
mesh_conservative_advancement_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_MESHCONSERVATIVEADVANCEMENTTRAVERSALNODE_H
39 #define FCL_TRAVERSAL_MESHCONSERVATIVEADVANCEMENTTRAVERSALNODE_H
40 
41 #include "fcl/math/motion/tbv_motion_bound_visitor.h"
42 #include "fcl/narrowphase/detail/traversal/distance/mesh_distance_traversal_node.h"
43 #include "fcl/narrowphase/detail/traversal/distance/conservative_advancement_stack_data.h"
44 
45 namespace fcl
46 {
47 
48 namespace detail
49 {
50 
52 template <typename BV>
54  : public MeshDistanceTraversalNode<BV>
55 {
56 public:
57 
58  using S = typename BV::S;
59 
61 
63  S BVTesting(int b1, int b2) const;
64 
66  void leafTesting(int b1, int b2) const;
67 
69  bool canStop(S c) const;
70 
71  mutable S min_distance;
72 
73  mutable Vector3<S> closest_p1, closest_p2;
74 
75  mutable int last_tri_id1, last_tri_id2;
76 
78  S w;
79 
81  S toc;
82  S t_err;
83 
85  mutable S delta_t;
86 
89  const MotionBase<S>* motion2;
90 
91  mutable std::vector<ConservativeAdvancementStackData<S>> stack;
92 
93  template <typename, typename>
94  friend struct CanStopImpl;
95 };
96 
99 template <typename BV>
100 bool initialize(
103  const Transform3<typename BV::S>& tf1,
105  const Transform3<typename BV::S>& tf2,
106  typename BV::S w = 1,
107  bool use_refit = false,
108  bool refit_bottomup = false);
109 
110 template <typename S>
113 {
114 public:
116 
117  S BVTesting(int b1, int b2) const
118  {
119  if (this->enable_statistics)
120  this->num_bv_tests++;
121 
122  Vector3<S> P1, P2;
123  S d = distance(
124  R,
125  T,
126  this->model1->getBV(b1).bv,
127  this->model2->getBV(b2).bv,
128  &P1,
129  &P2);
130 
131  this->stack.emplace_back(P1, P2, b1, b2, d);
132 
133  return d;
134  }
135 
136  void leafTesting(int b1, int b2) const;
137 
138  bool canStop(S c) const;
139 
140  Matrix3<S> R;
141  Vector3<S> T;
142 
143  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
144 };
145 
148 
151 template <typename S>
152 bool initialize(
154  const BVHModel<RSS<S>>& model1,
155  const Transform3<S>& tf1,
156  const BVHModel<RSS<S>>& model2,
157  const Transform3<S>& tf2,
158  S w = 1);
159 
160 template <typename S>
162  : public MeshConservativeAdvancementTraversalNode<OBBRSS<S>>
163 {
164 public:
166 
167  S BVTesting(int b1, int b2) const
168  {
169  if (this->enable_statistics)
170  this->num_bv_tests++;
171 
172  Vector3<S> P1, P2;
173  S d = distance(
174  R,
175  T,
176  this->model1->getBV(b1).bv,
177  this->model2->getBV(b2).bv,
178  &P1,
179  &P2);
180 
181  this->stack.emplace_back(P1, P2, b1, b2, d);
182 
183  return d;
184  }
185 
186  void leafTesting(int b1, int b2) const;
187 
188  bool canStop(S c) const;
189 
190  Matrix3<S> R;
191  Vector3<S> T;
192 
193  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
194 };
195 
198 
199 template <typename S>
200 bool initialize(
202  const BVHModel<OBBRSS<S>>& model1,
203  const Transform3<S>& tf1,
204  const BVHModel<OBBRSS<S>>& model2,
205  const Transform3<S>& tf2,
206  S w = 1);
207 
208 template <typename S, typename BV>
209 const Vector3<S> getBVAxis(const BV& bv, int i);
210 
211 template <typename BV>
212 bool meshConservativeAdvancementTraversalNodeCanStop(
213  typename BV::S c,
214  typename BV::S min_distance,
215  typename BV::S abs_err,
216  typename BV::S rel_err,
217  typename BV::S w,
218  const BVHModel<BV>* model1,
219  const BVHModel<BV>* model2,
221  const MotionBase<typename BV::S>* motion2,
223  typename BV::S& delta_t);
224 
225 template <typename BV>
226 bool meshConservativeAdvancementOrientedNodeCanStop(
227  typename BV::S c,
228  typename BV::S min_distance,
229  typename BV::S abs_err,
230  typename BV::S rel_err,
231  typename BV::S w,
232  const BVHModel<BV>* model1,
233  const BVHModel<BV>* model2,
234  const MotionBase<typename BV::S>* motion1,
235  const MotionBase<typename BV::S>* motion2,
237  typename BV::S& delta_t);
238 
239 template <typename BV>
240 void meshConservativeAdvancementOrientedNodeLeafTesting(
241  int b1,
242  int b2,
243  const BVHModel<BV>* model1,
244  const BVHModel<BV>* model2,
245  const Triangle* tri_indices1,
246  const Triangle* tri_indices2,
247  const Vector3<typename BV::S>* vertices1,
248  const Vector3<typename BV::S>* vertices2,
249  const Matrix3<typename BV::S>& R,
250  const Vector3<typename BV::S>& T,
251  const MotionBase<typename BV::S>* motion1,
252  const MotionBase<typename BV::S>* motion2,
253  bool enable_statistics,
254  typename BV::S& min_distance,
255  Vector3<typename BV::S>& p1,
256  Vector3<typename BV::S>& p2,
257  int& last_tri_id1,
258  int& last_tri_id2,
259  typename BV::S& delta_t,
260  int& num_leaf_tests);
261 
262 } // namespace detail
263 } // namespace fcl
264 
265 #include "fcl/narrowphase/detail/traversal/distance/mesh_conservative_advancement_traversal_node-inl.h"
266 
267 #endif
const BVHModel< BV > * model1
The first BVH model.
Definition: bvh_distance_traversal_node.h:87
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
Definition: mesh_conservative_advancement_traversal_node.h:161
const MotionBase< S > * motion1
Motions for the two objects in query.
Definition: mesh_conservative_advancement_traversal_node.h:88
S BVTesting(int b1, int b2) const
BV test between b1 and b2.
Definition: mesh_conservative_advancement_traversal_node.h:167
S BVTesting(int b1, int b2) const
BV culling test in one BVTT node.
Definition: mesh_conservative_advancement_traversal_node-inl.h:99
S w
CA controlling variable: early stop for the early iterations of CA.
Definition: mesh_conservative_advancement_traversal_node.h:78
Transform3< BV::S > tf2
configuration of second object
Definition: traversal_node_base.h:88
continuous collision node using conservative advancement. when using this default version...
Definition: mesh_conservative_advancement_traversal_node.h:53
Triangle with 3 indices for points.
Definition: triangle.h:47
Definition: mesh_conservative_advancement_traversal_node.h:111
int num_bv_tests
statistical information
Definition: bvh_distance_traversal_node.h:92
S delta_t
The delta_t each step.
Definition: mesh_conservative_advancement_traversal_node.h:85
S toc
The time from beginning point.
Definition: mesh_conservative_advancement_traversal_node.h:81
Definition: bv_motion_bound_visitor.h:45
void leafTesting(int b1, int b2) const
Conservative advancement testing between leaves (two triangles)
Definition: mesh_conservative_advancement_traversal_node-inl.h:112
S BVTesting(int b1, int b2) const
BV test between b1 and b2.
Definition: mesh_conservative_advancement_traversal_node.h:117
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
const BVHModel< BV > * model2
The second BVH model.
Definition: bvh_distance_traversal_node.h:89
bool canStop(S c) const
Whether the traversal process can stop early.
Definition: mesh_conservative_advancement_traversal_node-inl.h:234
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
Definition: mesh_conservative_advancement_traversal_node-inl.h:169
bool enable_statistics
Whether stores statistics.
Definition: distance_traversal_node_base.h:79
Traversal node for distance computation between two meshes.
Definition: mesh_distance_traversal_node.h:55