GCC Code Coverage Report


Directory: ./
File: include/coal/collision.h
Date: 2025-04-01 09:23:31
Exec Total Coverage
Lines: 1 1 100.0%
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 COAL_COLLISION_H
40 #define COAL_COLLISION_H
41
42 #include "coal/data_types.h"
43 #include "coal/collision_object.h"
44 #include "coal/collision_data.h"
45 #include "coal/collision_func_matrix.h"
46 #include "coal/timings.h"
47
48 namespace coal {
49
50 /// @brief Main collision interface: given two collision objects, and the
51 /// requirements for contacts, including num of max contacts, whether perform
52 /// exhaustive collision (i.e., returning returning all the contact points),
53 /// whether return detailed contact information (i.e., normal, contact point,
54 /// depth; otherwise only contact primitive id is returned), this function
55 /// performs the collision between them.
56 /// Return value is the number of contacts generated between the two objects.
57 COAL_DLLAPI std::size_t collide(const CollisionObject* o1,
58 const CollisionObject* o2,
59 const CollisionRequest& request,
60 CollisionResult& result);
61
62 /// @copydoc collide(const CollisionObject*, const CollisionObject*, const
63 /// CollisionRequest&, CollisionResult&)
64 COAL_DLLAPI std::size_t collide(const CollisionGeometry* o1,
65 const Transform3s& tf1,
66 const CollisionGeometry* o2,
67 const Transform3s& tf2,
68 const CollisionRequest& request,
69 CollisionResult& result);
70
71 /// @brief This class reduces the cost of identifying the geometry pair.
72 /// This is mostly useful for repeated shape-shape queries.
73 ///
74 /// \code
75 /// ComputeCollision calc_collision (o1, o2);
76 /// std::size_t ncontacts = calc_collision(tf1, tf2, request, result);
77 /// \endcode
78 class COAL_DLLAPI ComputeCollision {
79 public:
80 /// @brief Default constructor from two Collision Geometries.
81 ComputeCollision(const CollisionGeometry* o1, const CollisionGeometry* o2);
82
83 std::size_t operator()(const Transform3s& tf1, const Transform3s& tf2,
84 const CollisionRequest& request,
85 CollisionResult& result) const;
86
87 bool operator==(const ComputeCollision& other) const {
88 return o1 == other.o1 && o2 == other.o2 && solver == other.solver;
89 }
90
91 bool operator!=(const ComputeCollision& other) const {
92 return !(*this == other);
93 }
94
95 6 virtual ~ComputeCollision() {};
96
97 protected:
98 // These pointers are made mutable to let the derived classes to update
99 // their values when updating the collision geometry (e.g. creating a new
100 // one). This feature should be used carefully to avoid any mis usage (e.g,
101 // changing the type of the collision geometry should be avoided).
102 mutable const CollisionGeometry* o1;
103 mutable const CollisionGeometry* o2;
104
105 mutable GJKSolver solver;
106
107 CollisionFunctionMatrix::CollisionFunc func;
108 bool swap_geoms;
109
110 virtual std::size_t run(const Transform3s& tf1, const Transform3s& tf2,
111 const CollisionRequest& request,
112 CollisionResult& result) const;
113
114 public:
115 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
116 };
117
118 } // namespace coal
119
120 #endif
121