Skip to content

Commit e49f0d1

Browse files
committed
Update OpenDrive conversion
1 parent 957e82d commit e49f0d1

27 files changed

+1479
-1142
lines changed

.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ ignore =
1616
E731
1717
# Local variable name is assigned to but never used
1818
F841
19+
per-file-ignores =
20+
# imported but unused
21+
__init__.py: F401
1922
max-line-length = 120

d123/common/visualization/matplotlib/observation.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import shapely.geometry as geom
66

77
from d123.common.datatypes.detection.detection import BoxDetectionWrapper, TrafficLightDetectionWrapper
8+
from d123.common.datatypes.detection.detection_types import DetectionType
89
from d123.common.datatypes.vehicle_state.ego_state import EgoStateSE2, EgoStateSE3
910
from d123.common.geometry.base import Point2D
1011
from d123.common.geometry.bounding_box.bounding_box import BoundingBoxSE2, BoundingBoxSE3
@@ -27,6 +28,7 @@
2728
from d123.dataset.maps.abstract_map import AbstractMap
2829
from d123.dataset.maps.abstract_map_objects import AbstractLane
2930
from d123.dataset.maps.map_datatypes import MapLayer
31+
from d123.dataset.scene.abstract_scene import AbstractScene
3032

3133

3234
def add_default_map_on_ax(
@@ -87,6 +89,39 @@ def add_box_detections_to_ax(ax: plt.Axes, box_detections: BoxDetectionWrapper)
8789
add_bounding_box_to_ax(ax, box_detection.bounding_box, plot_config)
8890

8991

92+
def add_box_future_detections_to_ax(ax: plt.Axes, scene: AbstractScene, iteration: int) -> None:
93+
94+
# TODO: Refactor this function
95+
initial_agents = scene.get_box_detections_at_iteration(iteration)
96+
agents_poses = {
97+
agent.metadata.track_token: [agent.center_se3]
98+
for agent in initial_agents
99+
if agent.metadata.detection_type == DetectionType.VEHICLE
100+
}
101+
frequency = 1
102+
for iteration in range(iteration + frequency, scene.get_number_of_iterations(), frequency):
103+
agents = scene.get_box_detections_at_iteration(iteration)
104+
for agent in agents:
105+
if agent.metadata.track_token in agents_poses:
106+
agents_poses[agent.metadata.track_token].append(agent.center_se3)
107+
108+
for track_token, poses in agents_poses.items():
109+
if len(poses) < 2:
110+
continue
111+
poses = np.array([pose.point_2d.array for pose in poses])
112+
num_poses = poses.shape[0]
113+
alphas = 1 - np.linspace(0.2, 1.0, num_poses) # Start low, end high
114+
for i in range(num_poses - 1):
115+
ax.plot(
116+
poses[i : i + 2, 0],
117+
poses[i : i + 2, 1],
118+
color=BOX_DETECTION_CONFIG[DetectionType.VEHICLE].fill_color.hex,
119+
alpha=alphas[i + 1],
120+
linewidth=BOX_DETECTION_CONFIG[DetectionType.VEHICLE].line_width * 5,
121+
zorder=BOX_DETECTION_CONFIG[DetectionType.VEHICLE].zorder,
122+
)
123+
124+
90125
def add_ego_vehicle_to_ax(ax: plt.Axes, ego_vehicle_state: Union[EgoStateSE3, EgoStateSE2]) -> None:
91126
add_bounding_box_to_ax(ax, ego_vehicle_state.bounding_box, EGO_VEHICLE_CONFIG)
92127

d123/common/visualization/viser/server.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
LINE_WIDTH: float = 4.0
3434

3535
# Bounding box config:
36-
BOUNDING_BOX_TYPE: Literal["mesh", "lines"] = "mesh"
36+
BOUNDING_BOX_TYPE: Literal["mesh", "lines"] = "lines"
3737

3838
# Map config:
3939
MAP_AVAILABLE: bool = True
@@ -182,6 +182,9 @@ def _(_) -> None:
182182
else:
183183
raise ValueError(f"Unknown bounding box type: {BOUNDING_BOX_TYPE}")
184184

185+
current_frame_handle.remove()
186+
current_frame_handle = mew_frame_handle
187+
185188
for camera_type in VISUALIZE_CAMERA_GUI:
186189
if camera_type in scene.available_camera_types:
187190
camera_gui_handles[camera_type].image = scene.get_camera_at_iteration(
@@ -208,8 +211,6 @@ def _(_) -> None:
208211
rendering_time = time.time() - start
209212
sleep_time = 1.0 / gui_framerate.value - rendering_time
210213
time.sleep(max(sleep_time, 0.0))
211-
current_frame_handle.remove()
212-
current_frame_handle = mew_frame_handle
213214
self.server.flush() # Optional!
214215

215216
# Load in frames.

d123/common/visualization/viser/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,15 @@ def get_map_meshes(scene: AbstractScene):
9797
center = initial_ego_vehicle_state.center_se3
9898
map_layers = [
9999
MapLayer.LANE_GROUP,
100-
# MapLayer.LANE,
101-
# MapLayer.WALKWAY,
100+
MapLayer.LANE,
101+
MapLayer.WALKWAY,
102102
MapLayer.CROSSWALK,
103-
# MapLayer.CARPARK,
103+
MapLayer.CARPARK,
104104
MapLayer.GENERIC_DRIVABLE,
105105
]
106106

107107
map_objects_dict = scene.map_api.get_proximal_map_objects(center.point_2d, radius=MAP_RADIUS, layers=map_layers)
108+
print(map_objects_dict.keys())
108109
output = {}
109110

110111
for map_layer in map_objects_dict.keys():
@@ -115,13 +116,13 @@ def get_map_meshes(scene: AbstractScene):
115116
if map_layer in [
116117
MapLayer.WALKWAY,
117118
MapLayer.CROSSWALK,
118-
# MapLayer.GENERIC_DRIVABLE,
119+
MapLayer.GENERIC_DRIVABLE,
119120
MapLayer.CARPARK,
120121
]:
121122
# Push meshes up by a few centimeters to avoid overlap with the ground in the visualization.
122123
trimesh_mesh.vertices -= Point3D(x=center.x, y=center.y, z=center.z - 0.1).array
123124
else:
124-
trimesh_mesh.vertices -= Point3D(x=center.x, y=center.y, z=center.z + 0.1).array
125+
trimesh_mesh.vertices -= Point3D(x=center.x, y=center.y, z=center.z).array
125126

126127
if not scene.log_metadata.map_has_z:
127128
trimesh_mesh.vertices += Point3D(
@@ -131,7 +132,6 @@ def get_map_meshes(scene: AbstractScene):
131132
trimesh_mesh = configure_trimesh(trimesh_mesh, MAP_SURFACE_CONFIG[map_layer].fill_color)
132133
surface_meshes.append(trimesh_mesh)
133134
output[f"{map_layer.serialize()}"] = trimesh.util.concatenate(surface_meshes)
134-
135135
return output
136136

137137

d123/dataset/conversion/map/opendrive/elements/enums.py

Lines changed: 0 additions & 45 deletions
This file was deleted.

d123/dataset/conversion/map/opendrive/elements/reference.py

Lines changed: 0 additions & 211 deletions
This file was deleted.

0 commit comments

Comments
 (0)