coal 3.0.2
Coal, The Collision Detection Library. Previously known as HPP-FCL, fork of FCL -- The Flexible Collision Library
Loading...
Searching...
No Matches
kIOS.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
37
38#ifndef COAL_KIOS_H
39#define COAL_KIOS_H
40
41#include "coal/BV/OBB.h"
42
43namespace coal {
44
46
49
52class COAL_DLLAPI kIOS {
54 struct COAL_DLLAPI kIOS_Sphere {
55 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
56
59
60 bool operator==(const kIOS_Sphere& other) const {
61 return o == other.o && r == other.r;
62 }
63
64 bool operator!=(const kIOS_Sphere& other) const {
65 return !(*this == other);
66 }
67 };
68
70 static kIOS_Sphere encloseSphere(const kIOS_Sphere& s0,
71 const kIOS_Sphere& s1) {
72 Vec3s d = s1.o - s0.o;
73 CoalScalar dist2 = d.squaredNorm();
74 CoalScalar diff_r = s1.r - s0.r;
75
77 if (diff_r * diff_r >= dist2) {
78 if (s1.r > s0.r)
79 return s1;
80 else
81 return s0;
82 } else
83 {
84 float dist = (float)std::sqrt(dist2);
85 kIOS_Sphere s;
86 s.r = dist + s0.r + s1.r;
87 if (dist > 0)
88 s.o = s0.o + d * ((s.r - s0.r) / dist);
89 else
90 s.o = s0.o;
91 return s;
92 }
93 }
94
95 public:
96 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
97
99 bool operator==(const kIOS& other) const {
100 bool res = obb == other.obb && num_spheres == other.num_spheres;
101 if (!res) return false;
102
103 for (size_t k = 0; k < num_spheres; ++k) {
104 if (spheres[k] != other.spheres[k]) return false;
105 }
106
107 return true;
108 }
109
111 bool operator!=(const kIOS& other) const { return !(*this == other); }
112
113 static constexpr size_t max_num_spheres = 5;
114
117
119 unsigned int num_spheres;
120
123
125 bool contain(const Vec3s& p) const;
126
128 bool overlap(const kIOS& other) const;
129
131 bool overlap(const kIOS& other, const CollisionRequest&,
132 CoalScalar& sqrDistLowerBound) const;
133
135 CoalScalar distance(const kIOS& other, Vec3s* P = NULL,
136 Vec3s* Q = NULL) const;
137
139 kIOS& operator+=(const Vec3s& p);
140
142 kIOS& operator+=(const kIOS& other) {
143 *this = *this + other;
144 return *this;
145 }
146
148 kIOS operator+(const kIOS& other) const;
149
152
154 const Vec3s& center() const { return spheres[0].o; }
155
158
161
164
167};
168
170COAL_DLLAPI kIOS translate(const kIOS& bv, const Vec3s& t);
171
175COAL_DLLAPI bool overlap(const Matrix3s& R0, const Vec3s& T0, const kIOS& b1,
176 const kIOS& b2);
177
181COAL_DLLAPI bool overlap(const Matrix3s& R0, const Vec3s& T0, const kIOS& b1,
182 const kIOS& b2, const CollisionRequest& request,
183 CoalScalar& sqrDistLowerBound);
184
187COAL_DLLAPI CoalScalar distance(const Matrix3s& R0, const Vec3s& T0,
188 const kIOS& b1, const kIOS& b2, Vec3s* P = NULL,
189 Vec3s* Q = NULL);
190
191} // namespace coal
192
193#endif
A class describing the kIOS collision structure, which is a set of spheres.
Definition kIOS.h:52
bool operator!=(const kIOS_Sphere &other) const
Definition kIOS.h:64
bool overlap(const kIOS &other, const CollisionRequest &, CoalScalar &sqrDistLowerBound) const
Check collision between two kIOS.
CoalScalar size() const
size of the kIOS (used in BV_Splitter to order two kIOSs)
OBB obb
@ OBB related with kIOS
Definition kIOS.h:122
kIOS & operator+=(const Vec3s &p)
A simple way to merge the kIOS and a point.
CoalScalar height() const
Height of the kIOS.
bool contain(const Vec3s &p) const
Check whether the kIOS contains a point.
CoalScalar distance(const Matrix3s &R0, const Vec3s &T0, const kIOS &b1, const kIOS &b2, Vec3s *P=NULL, Vec3s *Q=NULL)
Approximate distance between two kIOS bounding volumes.
bool overlap(const kIOS &other) const
Check collision between two kIOS.
unsigned int num_spheres
The number of spheres, no larger than 5.
Definition kIOS.h:119
CoalScalar volume() const
Volume of the kIOS.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW bool operator==(const kIOS &other) const
Equality operator.
Definition kIOS.h:99
static constexpr size_t max_num_spheres
Definition kIOS.h:113
kIOS & operator+=(const kIOS &other)
Merge the kIOS and another kIOS.
Definition kIOS.h:142
kIOS_Sphere spheres[max_num_spheres]
The (at most) five spheres for intersection.
Definition kIOS.h:116
kIOS operator+(const kIOS &other) const
Return the merged kIOS of current kIOS and the other one.
bool overlap(const Matrix3s &R0, const Vec3s &T0, const AABB &b1, const AABB &b2)
Check collision between two aabbs, b1 is in configuration (R0, T0) and b2 is in identity.
bool operator!=(const kIOS &other) const
Difference operator.
Definition kIOS.h:111
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Vec3s o
Definition kIOS.h:57
CoalScalar distance(const kIOS &other, Vec3s *P=NULL, Vec3s *Q=NULL) const
The distance between two kIOS.
CoalScalar r
Definition kIOS.h:58
CoalScalar depth() const
Depth of the kIOS.
const Vec3s & center() const
Center of the kIOS.
Definition kIOS.h:154
CoalScalar width() const
Width of the kIOS.
bool operator==(const kIOS_Sphere &other) const
Definition kIOS.h:60
Main namespace.
Definition broadphase_bruteforce.h:44
Eigen::Matrix< CoalScalar, 3, 3 > Matrix3s
Definition data_types.h:81
Eigen::Matrix< CoalScalar, 3, 1 > Vec3s
Definition data_types.h:77
double CoalScalar
Definition data_types.h:76
request to the collision algorithm
Definition collision_data.h:311
Oriented bounding box class.
Definition OBB.h:51