forked from argoverse/argoverse-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_centerline_utils.py
187 lines (150 loc) · 5.7 KB
/
test_centerline_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# <Copyright 2019, Argo AI, LLC. Released under the MIT license.>
import numpy as np
from numpy.testing import assert_almost_equal
from argoverse.utils.centerline_utils import (
centerline_to_polygon,
filter_candidate_centerlines,
get_normal_and_tangential_distance_point,
get_nt_distance,
is_overlapping_lane_seq,
)
def temp_test_straight_centerline_to_polygon():
"""
Try converting a simple straight polyline into a polygon. Represents
the conversion from a centerline to a lane segment polygon.
Note that the returned polygon will ba a Numpy array of
shape (2N+1,2), with duplicate first and last vertices.
Dots below signify the centerline coordinates.
| . |
| . |
| . |
| . |
"""
# create centerline: Numpy array of shape (N,2)
centerline = np.array([[0, 2.0], [0.0, 0.0], [0.0, -2.0]])
polygon = centerline_to_polygon(centerline)
# polygon wraps around with right boundary, then reversed
# left boundary, then back to start vertex
gt_polygon = np.array([[-3.8, 2.0], [-3.8, 0.0], [-3.8, -2.0], [3.8, -2.0], [3.8, 0.0], [3.8, 2.0], [-3.8, 2.0]])
assert np.array_equal(polygon, gt_polygon)
def test_is_overlapping_lane_seq():
"""Test is_overlapping_lane_seq"""
lane_seq1 = [1, 2, 3, 4]
lane_seq2 = [2, 3, 4, 5]
assert is_overlapping_lane_seq(lane_seq1, lane_seq2)
lane_seq1 = [1, 2, 3, 4]
lane_seq2 = [3, 4]
assert is_overlapping_lane_seq(lane_seq1, lane_seq2)
lane_seq1 = [1, 2, 3, 4]
lane_seq2 = [0, 3, 4]
assert not is_overlapping_lane_seq(lane_seq1, lane_seq2)
def test_get_nt_distance_point():
"""Compute distances in centerline frame for a point"""
"""Test Case
0 1 . . 3 . 4 . 5 . 6 . 7
* 5
\
* 4
\
* 3
\
* x 2
\
. *---*---*---*---* 1
0
"""
x = 4.0
y = 2.0
centerline = [
(1.0, 5.0),
(1.5, 4.0),
(2.0, 3.0),
(2.5, 2.0),
(3.0, 1.0),
(4.0, 1.0),
(5.0, 1.0),
(6.0, 1.0),
(7.0, 1.0),
]
tang_dist, norm_dist = get_normal_and_tangential_distance_point(x, y, centerline)
assert_almost_equal(tang_dist, 5.472, 3)
assert_almost_equal(norm_dist, 1.000, 3)
def test_get_nt_distance():
"""Compute distances in centerline frame for a trajectory"""
"""Test Case
0 1 . . 3 . 4 . 5 . 6 . 7
* 5
\
x * 4
\
* x 3
\
x * x 2
\
. *---*---*---*---x 1
x 0
"""
xy = np.array([(0.0, 4.0), (3.0, 3.0), (1.0, 2.0), (4.0, 2.0), (5.0, 0.0), (7.0, 1.0)])
centerline = np.array(
[(1.0, 5.0), (1.5, 4.0), (2.0, 3.0), (2.5, 2.0), (3.0, 1.0), (4.0, 1.0), (5.0, 1.0), (6.0, 1.0), (7.0, 1.0)]
)
nt_dist = get_nt_distance(xy, centerline)
expected_nt_dist = np.array([[1.34, 0.44], [2.68, 0.89], [2.68, 1.34], [5.47, 1.0], [6.47, 1.0], [8.47, 0.0]])
print(nt_dist, expected_nt_dist)
np.array_equal(nt_dist, expected_nt_dist)
def test_filter_candidate_centerlines():
"""Test filter candidate centerlines"""
# Test Case
# 0 20 24 30 40 60
# * * 50
# | |
# | |
# | |
# | |
# | | 40
# (3) | | (2)
# ^ ^
# ^ ^
# | |
# | |
# | | (1)
# *--------<<<-----------|---------|--------<<<--------* 30
# | \ |
# xxxxxxxx^x \ ^
# ^ x \(5) ^
# (4) | x \ |
# *-------->>>-----------|---x-\---|-------->>>--------* 20
# | x \ |
# | x \ |
# | x \|
# | x | 10
# | x |
# ^ x ^
# ^ x ^
# | |
# * * 0
#
xy = np.array(
[
[35.0, 0.0],
[35.0, 4.0],
[35.0, 8.0],
[35.0, 12.0],
[35.0, 16.0],
[33.0, 20.0],
[31.0, 24.0],
[29.0, 28.0],
[25.0, 28.0],
[21.0, 28.0],
]
)
cl1 = np.array([(60.0, 30.0), (0.0, 30.0)])
cl2 = np.array([(40.0, 0.0), (40.0, 50.0)])
cl3 = np.array([(30.0, 0.0), (30.0, 50.0)])
cl4 = np.array([(0.0, 20.0), (60.0, 20.0)])
cl5 = np.array([(40.0, 0.0), (40.0, 10.0), (30.0, 30.0), (0.0, 30.0)])
candidate_cl = [cl1, cl2, cl3, cl4, cl5]
filtered_cl = sorted(filter_candidate_centerlines(xy, candidate_cl))
expected_cl = [cl5]
for i in range(len(filtered_cl)):
assert np.allclose(expected_cl[i], filtered_cl[i]), "Filtered centerlines wrong!"