app
android
jni
tango-gl
bounding_box.cpp
Go to the documentation of this file.
1
#include "
tango-gl/bounding_box.h
"
2
3
namespace
tango_gl
{
4
BoundingBox::BoundingBox
(
const
std::vector<float>&
vertices
) {
5
// Set min and max to the first vertice.
6
bounding_min_
=
glm::vec3
(
vertices
[0],
vertices
[1],
vertices
[2]);
7
bounding_max_
=
bounding_min_
;
8
size_t
vertices_count =
vertices
.size() / 3;
9
for
(
size_t
i
= 1;
i
< vertices_count;
i
+= 3) {
10
bounding_min_
.
x
=
std::min
(
vertices
[
i
* 3],
bounding_min_
.
x
);
11
bounding_min_
.
y
=
std::min
(
vertices
[
i
* 3 + 1],
bounding_min_
.
y
);
12
bounding_min_
.
z
=
std::min
(
vertices
[
i
* 3 + 2],
bounding_min_
.
z
);
13
14
bounding_max_
.
x
=
std::max
(
vertices
[
i
* 3],
bounding_max_
.
x
);
15
bounding_max_
.
y
=
std::max
(
vertices
[
i
* 3 + 1],
bounding_max_
.
y
);
16
bounding_max_
.
z
=
std::max
(
vertices
[
i
* 3 + 2],
bounding_max_
.
z
);
17
}
18
}
19
20
bool
BoundingBox::IsIntersecting
(
const
Segment
& segment,
21
const
glm::quat
&
rotation
,
22
const
glm::mat4
& transformation) {
23
// The current bounding box.
24
glm::vec3
min
,
max
;
25
26
// If the mesh has been rotated, we need to derive a new bounding box
27
// based on the original one, if it just been translated or scaled,
28
// we can still use the original one with current model matrix applied.
29
if
(
rotation
==
glm::quat
(1.0
f
, 0.0
f
, 0.0
f
, 0.0
f
)) {
30
min
=
util::ApplyTransform
(
transformation
,
bounding_min_
);
31
max
=
util::ApplyTransform
(
transformation
,
bounding_max_
);
32
}
else
{
33
std::vector<glm::vec3>
box
;
34
// Derive 8 vertices of the new bounding box from original min and max.
35
box
.push_back(
bounding_min_
);
36
box
.push_back(
bounding_max_
);
37
38
box
.push_back(
glm::vec3
(
bounding_min_
.
x
,
bounding_max_
.
y
,
bounding_max_
.
z
));
39
box
.push_back(
glm::vec3
(
bounding_max_
.
x
,
bounding_min_
.
y
,
bounding_min_
.
z
));
40
41
box
.push_back(
glm::vec3
(
bounding_min_
.
x
,
bounding_min_
.
y
,
bounding_max_
.
z
));
42
box
.push_back(
glm::vec3
(
bounding_max_
.
x
,
bounding_max_
.
y
,
bounding_min_
.
z
));
43
44
box
.push_back(
glm::vec3
(
bounding_max_
.
x
,
bounding_min_
.
y
,
bounding_max_
.
z
));
45
box
.push_back(
glm::vec3
(
bounding_min_
.
x
,
bounding_max_
.
y
,
bounding_min_
.
z
));
46
47
min
=
util::ApplyTransform
(
transformation
,
bounding_min_
);
48
max
=
min
;
49
for
(
size_t
i
= 1;
i
<
box
.size();
i
++) {
50
glm::vec3
temp =
util::ApplyTransform
(
transformation
,
box
[
i
]);
51
min
.x =
std::min
(temp.
x
,
min
.x);
52
min
.y =
std::min
(temp.
y
,
min
.y);
53
min
.z =
std::min
(temp.
z
,
min
.z);
54
55
max
.x =
std::max
(temp.
x
,
max
.x);
56
max
.y =
std::max
(temp.
y
,
max
.y);
57
max
.z =
std::max
(temp.
z
,
max
.z);
58
}
59
}
60
return
util::SegmentAABBIntersect
(
min
,
max
,
segment
.start,
segment
.end);
61
}
62
}
// namespace tango_gl
glm::min
GLM_FUNC_DECL genType min(genType const &x, genType const &y)
tango_gl::BoundingBox::IsIntersecting
bool IsIntersecting(const Segment &segment, const glm::quat &rotation, const glm::mat4 &transformation)
Definition:
bounding_box.cpp:20
tango_gl::util::ApplyTransform
glm::vec3 ApplyTransform(const glm::mat4 &mat, const glm::vec3 &vec)
Definition:
util.cpp:237
tango_gl::vertices
static const float vertices[]
Definition:
quad.cpp:39
tango_gl::BoundingBox::bounding_min_
glm::vec3 bounding_min_
Definition:
bounding_box.h:38
glm::vec3
highp_vec3 vec3
Definition:
type_vec.hpp:392
glm::detail::tquat
Definition:
fwd.hpp:41
glm::detail::tvec3
Definition:
type_mat.hpp:37
box
box
glm::detail::tmat4x4
Definition:
type_mat.hpp:47
bounding_box.h
tango_gl::Segment
Definition:
segment.h:23
glm::detail::tvec3::z
T z
Definition:
type_vec3.hpp:86
tango_gl::util::SegmentAABBIntersect
bool SegmentAABBIntersect(const glm::vec3 &aabb_min, const glm::vec3 &aabb_max, const glm::vec3 &start, const glm::vec3 &end)
Definition:
util.cpp:198
glm::max
GLM_FUNC_DECL genType max(genType const &x, genType const &y)
glm::detail::tvec3::y
T y
Definition:
type_vec3.hpp:85
glm::detail::tvec3::x
T x
Definition:
type_vec3.hpp:84
tango_gl::BoundingBox::bounding_max_
glm::vec3 bounding_max_
Definition:
bounding_box.h:39
f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
segment
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE FixedSegmentReturnType< N >::Type segment(Index start, Index n=N)
glm::rotation
GLM_FUNC_DECL detail::tquat< T, P > rotation(detail::tvec3< T, P > const &orig, detail::tvec3< T, P > const &dest)
transformation
transformation
tango_gl
Definition:
axis.cpp:20
tango_gl::BoundingBox::BoundingBox
BoundingBox()
Definition:
bounding_box.h:28
i
int i
rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:06