coal  3.0.1
Coal, The Collision Detection Library. Previously known as HPP-FCL, fork of FCL -- The Flexible Collision Library
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 
38 #ifndef COAL_KIOS_H
39 #define COAL_KIOS_H
40 
41 #include "coal/BV/OBB.h"
42 
43 namespace coal {
44 
45 struct CollisionRequest;
46 
49 
54  struct COAL_DLLAPI kIOS_Sphere {
55  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
56 
57  Vec3s o;
58  Scalar r;
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  Scalar dist2 = d.squaredNorm();
74  Scalar 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:
97  bool operator==(const kIOS& other) const {
98  bool res = obb == other.obb && num_spheres == other.num_spheres;
99  if (!res) return false;
100 
101  for (size_t k = 0; k < num_spheres; ++k) {
102  if (spheres[k] != other.spheres[k]) return false;
103  }
104 
105  return true;
106  }
107 
109  bool operator!=(const kIOS& other) const { return !(*this == other); }
110 
111  static constexpr size_t max_num_spheres = 5;
112 
114  kIOS_Sphere spheres[max_num_spheres];
115 
117  unsigned int num_spheres;
118 
121 
123  bool contain(const Vec3s& p) const;
124 
126  bool overlap(const kIOS& other) const;
127 
129  bool overlap(const kIOS& other, const CollisionRequest&,
130  Scalar& sqrDistLowerBound) const;
131 
133  Scalar distance(const kIOS& other, Vec3s* P = NULL, Vec3s* Q = NULL) const;
134 
136  kIOS& operator+=(const Vec3s& p);
137 
139  kIOS& operator+=(const kIOS& other) {
140  *this = *this + other;
141  return *this;
142  }
143 
145  kIOS operator+(const kIOS& other) const;
146 
148  Scalar size() const;
149 
151  const Vec3s& center() const { return spheres[0].o; }
152 
154  Scalar width() const;
155 
157  Scalar height() const;
158 
160  Scalar depth() const;
161 
163  Scalar volume() const;
164 
165  public:
166  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
167 };
168  // end of Bounding_Volume
170 
172 COAL_DLLAPI kIOS translate(const kIOS& bv, const Vec3s& t);
173 
177 COAL_DLLAPI bool overlap(const Matrix3s& R0, const Vec3s& T0, const kIOS& b1,
178  const kIOS& b2);
179 
183 COAL_DLLAPI bool overlap(const Matrix3s& R0, const Vec3s& T0, const kIOS& b1,
184  const kIOS& b2, const CollisionRequest& request,
185  Scalar& sqrDistLowerBound);
186 
189 COAL_DLLAPI Scalar distance(const Matrix3s& R0, const Vec3s& T0, const kIOS& b1,
190  const kIOS& b2, Vec3s* P = NULL, Vec3s* Q = NULL);
191 
192 } // namespace coal
193 
194 #endif
A class describing the kIOS collision structure, which is a set of spheres.
Definition: kIOS.h:52
const Vec3s & center() const
Center of the kIOS.
Definition: kIOS.h:151
Scalar width() const
Width of the kIOS.
OBB obb
@ OBB related with kIOS
Definition: kIOS.h:120
bool contain(const Vec3s &p) const
Check whether the kIOS contains a point.
bool overlap(const kIOS &other) const
Check collision between two kIOS.
bool operator==(const kIOS &other) const
Equality operator.
Definition: kIOS.h:97
unsigned int num_spheres
The number of spheres, no larger than 5.
Definition: kIOS.h:117
bool overlap(const kIOS &other, const CollisionRequest &, Scalar &sqrDistLowerBound) const
Check collision between two kIOS.
Scalar volume() const
Volume of the kIOS.
Scalar height() const
Height of the kIOS.
Scalar depth() const
Depth of the kIOS.
Scalar size() const
size of the kIOS (used in BV_Splitter to order two kIOSs)
kIOS & operator+=(const kIOS &other)
Merge the kIOS and another kIOS.
Definition: kIOS.h:139
kIOS_Sphere spheres[max_num_spheres]
The (at most) five spheres for intersection.
Definition: kIOS.h:114
kIOS operator+(const kIOS &other) const
Return the merged kIOS of current kIOS and the other one.
bool operator!=(const kIOS &other) const
Difference operator.
Definition: kIOS.h:109
kIOS & operator+=(const Vec3s &p)
A simple way to merge the kIOS and a point.
Scalar distance(const kIOS &other, Vec3s *P=NULL, Vec3s *Q=NULL) const
The distance between two kIOS.
#define COAL_DLLAPI
Definition: config.hh:88
Main namespace.
Definition: broadphase_bruteforce.h:44
Scalar 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 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.
KDOP< N > translate(const KDOP< N > &bv, const Vec3s &t)
translate the KDOP BV
Eigen::Matrix< Scalar, 3, 1 > Vec3s
Definition: data_types.h:70
double Scalar
Definition: data_types.h:68
Eigen::Matrix< Scalar, 3, 3 > Matrix3s
Definition: data_types.h:74
request to the collision algorithm
Definition: collision_data.h:311
Oriented bounding box class.
Definition: OBB.h:51