GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/hpp/fcl/collision.h Lines: 13 14 92.9 %
Date: 2024-02-09 12:57:42 Branches: 0 0 - %

Line Branch Exec Source
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
 *  Copyright (c) 2021, INRIA
7
 *  All rights reserved.
8
 *
9
 *  Redistribution and use in source and binary forms, with or without
10
 *  modification, are permitted provided that the following conditions
11
 *  are met:
12
 *
13
 *   * Redistributions of source code must retain the above copyright
14
 *     notice, this list of conditions and the following disclaimer.
15
 *   * Redistributions in binary form must reproduce the above
16
 *     copyright notice, this list of conditions and the following
17
 *     disclaimer in the documentation and/or other materials provided
18
 *     with the distribution.
19
 *   * Neither the name of Open Source Robotics Foundation nor the names of its
20
 *     contributors may be used to endorse or promote products derived
21
 *     from this software without specific prior written permission.
22
 *
23
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33
 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
 *  POSSIBILITY OF SUCH DAMAGE.
35
 */
36
37
/** \author Jia Pan */
38
39
#ifndef HPP_FCL_COLLISION_H
40
#define HPP_FCL_COLLISION_H
41
42
#include <hpp/fcl/data_types.h>
43
#include <hpp/fcl/collision_object.h>
44
#include <hpp/fcl/collision_data.h>
45
#include <hpp/fcl/collision_func_matrix.h>
46
#include <hpp/fcl/timings.h>
47
48
namespace hpp {
49
namespace fcl {
50
51
/// @brief Main collision interface: given two collision objects, and the
52
/// requirements for contacts, including num of max contacts, whether perform
53
/// exhaustive collision (i.e., returning returning all the contact points),
54
/// whether return detailed contact information (i.e., normal, contact point,
55
/// depth; otherwise only contact primitive id is returned), this function
56
/// performs the collision between them.
57
/// Return value is the number of contacts generated between the two objects.
58
HPP_FCL_DLLAPI std::size_t collide(const CollisionObject* o1,
59
                                   const CollisionObject* o2,
60
                                   const CollisionRequest& request,
61
                                   CollisionResult& result);
62
63
/// @copydoc collide(const CollisionObject*, const CollisionObject*, const
64
/// CollisionRequest&, CollisionResult&)
65
HPP_FCL_DLLAPI std::size_t collide(const CollisionGeometry* o1,
66
                                   const Transform3f& tf1,
67
                                   const CollisionGeometry* o2,
68
                                   const Transform3f& tf2,
69
                                   const CollisionRequest& request,
70
                                   CollisionResult& result);
71
72
/// @copydoc collide(const CollisionObject*, const CollisionObject*, const
73
/// CollisionRequest&, CollisionResult&) \note this function update the initial
74
/// guess of \c request if requested.
75
///       See QueryRequest::updateGuess
76
8306
inline std::size_t collide(const CollisionObject* o1, const CollisionObject* o2,
77
                           CollisionRequest& request, CollisionResult& result) {
78
8306
  std::size_t res = collide(o1, o2, (const CollisionRequest&)request, result);
79
8306
  request.updateGuess(result);
80
8306
  return res;
81
}
82
83
/// @copydoc collide(const CollisionObject*, const CollisionObject*, const
84
/// CollisionRequest&, CollisionResult&) \note this function update the initial
85
/// guess of \c request if requested.
86
///       See QueryRequest::updateGuess
87
2982
inline std::size_t collide(const CollisionGeometry* o1, const Transform3f& tf1,
88
                           const CollisionGeometry* o2, const Transform3f& tf2,
89
                           CollisionRequest& request, CollisionResult& result) {
90
  std::size_t res =
91
2982
      collide(o1, tf1, o2, tf2, (const CollisionRequest&)request, result);
92
2982
  request.updateGuess(result);
93
2982
  return res;
94
}
95
96
/// @brief This class reduces the cost of identifying the geometry pair.
97
/// This is mostly useful for repeated shape-shape queries.
98
///
99
/// \code
100
///   ComputeCollision calc_collision (o1, o2);
101
///   std::size_t ncontacts = calc_collision(tf1, tf2, request, result);
102
/// \endcode
103
class HPP_FCL_DLLAPI ComputeCollision {
104
 public:
105
  /// @brief Default constructor from two Collision Geometries.
106
  ComputeCollision(const CollisionGeometry* o1, const CollisionGeometry* o2);
107
108
  std::size_t operator()(const Transform3f& tf1, const Transform3f& tf2,
109
                         const CollisionRequest& request,
110
                         CollisionResult& result) const;
111
112
2
  inline std::size_t operator()(const Transform3f& tf1, const Transform3f& tf2,
113
                                CollisionRequest& request,
114
                                CollisionResult& result) const {
115
2
    std::size_t res = operator()(tf1, tf2, (const CollisionRequest&)request,
116
                                 result);
117
2
    request.updateGuess(result);
118
2
    return res;
119
  }
120
121
  bool operator==(const ComputeCollision& other) const {
122
    return o1 == other.o1 && o2 == other.o2 && solver == other.solver;
123
  }
124
125
  bool operator!=(const ComputeCollision& other) const {
126
    return !(*this == other);
127
  }
128
129
2
  virtual ~ComputeCollision(){};
130
131
 protected:
132
  // These pointers are made mutable to let the derived classes to update
133
  // their values when updating the collision geometry (e.g. creating a new
134
  // one). This feature should be used carefully to avoid any mis usage (e.g,
135
  // changing the type of the collision geometry should be avoided).
136
  mutable const CollisionGeometry* o1;
137
  mutable const CollisionGeometry* o2;
138
139
  mutable GJKSolver solver;
140
141
  CollisionFunctionMatrix::CollisionFunc func;
142
  bool swap_geoms;
143
144
  virtual std::size_t run(const Transform3f& tf1, const Transform3f& tf2,
145
                          const CollisionRequest& request,
146
                          CollisionResult& result) const;
147
148
 public:
149
  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
150
};
151
152
}  // namespace fcl
153
}  // namespace hpp
154
155
#endif