Directory: | ./ |
---|---|
File: | include/coal/data_types.h |
Date: | 2025-04-01 09:23:31 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 27 | 28 | 96.4% |
Branches: | 6 | 12 | 50.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) 2023, 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_DATA_TYPES_H | ||
40 | #define COAL_DATA_TYPES_H | ||
41 | |||
42 | #include <Eigen/Core> | ||
43 | #include <Eigen/Geometry> | ||
44 | |||
45 | #include "coal/config.hh" | ||
46 | #include "coal/deprecated.hh" | ||
47 | |||
48 | #ifdef COAL_HAS_OCTOMAP | ||
49 | #define OCTOMAP_VERSION_AT_LEAST(x, y, z) \ | ||
50 | (OCTOMAP_MAJOR_VERSION > x || \ | ||
51 | (OCTOMAP_MAJOR_VERSION >= x && \ | ||
52 | (OCTOMAP_MINOR_VERSION > y || \ | ||
53 | (OCTOMAP_MINOR_VERSION >= y && OCTOMAP_PATCH_VERSION >= z)))) | ||
54 | |||
55 | #define OCTOMAP_VERSION_AT_MOST(x, y, z) \ | ||
56 | (OCTOMAP_MAJOR_VERSION < x || \ | ||
57 | (OCTOMAP_MAJOR_VERSION <= x && \ | ||
58 | (OCTOMAP_MINOR_VERSION < y || \ | ||
59 | (OCTOMAP_MINOR_VERSION <= y && OCTOMAP_PATCH_VERSION <= z)))) | ||
60 | #endif // COAL_HAS_OCTOMAP | ||
61 | |||
62 | namespace coal { | ||
63 | #ifdef COAL_USE_FLOAT_PRECISION | ||
64 | COAL_DEPRECATED typedef float CoalScalar; | ||
65 | typedef float Scalar; | ||
66 | #else | ||
67 | COAL_DEPRECATED typedef double CoalScalar; | ||
68 | typedef double Scalar; | ||
69 | #endif | ||
70 | typedef Eigen::Matrix<Scalar, 3, 1> Vec3s; | ||
71 | typedef Eigen::Matrix<Scalar, 2, 1> Vec2s; | ||
72 | typedef Eigen::Matrix<Scalar, 6, 1> Vec6s; | ||
73 | typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> VecXs; | ||
74 | typedef Eigen::Matrix<Scalar, 3, 3> Matrix3s; | ||
75 | typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 3, Eigen::RowMajor> MatrixX3s; | ||
76 | typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 2, Eigen::RowMajor> MatrixX2s; | ||
77 | typedef Eigen::Matrix<Eigen::DenseIndex, Eigen::Dynamic, 3, Eigen::RowMajor> | ||
78 | Matrixx3i; | ||
79 | typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> MatrixXs; | ||
80 | typedef Eigen::Vector2i support_func_guess_t; | ||
81 | |||
82 | typedef double SolverScalar; | ||
83 | typedef Eigen::Matrix<SolverScalar, 3, 1> Vec3ps; | ||
84 | |||
85 | #ifdef COAL_BACKWARD_COMPATIBILITY_WITH_HPP_FCL | ||
86 | // We keep the FCL_REAL typedef and the Vec[..]f typedefs for backward | ||
87 | // compatibility. | ||
88 | typedef Scalar FCL_REAL; | ||
89 | typedef Vec3s Vec3f; | ||
90 | typedef Vec2s Vec2f; | ||
91 | typedef Vec6s Vec6f; | ||
92 | typedef VecXs VecXf; | ||
93 | typedef Matrix3s Matrix3f; | ||
94 | typedef MatrixX3s Matrixx3f; | ||
95 | typedef MatrixX2s Matrixx2f; | ||
96 | typedef MatrixXs MatrixXf; | ||
97 | #endif | ||
98 | |||
99 | /// @brief Initial guess to use for the GJK algorithm | ||
100 | /// DefaultGuess: Vec3s(1, 0, 0) | ||
101 | /// CachedGuess: previous vector found by GJK or guess cached by the user | ||
102 | /// BoundingVolumeGuess: guess using the centers of the shapes' AABB | ||
103 | /// WARNING: to use BoundingVolumeGuess, computeLocalAABB must have been called | ||
104 | /// on the two shapes. | ||
105 | enum GJKInitialGuess { DefaultGuess, CachedGuess, BoundingVolumeGuess }; | ||
106 | |||
107 | /// @brief Variant to use for the GJK algorithm | ||
108 | enum GJKVariant { DefaultGJK, PolyakAcceleration, NesterovAcceleration }; | ||
109 | |||
110 | /// @brief Which convergence criterion is used to stop the algorithm (when the | ||
111 | /// shapes are not in collision). (default) VDB: Van den Bergen (A Fast and | ||
112 | /// Robust GJK Implementation, 1999) DG: duality-gap, as used in the Frank-Wolfe | ||
113 | /// and the vanilla 1988 GJK algorithms Hybrid: a mix between VDB and DG. | ||
114 | enum GJKConvergenceCriterion { Default, DualityGap, Hybrid }; | ||
115 | |||
116 | /// @brief Wether the convergence criterion is scaled on the norm of the | ||
117 | /// solution or not | ||
118 | enum GJKConvergenceCriterionType { Relative, Absolute }; | ||
119 | |||
120 | /// @brief Triangle with 3 indices for points | ||
121 | class COAL_DLLAPI Triangle { | ||
122 | public: | ||
123 | typedef std::size_t index_type; | ||
124 | typedef int size_type; | ||
125 | |||
126 | /// @brief Default constructor | ||
127 | 2643337 | Triangle() {} | |
128 | |||
129 | /// @brief Create a triangle with given vertex indices | ||
130 | 613879 | Triangle(index_type p1, index_type p2, index_type p3) { set(p1, p2, p3); } | |
131 | |||
132 | /// @brief Set the vertex indices of the triangle | ||
133 | 2105954 | inline void set(index_type p1, index_type p2, index_type p3) { | |
134 | 2105954 | vids[0] = p1; | |
135 | 2105954 | vids[1] = p2; | |
136 | 2105954 | vids[2] = p3; | |
137 | 2105954 | } | |
138 | |||
139 | /// @brief Access the triangle index | ||
140 | 339004081 | inline index_type operator[](index_type i) const { return vids[i]; } | |
141 | |||
142 | 12496558 | inline index_type& operator[](index_type i) { return vids[i]; } | |
143 | |||
144 | 2458905 | static inline size_type size() { return 3; } | |
145 | |||
146 | 44032 | bool operator==(const Triangle& other) const { | |
147 |
2/4✓ Branch 0 taken 44032 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 44032 times.
✗ Branch 3 not taken.
|
88064 | return vids[0] == other.vids[0] && vids[1] == other.vids[1] && |
148 |
1/2✓ Branch 0 taken 44032 times.
✗ Branch 1 not taken.
|
88064 | vids[2] == other.vids[2]; |
149 | } | ||
150 | |||
151 | 41636 | bool operator!=(const Triangle& other) const { return !(*this == other); } | |
152 | |||
153 | 87 | bool isValid() const { | |
154 |
1/2✓ Branch 1 taken 87 times.
✗ Branch 2 not taken.
|
174 | return vids[0] != (std::numeric_limits<index_type>::max)() && |
155 |
2/4✓ Branch 0 taken 87 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 87 times.
✗ Branch 4 not taken.
|
174 | vids[1] != (std::numeric_limits<index_type>::max)() && |
156 | 174 | vids[2] != (std::numeric_limits<index_type>::max)(); | |
157 | } | ||
158 | |||
159 | private: | ||
160 | /// @brief indices for each vertex of triangle | ||
161 | index_type vids[3] = {(std::numeric_limits<index_type>::max)(), | ||
162 | (std::numeric_limits<index_type>::max)(), | ||
163 | (std::numeric_limits<index_type>::max)()}; | ||
164 | }; | ||
165 | |||
166 | /// @brief Quadrilateral with 4 indices for points | ||
167 | struct COAL_DLLAPI Quadrilateral { | ||
168 | typedef std::size_t index_type; | ||
169 | typedef int size_type; | ||
170 | |||
171 | 24 | Quadrilateral() {} | |
172 | |||
173 | Quadrilateral(index_type p0, index_type p1, index_type p2, index_type p3) { | ||
174 | set(p0, p1, p2, p3); | ||
175 | } | ||
176 | |||
177 | /// @brief Set the vertex indices of the quadrilateral | ||
178 | 24 | inline void set(index_type p0, index_type p1, index_type p2, index_type p3) { | |
179 | 24 | vids[0] = p0; | |
180 | 24 | vids[1] = p1; | |
181 | 24 | vids[2] = p2; | |
182 | 24 | vids[3] = p3; | |
183 | 24 | } | |
184 | |||
185 | /// @access the quadrilateral index | ||
186 | 288 | inline index_type operator[](index_type i) const { return vids[i]; } | |
187 | |||
188 | ✗ | inline index_type& operator[](index_type i) { return vids[i]; } | |
189 | |||
190 | 144 | static inline size_type size() { return 4; } | |
191 | |||
192 | bool operator==(const Quadrilateral& other) const { | ||
193 | return vids[0] == other.vids[0] && vids[1] == other.vids[1] && | ||
194 | vids[2] == other.vids[2] && vids[3] == other.vids[3]; | ||
195 | } | ||
196 | |||
197 | bool operator!=(const Quadrilateral& other) const { | ||
198 | return !(*this == other); | ||
199 | } | ||
200 | |||
201 | private: | ||
202 | index_type vids[4]; | ||
203 | }; | ||
204 | |||
205 | } // namespace coal | ||
206 | |||
207 | #endif | ||
208 |