Aabb.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
9 //
10 // Unless required by applicable law or agreed to in writing, software
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15
16 #ifndef SURGSIM_MATH_AABB_H
17 #define SURGSIM_MATH_AABB_H
18
19 #include <Eigen/Geometry>
20
21 namespace SurgSim
22 {
23 namespace Math
24 {
25
27 typedef Eigen::AlignedBox<float, 3> Aabbf;
28
30 typedef Eigen::AlignedBox<double, 3> Aabbd;
31
40 template <class Scalar, int Dim>
41 bool doAabbIntersect(const Eigen::AlignedBox<Scalar, Dim>& aabb0,
42  const Eigen::AlignedBox<Scalar, Dim>& aabb1,
43  double tolerance)
44 {
45  typedef typename Eigen::AlignedBox<Scalar, Dim>::VectorType VectorType;
46
47  VectorType vector = (aabb1.center() - aabb0.center()).array().abs();
48  VectorType totalSizes = ((aabb0.sizes() + aabb1.sizes()) * 0.5).array() + tolerance;
49
50  return (vector.array() <= totalSizes.array()).all();
51 }
52
59 template <class Scalar, int Dim>
60 bool doAabbIntersect(const Eigen::AlignedBox<Scalar, Dim>& a,
61  const Eigen::AlignedBox<Scalar, Dim>& b)
62 {
63  return !a.intersection(b).isEmpty();
64 }
70 template <class Scalar, int Dim, int MType>
71 Eigen::AlignedBox<Scalar, Dim> makeAabb(
72  const Eigen::Matrix<Scalar, Dim, 1, MType>& vector0,
73  const Eigen::Matrix<Scalar, Dim, 1, MType>& vector1,
74  const Eigen::Matrix<Scalar, Dim, 1, MType>& vector2)
75 {
76  Eigen::AlignedBox<Scalar, Dim> result(vector0);
77  result.extend(vector1);
78  result.extend(vector2);
79  return std::move(result);
80 }
81 }
82 }
83
84 #endif
Eigen::AlignedBox< float, 3 > Aabbf
Wrapper around the Eigen type.
Definition: Aabb.h:27
Eigen::AlignedBox< double, 3 > Aabbd
Wrapper around the Eigen type.
Definition: Aabb.h:30
bool doAabbIntersect(const Eigen::AlignedBox< Scalar, Dim > &aabb0, const Eigen::AlignedBox< Scalar, Dim > &aabb1, double tolerance)
Determine whether two AABBs have an intersection with each other, for the calculation see http://www...
Definition: Aabb.h:41
Eigen::AlignedBox< Scalar, Dim > makeAabb(const Eigen::Matrix< Scalar, Dim, 1, MType > &vector0, const Eigen::Matrix< Scalar, Dim, 1, MType > &vector1, const Eigen::Matrix< Scalar, Dim, 1, MType > &vector2)
Convenience function for creating a bounding box from three vertices (e.g.
Definition: Aabb.h:71