hpp-fcl: include/hpp/fcl/BV/AABB.h Source File

hpp-fcl 1.6.0 HPP fork of FCL -- The Flexible Collision Library

AABB.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 HPP_FCL_AABB_H
39 #define HPP_FCL_AABB_H
40
41 #include <hpp/fcl/data_types.h>
42
43 namespace hpp
44 {
45 namespace fcl
46 {
47
48 struct CollisionRequest;
49
53
55 class HPP_FCL_DLLAPI AABB
56 {
57 public:
59 Vec3f min_;
61 Vec3f max_;
62
64 AABB();
65
67 AABB(const Vec3f& v) : min_(v), max_(v)
68 {
69 }
70
72 AABB(const Vec3f& a, const Vec3f&b) : min_(a.cwiseMin(b)),
73 max_(a.cwiseMax(b))
74 {
75 }
76
78 AABB(const AABB& core, const Vec3f& delta) : min_(core.min_ - delta),
79 max_(core.max_ + delta)
80 {
81 }
82
84 AABB(const Vec3f& a, const Vec3f& b, const Vec3f& c) : min_(a.cwiseMin(b).cwiseMin(c)),
85 max_(a.cwiseMax(b).cwiseMax(c))
86 {
87 }
88
92
94 inline bool contain(const Vec3f& p) const
95 {
96 if(p[0] < min_[0] || p[0] > max_[0]) return false;
97 if(p[1] < min_[1] || p[1] > max_[1]) return false;
98 if(p[2] < min_[2] || p[2] > max_[2]) return false;
99
100 return true;
101 }
102
104 inline bool overlap(const AABB& other) const
105 {
106 if(min_[0] > other.max_[0]) return false;
107 if(min_[1] > other.max_[1]) return false;
108 if(min_[2] > other.max_[2]) return false;
109
110 if(max_[0] < other.min_[0]) return false;
111 if(max_[1] < other.min_[1]) return false;
112 if(max_[2] < other.min_[2]) return false;
113
114 return true;
115 }
116
118 bool overlap(const AABB& other, const CollisionRequest& request,
119 FCL_REAL& sqrDistLowerBound) const;
120
122 FCL_REAL distance(const AABB& other) const;
123
125 FCL_REAL distance(const AABB& other, Vec3f* P, Vec3f* Q) const;
126
128 inline AABB& operator += (const Vec3f& p)
129 {
130 min_ = min_.cwiseMin(p);
131 max_ = max_.cwiseMax(p);
132 return *this;
133 }
134
136 inline AABB& operator += (const AABB& other)
137 {
138 min_ = min_.cwiseMin(other.min_);
139 max_ = max_.cwiseMax(other.max_);
140 return *this;
141 }
142
144 inline AABB operator + (const AABB& other) const
145 {
146 AABB res(*this);
147 return res += other;
148 }
149
151 inline FCL_REAL size() const
152 {
153 return (max_ - min_).squaredNorm();
154 }
155
157 inline Vec3f center() const
158 {
159 return (min_ + max_) * 0.5;
160 }
161
163 inline FCL_REAL width() const
164 {
165 return max_[0] - min_[0];
166 }
167
169 inline FCL_REAL height() const
170 {
171 return max_[1] - min_[1];
172 }
173
175 inline FCL_REAL depth() const
176 {
177 return max_[2] - min_[2];
178 }
179
181 inline FCL_REAL volume() const
182 {
183 return width() * height() * depth();
184 }
185
187
189 inline bool contain(const AABB& other) const
190 {
191 return (other.min_[0] >= min_[0]) && (other.max_[0] <= max_[0]) && (other.min_[1] >= min_[1]) && (other.max_[1] <= max_[1]) && (other.min_[2] >= min_[2]) && (other.max_[2] <= max_[2]);
192 }
193
195 inline bool overlap(const AABB& other, AABB& overlap_part) const
196 {
197 if(!overlap(other))
198 {
199 return false;
200 }
201
202 overlap_part.min_ = min_.cwiseMax(other.min_);
203 overlap_part.max_ = max_.cwiseMin(other.max_);
204 return true;
205 }
206
208 inline AABB& expand(const Vec3f& delta)
209 {
210 min_ -= delta;
211 max_ += delta;
212 return *this;
213 }
214
216 inline AABB& expand(const AABB& core, FCL_REAL ratio)
217 {
218 min_ = min_ * ratio - core.min_;
219 max_ = max_ * ratio - core.max_;
220 return *this;
221 }
222 };
223
225 static inline AABB translate(const AABB& aabb, const Vec3f& t)
226 {
227 AABB res(aabb);
228 res.min_ += t;
229 res.max_ += t;
230 return res;
231 }
232
233 static inline AABB rotate(const AABB& aabb, const Matrix3f& R)
234 {
235 AABB res (R * aabb.min_);
236 Vec3f corner (aabb.min_);
237 const std::size_t bit[3] = { 1, 2, 4 };
238 for (std::size_t ic = 1; ic < 8; ++ic) { // ic = 0 corresponds to aabb.min_. Skip it.
239 for (std::size_t i = 0; i < 3; ++i) {
240 corner[i] = (ic && bit[i]) ? aabb.max_[i] : aabb.min_[i];
241 }
242 res += R * corner;
243 }
244 return res;
245 }
246
248 HPP_FCL_DLLAPI bool overlap(const Matrix3f& R0, const Vec3f& T0, const AABB& b1,
249 const AABB& b2);
250
252 HPP_FCL_DLLAPI bool overlap(const Matrix3f& R0, const Vec3f& T0, const AABB& b1,
253 const AABB& b2, const CollisionRequest& request,
254 FCL_REAL& sqrDistLowerBound);
255 }
256
257 } // namespace hpp
258
259 #endif
hpp::fcl::AABB::AABB
AABB(const AABB &core, const Vec3f &delta)
Creating an AABB centered as core and is of half-dimension delta.
Definition: AABB.h:78
data_types.h
hpp::fcl::Vec3f
Eigen::Matrix< FCL_REAL, 3, 1 > Vec3f
Definition: data_types.h:67
hpp::fcl::AABB::distance
FCL_REAL distance(const AABB &other, Vec3f *P, Vec3f *Q) const
Distance between two AABBs; P and Q, should not be NULL, return the nearest points.
hpp::fcl::AABB::AABB
AABB(const Vec3f &a, const Vec3f &b, const Vec3f &c)
Creating an AABB contains three points.
Definition: AABB.h:84
hpp::fcl::AABB::min_
Vec3f min_
The min point in the AABB.
Definition: AABB.h:59
hpp::fcl::AABB::volume
FCL_REAL volume() const
Volume of the AABB.
Definition: AABB.h:181
hpp::fcl::AABB::AABB
AABB()
Creating an AABB with zero size (low bound +inf, upper bound -inf)
hpp::fcl::CollisionRequest
request to the collision algorithm
Definition: collision_data.h:198
hpp::fcl::AABB
A class describing the AABB collision structure, which is a box in 3D space determined by two diagona...
Definition: AABB.h:56
hpp::fcl::AABB::depth
FCL_REAL depth() const
Depth of the AABB.
Definition: AABB.h:175
hpp::fcl::AABB::size
FCL_REAL size() const
Size of the AABB (used in BV_Splitter to order two AABBs)
Definition: AABB.h:151
hpp::fcl::AABB::center
Vec3f center() const
Center of the AABB.
Definition: AABB.h:157
hpp::fcl::AABB::height
FCL_REAL height() const
Height of the AABB.
Definition: AABB.h:169
hpp::fcl::AABB::contain
bool contain(const Vec3f &p) const
Check whether the AABB contains a point.
Definition: AABB.h:94
hpp::fcl::FCL_REAL
double FCL_REAL
Definition: data_types.h:66
hpp
Main namespace.
Definition: AABB.h:44
hpp::fcl::AABB::expand
AABB & expand(const Vec3f &delta)
expand the half size of the AABB by delta, and keep the center unchanged.
Definition: AABB.h:208
hpp::fcl::AABB::overlap
bool overlap(const AABB &other, AABB &overlap_part) const
Check whether two AABB are overlap and return the overlap part.
Definition: AABB.h:195
hpp::fcl::overlap
bool overlap(const Matrix3f &R0, const Vec3f &T0, const AABB &b1, const AABB &b2)
Check collision between two aabbs, b1 is in configuration (R0, T0) and b2 is in identity.
hpp::fcl::AABB::distance
FCL_REAL distance(const AABB &other) const
Distance between two AABBs.
hpp::fcl::AABB::overlap
bool overlap(const AABB &other) const
Check whether two AABB are overlap.
Definition: AABB.h:104
hpp::fcl::Matrix3f
Eigen::Matrix< FCL_REAL, 3, 3 > Matrix3f
Definition: data_types.h:68
hpp::fcl::AABB::AABB
AABB(const Vec3f &v)
Creating an AABB at position v with zero size.
Definition: AABB.h:67
hpp::fcl::AABB::overlap
bool overlap(const AABB &other, const CollisionRequest &request, FCL_REAL &sqrDistLowerBound) const
Check whether two AABB are overlap.
hpp::fcl::AABB::AABB
AABB(const Vec3f &a, const Vec3f &b)
Creating an AABB with two endpoints a and b.
Definition: AABB.h:72
hpp::fcl::AABB::width
FCL_REAL width() const
Width of the AABB.
Definition: AABB.h:163
hpp::fcl::AABB::expand
AABB & expand(const AABB &core, FCL_REAL ratio)
expand the aabb by increase the thickness of the plate by a ratio
Definition: AABB.h:216
hpp::fcl::AABB::contain
bool contain(const AABB &other) const
Check whether the AABB contains another AABB.
Definition: AABB.h:189
hpp::fcl::AABB::max_
Vec3f max_
The max point in the AABB.
Definition: AABB.h:61