CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
geom
LibCarla/source/carla/geom/BoundingBox.h
Go to the documentation of this file.
1
// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2
// de Barcelona (UAB).
3
//
4
// This work is licensed under the terms of the MIT license.
5
// For a copy, see <https://opensource.org/licenses/MIT>.
6
7
#pragma once
8
9
#include "
carla/Debug.h
"
10
#include "
carla/MsgPack.h
"
11
#include "
carla/geom/Transform.h
"
12
#include "
carla/geom/Location.h
"
13
#include "
carla/geom/Vector3D.h
"
14
15
#include <array>
16
17
#ifdef LIBCARLA_INCLUDED_FROM_UE4
18
#include <
util/enable-ue4-macros.h
>
19
#include "
Carla/Util/BoundingBox.h
"
20
#include <
util/disable-ue4-macros.h
>
21
#endif
// LIBCARLA_INCLUDED_FROM_UE4
22
23
namespace
carla
{
24
namespace
geom
{
25
26
class
BoundingBox
{
27
public
:
28
29
BoundingBox
() =
default
;
30
31
// =========================================================================
32
// -- Constructors ---------------------------------------------------------
33
// =========================================================================
34
35
explicit
BoundingBox
(
const
Location
&in_location,
const
Vector3D
&in_extent,
const
Rotation
&in_rotation)
36
:
location
(in_location),
37
extent
(in_extent),
38
rotation
(in_rotation) {}
39
40
explicit
BoundingBox
(
const
Location
&in_location,
const
Vector3D
&in_extent)
41
:
location
(in_location),
42
extent
(in_extent),
43
rotation
() {}
44
45
explicit
BoundingBox
(
const
Vector3D
&in_extent)
46
:
location
(),
47
extent
(in_extent),
48
rotation
() {}
49
50
Location
location
;
///< Center of the BoundingBox in local space
51
Vector3D
extent
;
///< Half the size of the BoundingBox in local space
52
Rotation
rotation
;
///< Rotation of the BoundingBox in local space
53
54
// =========================================================================
55
// -- Other methods --------------------------------------------------------
56
// =========================================================================
57
58
/**
59
* Whether this BoundingBox contains @a in_world_point in world space.
60
* @param in_world_point the point in world space that you want to query whether it is inside or not.
61
* @param in_bbox_to_world_transform the transformation from BoundingBox space to World space.
62
*/
63
bool
Contains
(
const
Location
&in_world_point,
const
Transform
&in_bbox_to_world_transform)
const
{
64
auto
point_in_bbox_space = in_world_point;
65
in_bbox_to_world_transform.
InverseTransformPoint
(point_in_bbox_space);
66
point_in_bbox_space -=
location
;
67
68
return
point_in_bbox_space.
x
>= -
extent
.
x
&& point_in_bbox_space.x <=
extent
.
x
&&
69
point_in_bbox_space.y >= -
extent
.
y
&& point_in_bbox_space.y <=
extent
.
y
&&
70
point_in_bbox_space.z >= -
extent
.
z
&& point_in_bbox_space.z <=
extent
.
z
;
71
}
72
73
/**
74
* Returns the positions of the 8 vertices of this BoundingBox in local space.
75
*/
76
std::array<Location, 8>
GetLocalVertices
()
const
{
77
78
return
{{
79
location
+
Location
(
rotation
.
RotateVector
({-extent.x,-extent.y,-extent.z})),
80
location
+
Location
(
rotation
.
RotateVector
({-extent.x,-extent.y, extent.z})),
81
location
+
Location
(
rotation
.
RotateVector
({-extent.x, extent.y,-extent.z})),
82
location
+
Location
(
rotation
.
RotateVector
({-extent.x, extent.y, extent.z})),
83
location
+
Location
(
rotation
.
RotateVector
({ extent.x,-extent.y,-extent.z})),
84
location
+
Location
(
rotation
.
RotateVector
({ extent.x,-extent.y, extent.z})),
85
location
+
Location
(
rotation
.
RotateVector
({ extent.x, extent.y,-extent.z})),
86
location
+
Location
(
rotation
.
RotateVector
({ extent.x, extent.y, extent.z}))
87
}};
88
}
89
90
/**
91
* Returns the positions of the 8 vertices of this BoundingBox in local space without its own rotation.
92
*/
93
std::array<Location, 8>
GetLocalVerticesNoRotation
()
const
{
94
95
return
{{
96
location
+
Location
(-
extent
.
x
,-
extent
.
y
,-
extent
.
z
),
97
location
+
Location
(-
extent
.
x
,-
extent
.
y
,
extent
.
z
),
98
location
+
Location
(-
extent
.
x
,
extent
.
y
,-
extent
.
z
),
99
location
+
Location
(-
extent
.
x
,
extent
.
y
,
extent
.
z
),
100
location
+
Location
(
extent
.
x
,-
extent
.
y
,-
extent
.
z
),
101
location
+
Location
(
extent
.
x
,-
extent
.
y
,
extent
.
z
),
102
location
+
Location
(
extent
.
x
,
extent
.
y
,-
extent
.
z
),
103
location
+
Location
(
extent
.
x
,
extent
.
y
,
extent
.
z
)
104
}};
105
}
106
107
/**
108
* Returns the positions of the 8 vertices of this BoundingBox in world space.
109
* @param in_bbox_to_world_tr The Transform from this BoundingBox space to world space.
110
*/
111
std::array<Location, 8>
GetWorldVertices
(
const
Transform
&in_bbox_to_world_tr)
const
{
112
auto
world_vertices =
GetLocalVertices
();
113
std::for_each(world_vertices.begin(), world_vertices.end(), [&in_bbox_to_world_tr](
auto
&world_vertex) {
114
in_bbox_to_world_tr.TransformPoint(world_vertex);
115
});
116
return
world_vertices;
117
}
118
119
// =========================================================================
120
// -- Comparison operators -------------------------------------------------
121
// =========================================================================
122
123
bool
operator==
(
const
BoundingBox
&rhs)
const
{
124
return
(
location
== rhs.
location
) && (
extent
== rhs.
extent
) && (
rotation
== rhs.
rotation
);
125
}
126
127
bool
operator!=
(
const
BoundingBox
&rhs)
const
{
128
return
!(*
this
== rhs);
129
}
130
131
// =========================================================================
132
// -- Conversions to UE4 types ---------------------------------------------
133
// =========================================================================
134
135
#ifdef LIBCARLA_INCLUDED_FROM_UE4
136
137
BoundingBox
(
const
FBoundingBox
&Box)
138
:
location
(Box.Origin),
139
extent
(1e-2f * Box.Extent.X, 1e-2f * Box.Extent.Y, 1e-2f * Box.Extent.Z),
140
rotation
(Box.
Rotation
) {}
141
142
#endif
// LIBCARLA_INCLUDED_FROM_UE4
143
144
MSGPACK_DEFINE_ARRAY
(
location
,
extent
,
rotation
);
145
};
146
147
}
// namespace geom
148
}
// namespace carla
Debug.h
MsgPack.h
BoundingBox.h
carla::geom::BoundingBox::BoundingBox
BoundingBox(const Vector3D &in_extent)
Definition
LibCarla/source/carla/geom/BoundingBox.h:45
carla::geom::BoundingBox::operator!=
bool operator!=(const BoundingBox &rhs) const
Definition
LibCarla/source/carla/geom/BoundingBox.h:127
carla::geom::BoundingBox::BoundingBox
BoundingBox()=default
carla::geom::BoundingBox::location
Location location
Center of the BoundingBox in local space.
Definition
LibCarla/source/carla/geom/BoundingBox.h:50
carla::geom::BoundingBox::GetLocalVertices
std::array< Location, 8 > GetLocalVertices() const
Returns the positions of the 8 vertices of this BoundingBox in local space.
Definition
LibCarla/source/carla/geom/BoundingBox.h:76
carla::geom::BoundingBox::GetLocalVerticesNoRotation
std::array< Location, 8 > GetLocalVerticesNoRotation() const
Returns the positions of the 8 vertices of this BoundingBox in local space without its own rotation.
Definition
LibCarla/source/carla/geom/BoundingBox.h:93
carla::geom::BoundingBox::MSGPACK_DEFINE_ARRAY
MSGPACK_DEFINE_ARRAY(location, extent, rotation)
carla::geom::BoundingBox::BoundingBox
BoundingBox(const Location &in_location, const Vector3D &in_extent)
Definition
LibCarla/source/carla/geom/BoundingBox.h:40
carla::geom::BoundingBox::Contains
bool Contains(const Location &in_world_point, const Transform &in_bbox_to_world_transform) const
Whether this BoundingBox contains in_world_point in world space.
Definition
LibCarla/source/carla/geom/BoundingBox.h:63
carla::geom::BoundingBox::extent
Vector3D extent
Half the size of the BoundingBox in local space.
Definition
LibCarla/source/carla/geom/BoundingBox.h:51
carla::geom::BoundingBox::BoundingBox
BoundingBox(const FBoundingBox &Box)
Definition
LibCarla/source/carla/geom/BoundingBox.h:137
carla::geom::BoundingBox::GetWorldVertices
std::array< Location, 8 > GetWorldVertices(const Transform &in_bbox_to_world_tr) const
Returns the positions of the 8 vertices of this BoundingBox in world space.
Definition
LibCarla/source/carla/geom/BoundingBox.h:111
carla::geom::BoundingBox::BoundingBox
BoundingBox(const Location &in_location, const Vector3D &in_extent, const Rotation &in_rotation)
Definition
LibCarla/source/carla/geom/BoundingBox.h:35
carla::geom::BoundingBox::operator==
bool operator==(const BoundingBox &rhs) const
Definition
LibCarla/source/carla/geom/BoundingBox.h:123
carla::geom::BoundingBox::rotation
Rotation rotation
Rotation of the BoundingBox in local space.
Definition
LibCarla/source/carla/geom/BoundingBox.h:52
carla::geom::Rotation
Euler angles of a rotation in CARLA's / Unreal's left-handed frame: x forward, y right,...
Definition
Rotation.h:45
carla::geom::Rotation::RotateVector
void RotateVector(Vector3D &in_point) const
Definition
Rotation.h:87
carla::geom::Transform
A rigid transform in CARLA's / Unreal's left-handed frame: x forward, y right, z up,...
Definition
geom/Transform.h:32
carla::geom::Transform::InverseTransformPoint
void InverseTransformPoint(Vector3D &in_point) const
Applies the inverse of this transformation to in_point.
Definition
geom/Transform.h:91
disable-ue4-macros.h
enable-ue4-macros.h
Location.h
Transform.h
Vector3D.h
carla::geom
Definition
Misc.h:24
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
FBoundingBox
Definition
Unreal/CarlaUnreal/Plugins/Carla/Source/Carla/Util/BoundingBox.h:13
carla::geom::Location
Definition
geom/Location.h:23
carla::geom::Location::Location
Location()=default
carla::geom::Vector3D
Definition
geom/Vector3D.h:17
carla::geom::Vector3D::y
float y
Definition
geom/Vector3D.h:27
carla::geom::Vector3D::x
float x
Definition
geom/Vector3D.h:25
carla::geom::Vector3D::z
float z
Definition
geom/Vector3D.h:29
Generated by
1.18.0