coal/BV/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 
52 class 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 
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 
116  kIOS_Sphere spheres[max_num_spheres];
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 
151  CoalScalar size() const;
152 
154  const Vec3s& center() const { return spheres[0].o; }
155 
157  CoalScalar width() const;
158 
160  CoalScalar height() const;
161 
163  CoalScalar depth() const;
164 
166  CoalScalar volume() const;
167 };
168 
170 COAL_DLLAPI kIOS translate(const kIOS& bv, const Vec3s& t);
171 
175 COAL_DLLAPI bool overlap(const Matrix3s& R0, const Vec3s& T0, const kIOS& b1,
176  const kIOS& b2);
177 
181 COAL_DLLAPI bool overlap(const Matrix3s& R0, const Vec3s& T0, const kIOS& b1,
182  const kIOS& b2, const CollisionRequest& request,
183  CoalScalar& sqrDistLowerBound);
184 
187 COAL_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
coal::Vec3s
Eigen::Matrix< CoalScalar, 3, 1 > Vec3s
Definition: coal/data_types.h:77
coal::kIOS::operator==
EIGEN_MAKE_ALIGNED_OPERATOR_NEW bool operator==(const kIOS &other) const
Equality operator.
Definition: coal/BV/kIOS.h:99
coal::kIOS::kIOS_Sphere::o
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Vec3s o
Definition: coal/BV/kIOS.h:57
obb
Definition: obb.py:1
coal::kIOS::encloseSphere
static kIOS_Sphere encloseSphere(const kIOS_Sphere &s0, const kIOS_Sphere &s1)
generate one sphere enclosing two spheres
Definition: coal/BV/kIOS.h:70
OBB.h
coal
Main namespace.
Definition: coal/broadphase/broadphase_bruteforce.h:44
coal::kIOS::kIOS_Sphere::r
CoalScalar r
Definition: coal/BV/kIOS.h:58
octree.r
r
Definition: octree.py:9
coal::kIOS
A class describing the kIOS collision structure, which is a set of spheres.
Definition: coal/BV/kIOS.h:52
coal::distance
COAL_DLLAPI 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.
Definition: kIOS.cpp:180
coal::kIOS::spheres
kIOS_Sphere spheres[max_num_spheres]
The (at most) five spheres for intersection.
Definition: coal/BV/kIOS.h:116
res
res
coal::kIOS::kIOS_Sphere::operator!=
bool operator!=(const kIOS_Sphere &other) const
Definition: coal/BV/kIOS.h:64
coal::kIOS::kIOS_Sphere::operator==
bool operator==(const kIOS_Sphere &other) const
Definition: coal/BV/kIOS.h:60
d
d
coal::kIOS::operator+=
kIOS & operator+=(const kIOS &other)
Merge the kIOS and another kIOS.
Definition: coal/BV/kIOS.h:142
coal::CollisionRequest
request to the collision algorithm
Definition: coal/collision_data.h:311
coal::kIOS::num_spheres
unsigned int num_spheres
The number of spheres, no larger than 5.
Definition: coal/BV/kIOS.h:119
coal::translate
static AABB translate(const AABB &aabb, const Vec3s &t)
translate the center of AABB by t
Definition: coal/BV/AABB.h:233
coal::overlap
COAL_DLLAPI 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.
Definition: AABB.cpp:134
coal::Matrix3s
Eigen::Matrix< CoalScalar, 3, 3 > Matrix3s
Definition: coal/data_types.h:81
coal::kIOS::obb
OBB obb
@ OBB related with kIOS
Definition: coal/BV/kIOS.h:122
coal::OBB
Oriented bounding box class.
Definition: include/coal/BV/OBB.h:51
coal::kIOS::operator!=
bool operator!=(const kIOS &other) const
Difference operator.
Definition: coal/BV/kIOS.h:111
coal::CoalScalar
double CoalScalar
Definition: coal/data_types.h:76
coal::kIOS::center
const Vec3s & center() const
Center of the kIOS.
Definition: coal/BV/kIOS.h:154
coal::kIOS::kIOS_Sphere
One sphere in kIOS.
Definition: coal/BV/kIOS.h:54


hpp-fcl
Author(s):
autogenerated on Sat Nov 23 2024 03:44:58