pcod-common
v1.0.0
Shared preprocessing and postprocessing for point-cloud object detection
Loading...
Searching...
No Matches
test_bounding_box.cpp
Go to the documentation of this file.
1
// Copyright Institute for Automotive Engineering (ika), RWTH Aachen University
2
// SPDX-License-Identifier: Apache-2.0
3
4
#include "
pcod_common/bounding_box.hpp
"
5
6
#include <cassert>
7
#include <cmath>
8
9
namespace
{
10
19
pcod_common::BoundingBox
MakeBox(
float
x,
float
y,
float
length,
float
width,
float
yaw) {
20
pcod_common::BoundingBox
box;
21
box.
center
= {x, y};
22
box.
length
= length;
23
box.
width
= width;
24
box.
yaw
= yaw;
25
return
box;
26
}
27
28
}
// namespace
29
31
int
main
() {
32
const
pcod_common::BoundingBox
base = MakeBox(0.0f, 0.0f, 4.0f, 2.0f, 0.0f);
33
34
{
35
const
pcod_common::BoundingBox
same = MakeBox(0.0f, 0.0f, 4.0f, 2.0f, 0.0f);
36
const
float
area_a = base.
intersection_area
(same);
37
const
float
area_b = same.
intersection_area
(base);
38
assert(std::abs(area_a - area_b) < 1e-6f);
39
assert(std::abs(area_a - (base.
length
* base.
width
)) < 1e-6f);
40
assert(base.
overlaps
(same, 0.99f));
41
}
42
43
{
44
const
pcod_common::BoundingBox
far = MakeBox(100.0f, 100.0f, 4.0f, 2.0f, 0.0f);
45
assert(base.
intersection_area
(far) == 0.0f);
46
assert(!base.
overlaps
(far, 0.0f));
47
}
48
49
{
50
const
pcod_common::BoundingBox
shifted = MakeBox(1.0f, 0.0f, 4.0f, 2.0f, 0.0f);
51
const
float
area_forward = base.
intersection_area
(shifted);
52
const
float
area_reverse = shifted.
intersection_area
(base);
53
assert(area_forward > 0.0f);
54
assert(std::abs(area_forward - area_reverse) < 1e-6f);
55
}
56
57
{
58
const
pcod_common::BoundingBox
rotated = MakeBox(0.0f, 0.0f, 4.0f, 2.0f, 1.57079632679f);
59
const
float
area = base.
intersection_area
(rotated);
60
assert(area > 0.0f);
61
assert(area < base.
length
* base.
width
);
62
}
63
64
return
0;
65
}
bounding_box.hpp
pcod_common::BoundingBox
Definition
bounding_box.hpp:63
pcod_common::BoundingBox::length
float length
Length along the local X axis.
Definition
bounding_box.hpp:66
pcod_common::BoundingBox::intersection_area
float intersection_area(const BoundingBox &other) const
Definition
bounding_box.cpp:11
pcod_common::BoundingBox::center
std::array< float, 2 > center
XY center in metres.
Definition
bounding_box.hpp:64
pcod_common::BoundingBox::width
float width
Width along the local Y axis.
Definition
bounding_box.hpp:67
pcod_common::BoundingBox::overlaps
bool overlaps(const BoundingBox &other, float iou_threshold) const
Definition
bounding_box.cpp:63
pcod_common::BoundingBox::yaw
float yaw
Heading in radians.
Definition
bounding_box.hpp:69
main
int main()
Definition
test_bounding_box.cpp:31
tests
test_bounding_box.cpp
Generated by
1.12.0