From 4d7bbd80fa0782f8c01fb61b258fc29609cd8d34 Mon Sep 17 00:00:00 2001 From: deanlee Date: Mon, 6 May 2024 17:58:28 +0800 Subject: [PATCH] improve update_line_data --- selfdrive/boardd/boardd_api_impl.pyx | 8 ++------ selfdrive/ui/ui.cc | 15 ++++++--------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/selfdrive/boardd/boardd_api_impl.pyx b/selfdrive/boardd/boardd_api_impl.pyx index 6a552bb44771fb..c4794f360863d2 100644 --- a/selfdrive/boardd/boardd_api_impl.pyx +++ b/selfdrive/boardd/boardd_api_impl.pyx @@ -18,13 +18,9 @@ def can_list_to_can_capnp(can_msgs, msgtype='can', valid=True): cdef vector[can_frame] can_list can_list.reserve(len(can_msgs)) - cdef can_frame f for can_msg in can_msgs: - f.address = can_msg[0] - f.busTime = can_msg[1] - f.dat = can_msg[2] - f.src = can_msg[3] - can_list.push_back(f) + can_list.emplace_back(can_frame(address=can_msg[0], busTime=can_msg[1], dat=can_msg[2], src=can_msg[3])) + cdef string out can_list_to_can_capnp_cpp(can_list, out, msgtype == 'sendcan', valid) return out diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 9afd22f13a12da..ee6bb26b9deabe 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -57,26 +57,23 @@ void update_leads(UIState *s, const cereal::RadarState::Reader &radar_state, con void update_line_data(const UIState *s, const cereal::XYZTData::Reader &line, float y_off, float z_off, QPolygonF *pvd, int max_idx, bool allow_invert=true) { const auto line_x = line.getX(), line_y = line.getY(), line_z = line.getZ(); - QPolygonF left_points, right_points; - left_points.reserve(max_idx + 1); - right_points.reserve(max_idx + 1); - + QPointF left, right; + pvd->clear(); for (int i = 0; i <= max_idx; i++) { // highly negative x positions are drawn above the frame and cause flickering, clip to zy plane of camera if (line_x[i] < 0) continue; - QPointF left, right; + bool l = calib_frame_to_full_frame(s, line_x[i], line_y[i] - y_off, line_z[i] + z_off, &left); bool r = calib_frame_to_full_frame(s, line_x[i], line_y[i] + y_off, line_z[i] + z_off, &right); if (l && r) { // For wider lines the drawn polygon will "invert" when going over a hill and cause artifacts - if (!allow_invert && left_points.size() && left.y() > left_points.back().y()) { + if (!allow_invert && pvd->size() && left.y() > pvd->back().y()) { continue; } - left_points.push_back(left); - right_points.push_front(right); + pvd->push_back(left); + pvd->push_front(right); } } - *pvd = left_points + right_points; } void update_model(UIState *s,