ui/drawLaneLines: read the accel from the submaster outside of the loop (#28145)

* read the accel from the submaster outside of the loop.

* const max_idx

* remove data copy and converting from list to vector

* correct name is len

* fix drawing last point

* add comment, remove right_points

* fix

---------

Co-authored-by: Shane Smiskol <shane@smiskol.com>
pull/28158/head
Dean Lee 2 years ago committed by GitHub
parent d738f66711
commit 2ec14c2065
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      selfdrive/ui/qt/onroad.cc

@ -513,17 +513,17 @@ void AnnotatedCameraWidget::drawLaneLines(QPainter &painter, const UIState *s) {
// paint path
QLinearGradient bg(0, height(), 0, 0);
if (sm["controlsState"].getControlsState().getExperimentalMode()) {
const QVector<QPointF> right_points = scene.track_vertices.mid(0, scene.track_vertices.length() / 2);
for (int i = 0; i < right_points.length(); i++) {
const auto &acceleration = sm["uiPlan"].getUiPlan().getAccel();
if (i >= acceleration.size()) break;
// The first half of track_vertices are the points for the right side of the path
// and the indices match the positions of accel from uiPlan
const auto &acceleration = sm["uiPlan"].getUiPlan().getAccel();
const int max_len = std::min<int>(scene.track_vertices.length() / 2, acceleration.size());
for (int i = 0; i < max_len; ++i) {
// Some points are out of frame
if (right_points[i].y() < 0 || right_points[i].y() > height()) continue;
if (scene.track_vertices[i].y() < 0 || scene.track_vertices[i].y() > height()) continue;
// Flip so 0 is bottom of frame
float lin_grad_point = (height() - right_points[i].y()) / height();
float lin_grad_point = (height() - scene.track_vertices[i].y()) / height();
// speed up: 120, slow down: 0
float path_hue = fmax(fmin(60 + acceleration[i] * 35, 120), 0);
@ -536,7 +536,7 @@ void AnnotatedCameraWidget::drawLaneLines(QPainter &painter, const UIState *s) {
bg.setColorAt(lin_grad_point, QColor::fromHslF(path_hue / 360., saturation, lightness, alpha));
// Skip a point, unless next is last
i += (i + 2) < right_points.length() ? 1 : 0;
i += (i + 2) < max_len ? 1 : 0;
}
} else {

Loading…
Cancel
Save