hpp-fcl  1.6.0
HPP fork of FCL -- The Flexible Collision Library
distance.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-2015, 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 HPP_FCL_DISTANCE_H
39 #define HPP_FCL_DISTANCE_H
40 
42 #include <hpp/fcl/collision_data.h>
44 
45 namespace hpp
46 {
47 namespace fcl
48 {
49 
52 HPP_FCL_DLLAPI FCL_REAL distance(const CollisionObject* o1, const CollisionObject* o2,
53  const DistanceRequest& request, DistanceResult& result);
54 
56 HPP_FCL_DLLAPI FCL_REAL distance(const CollisionGeometry* o1, const Transform3f& tf1,
57  const CollisionGeometry* o2, const Transform3f& tf2,
58  const DistanceRequest& request, DistanceResult& result);
59 
63 inline FCL_REAL distance(const CollisionObject* o1, const CollisionObject* o2,
64  DistanceRequest& request, DistanceResult& result)
65 {
66  FCL_REAL res = distance(o1, o2, (const DistanceRequest&) request, result);
67  request.updateGuess (result);
68  return res;
69 }
70 
74 inline FCL_REAL distance(const CollisionGeometry* o1, const Transform3f& tf1,
75  const CollisionGeometry* o2, const Transform3f& tf2,
76  DistanceRequest& request, DistanceResult& result)
77 {
78  FCL_REAL res = distance(o1, tf1, o2, tf2,
79  (const DistanceRequest&) request, result);
80  request.updateGuess (result);
81  return res;
82 }
83 
92 public:
94 
95  FCL_REAL operator()(const Transform3f& tf1, const Transform3f& tf2,
96  const DistanceRequest& request, DistanceResult& result)
97  {
98  bool cached = request.enable_cached_gjk_guess;
99  solver.enable_cached_guess = cached;
100  if (cached) {
101  solver.cached_guess = request.cached_gjk_guess;
102  solver.support_func_cached_guess = request.cached_support_func_guess;
103  }
104 
105  FCL_REAL res;
106  if (swap_geoms) {
107  res = func(o2, tf2, o1, tf1, &solver, request, result);
108  if (request.enable_nearest_points) {
109  std::swap(result.o1, result.o2);
110  result.nearest_points[0].swap(result.nearest_points[1]);
111  }
112  } else {
113  res = func (o1, tf1, o2, tf2, &solver, request, result);
114  }
115 
116  if (cached) {
117  result.cached_gjk_guess = solver.cached_guess;
118  result.cached_support_func_guess = solver.support_func_cached_guess;
119  }
120  return res;
121  }
122 
123  inline FCL_REAL operator()(const Transform3f& tf1, const Transform3f& tf2,
124  DistanceRequest& request, DistanceResult& result)
125  {
126  FCL_REAL res = operator()(tf1, tf2, (const DistanceRequest&) request, result);
127  request.updateGuess (result);
128  return res;
129  }
130 
131 private:
132  CollisionGeometry const *o1, *o2;
133  GJKSolver solver;
134 
136  bool swap_geoms;
137 };
138 
139 } // namespace fcl
140 } // namespace hpp
141 
142 #endif
support_func_guess_t cached_support_func_guess
the support function intial guess set by user
Definition: collision_data.h:149
FCL_REAL(* DistanceFunc)(const CollisionGeometry *o1, const Transform3f &tf1, const CollisionGeometry *o2, const Transform3f &tf2, const GJKSolver *nsolver, const DistanceRequest &request, DistanceResult &result)
the uniform call interface for distance: for distance, we need know
Definition: distance_func_matrix.h:57
Simple transform class used locally by InterpMotion.
Definition: transform.h:58
request to the distance computation
Definition: collision_data.h:333
support_func_guess_t cached_support_func_guess
stores the last support function vertex index, when relevant.
Definition: collision_data.h:175
const CollisionGeometry * o1
collision object 1
Definition: collision_data.h:382
Main namespace.
Definition: AABB.h:43
Vec3f nearest_points[2]
nearest points
Definition: collision_data.h:376
bool enable_cached_gjk_guess
whether enable gjk intial guess
Definition: collision_data.h:143
Definition: distance.h:91
FCL_REAL distance(const Matrix3f &R0, const Vec3f &T0, const kIOS &b1, const kIOS &b2, Vec3f *P=NULL, Vec3f *Q=NULL)
Approximate distance between two kIOS bounding volumes.
double FCL_REAL
Definition: data_types.h:66
void updateGuess(const QueryResult &result)
Definition: collision_data.h:178
Vec3f cached_gjk_guess
the gjk intial guess set by user
Definition: collision_data.h:146
bool enable_nearest_points
whether to return the nearest points
Definition: collision_data.h:336
FCL_REAL operator()(const Transform3f &tf1, const Transform3f &tf2, DistanceRequest &request, DistanceResult &result)
Definition: distance.h:123
Vec3f cached_gjk_guess
stores the last GJK ray when relevant.
Definition: collision_data.h:172
collision and distance solver based on GJK algorithm implemented in fcl (rewritten the code from the ...
Definition: narrowphase.h:50
the object for collision or distance computation, contains the geometry and the transform information...
Definition: collision_object.h:157
The geometry for the object for collision or distance computation.
Definition: collision_object.h:63
const CollisionGeometry * o2
collision object 2
Definition: collision_data.h:385
#define HPP_FCL_DLLAPI
Definition: config.hh:64
distance result
Definition: collision_data.h:367
FCL_REAL operator()(const Transform3f &tf1, const Transform3f &tf2, const DistanceRequest &request, DistanceResult &result)
Definition: distance.h:95