FCL  0.6.0
Flexible Collision Library
kIOS.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011-2014, Willow Garage, Inc.
5  * Copyright (c) 2014-2016, 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 FCL_BV_KIOS_H
39 #define FCL_BV_KIOS_H
40 
41 #include "fcl/math/bv/OBB.h"
42 
43 namespace fcl
44 {
45 
47 template <typename S_>
48 class kIOS
49 {
51  struct kIOS_Sphere
52  {
53  Vector3<S_> o;
54  S_ r;
55  };
56 
58  static kIOS_Sphere encloseSphere(
59  const kIOS_Sphere& s0, const kIOS_Sphere& s1);
60 
61 public:
62 
63  using S = S_;
64 
66  kIOS_Sphere spheres[5];
67 
69  unsigned int num_spheres;
70 
73 
75  bool overlap(const kIOS<S>& other) const;
76 
82  bool overlap(const kIOS<S>& other, kIOS<S>& overlap_part) const;
83 
85  bool contain(const Vector3<S>& p) const;
86 
88  kIOS<S>& operator += (const Vector3<S>& p);
89 
91  kIOS<S>& operator += (const kIOS<S>& other);
92 
94  kIOS<S> operator + (const kIOS<S>& other) const;
95 
97  const Vector3<S>& center() const;
98 
100  S width() const;
101 
103  S height() const;
104 
106  S depth() const;
107 
109  S volume() const;
110 
112  S size() const;
113 
115  S distance(
116  const kIOS<S>& other,
117  Vector3<S>* P = nullptr, Vector3<S>* Q = nullptr) const;
118 
119  static constexpr S ratio() { return 1.5; }
120  static constexpr S invSinA() { return 2; }
121  static S cosA() { return std::sqrt(3.0) / 2.0; }
122 };
123 
124 using kIOSf = kIOS<float>;
125 using kIOSd = kIOS<double>;
126 
128 template <typename S, typename Derived>
130  const kIOS<S>& bv, const Eigen::MatrixBase<Derived>& t);
131 
135 template <typename S, typename DerivedA, typename DerivedB>
136 bool overlap(
137  const Eigen::MatrixBase<DerivedA>& R0,
138  const Eigen::MatrixBase<DerivedB>& T0,
139  const kIOS<S>& b1, const kIOS<S>& b2);
140 
144 template <typename S>
145 bool overlap(
146  const Transform3<S>& tf,
147  const kIOS<S>& b1,
148  const kIOS<S>& b2);
149 
152 template <typename S, typename DerivedA, typename DerivedB>
153 S distance(
154  const Eigen::MatrixBase<DerivedA>& R0,
155  const Eigen::MatrixBase<DerivedB>& T0,
156  const kIOS<S>& b1,
157  const kIOS<S>& b2,
158  Vector3<S>* P = nullptr,
159  Vector3<S>* Q = nullptr);
160 
163 template <typename S>
164 S distance(
165  const Transform3<S>& tf,
166  const kIOS<S>& b1,
167  const kIOS<S>& b2,
168  Vector3<S>* P = nullptr,
169  Vector3<S>* Q = nullptr);
170 
171 } // namespace fcl
172 
173 #include "fcl/math/bv/kIOS-inl.h"
174 
175 #endif
kIOS< S > operator+(const kIOS< S > &other) const
Return the merged kIOS of current kIOS and the other one.
Definition: kIOS-inl.h:148
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
AABB< S > translate(const AABB< S > &aabb, const Eigen::MatrixBase< Derived > &t)
translate the center of AABB by t
Definition: AABB-inl.h:345
bool overlap(const kIOS< S > &other) const
Check collision between two kIOS.
Definition: kIOS-inl.h:80
S width() const
Width of the kIOS.
Definition: kIOS-inl.h:173
S depth() const
Depth of the kIOS.
Definition: kIOS-inl.h:187
OBB< S > obb
OBB related with kIOS.
Definition: kIOS.h:72
unsigned int num_spheres
The number of spheres, no larger than 5.
Definition: kIOS.h:69
S distance(const kIOS< S > &other, Vector3< S > *P=nullptr, Vector3< S > *Q=nullptr) const
The distance between two kIOS.
Definition: kIOS-inl.h:208
const Vector3< S > & center() const
Center of the kIOS.
Definition: kIOS-inl.h:166
S size() const
size of the kIOS (used in BV_Splitter to order two kIOSs)
Definition: kIOS-inl.h:201
S height() const
Height of the kIOS.
Definition: kIOS-inl.h:180
S volume() const
Volume of the kIOS.
Definition: kIOS-inl.h:194
bool contain(const Vector3< S > &p) const
Check whether the kIOS contains a point.
Definition: kIOS-inl.h:108
A class describing the kIOS collision structure, which is a set of spheres.
Definition: kIOS.h:48
kIOS< S > & operator+=(const Vector3< S > &p)
A simple way to merge the kIOS and a point.
Definition: kIOS-inl.h:122
kIOS_Sphere spheres[5]
The (at most) five spheres for intersection.
Definition: kIOS.h:66