From 998cd7fa204081c12f7211113044dfa254a9e24c Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Thu, 14 Apr 2022 20:09:51 -0700 Subject: [PATCH] UI: new laneless design (#24169) * stash * Revert "stash" This reverts commit f0019010e28ffb6d70b3c84666572f30c22077c9. * new laneless ui * clean up * always draw lane lines * no compensation * make sure it's long enough * debug time * tune design * tune design 2 * correct scaling with new updated curve hue * debug time * full test * revert test * move yellow back a bit --- selfdrive/ui/qt/onroad.cc | 48 +++++++++++++++++++++++++++------------ selfdrive/ui/qt/onroad.h | 2 +- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/selfdrive/ui/qt/onroad.cc b/selfdrive/ui/qt/onroad.cc index cf997ed953..8af6fbae30 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -304,23 +304,41 @@ void NvgWindow::updateFrameMat(int w, int h) { .translate(-intrinsic_matrix.v[2], -intrinsic_matrix.v[5]); } -void NvgWindow::drawLaneLines(QPainter &painter, const UIScene &scene) { - if (!scene.end_to_end) { - // lanelines - for (int i = 0; i < std::size(scene.lane_line_vertices); ++i) { - painter.setBrush(QColor::fromRgbF(1.0, 1.0, 1.0, scene.lane_line_probs[i])); - painter.drawPolygon(scene.lane_line_vertices[i].v, scene.lane_line_vertices[i].cnt); - } - // road edges - for (int i = 0; i < std::size(scene.road_edge_vertices); ++i) { - painter.setBrush(QColor::fromRgbF(1.0, 0, 0, std::clamp(1.0 - scene.road_edge_stds[i], 0.0, 1.0))); - painter.drawPolygon(scene.road_edge_vertices[i].v, scene.road_edge_vertices[i].cnt); - } +void NvgWindow::drawLaneLines(QPainter &painter, const UIState *s) { + const UIScene &scene = s->scene; + // lanelines + for (int i = 0; i < std::size(scene.lane_line_vertices); ++i) { + painter.setBrush(QColor::fromRgbF(1.0, 1.0, 1.0, std::clamp(scene.lane_line_probs[i], 0.0, 0.7))); + painter.drawPolygon(scene.lane_line_vertices[i].v, scene.lane_line_vertices[i].cnt); + } + + // road edges + for (int i = 0; i < std::size(scene.road_edge_vertices); ++i) { + painter.setBrush(QColor::fromRgbF(1.0, 0, 0, std::clamp(1.0 - scene.road_edge_stds[i], 0.0, 1.0))); + painter.drawPolygon(scene.road_edge_vertices[i].v, scene.road_edge_vertices[i].cnt); } + // paint path QLinearGradient bg(0, height(), 0, height() / 4); - bg.setColorAt(0, scene.end_to_end ? redColor() : whiteColor()); - bg.setColorAt(1, scene.end_to_end ? redColor(0) : whiteColor(0)); + if (scene.end_to_end) { + const auto &orientation = (*s->sm)["modelV2"].getModelV2().getOrientation(); + float orientation_future = 0; + if (orientation.getZ().size() > 16) { + orientation_future = std::abs(orientation.getZ()[16]); // 2.5 seconds + } + // straight: 112, in turns: 70 + float curve_hue = fmax(70, 112 - (orientation_future * 420)); + // FIXME: painter.drawPolygon can be slow if hue is not rounded + curve_hue = int(curve_hue * 100 + 0.5) / 100; + + bg.setColorAt(0.0 / 1.5, QColor::fromHslF(148 / 360., 1.0, 0.5, 1.0)); + bg.setColorAt(0.55 / 1.5, QColor::fromHslF(112 / 360., 1.0, 0.68, 0.8)); + bg.setColorAt(0.9 / 1.5, QColor::fromHslF(curve_hue / 360., 1.0, 0.65, 0.6)); + bg.setColorAt(1.0, QColor::fromHslF(curve_hue / 360., 1.0, 0.65, 0.0)); + } else { + bg.setColorAt(0, whiteColor()); + bg.setColorAt(1, whiteColor(0)); + } painter.setBrush(bg); painter.drawPolygon(scene.track_vertices.v, scene.track_vertices.cnt); } @@ -366,7 +384,7 @@ void NvgWindow::paintGL() { painter.setRenderHint(QPainter::Antialiasing); painter.setPen(Qt::NoPen); - drawLaneLines(painter, s->scene); + drawLaneLines(painter, s); if (s->scene.longitudinal_control) { auto leads = (*s->sm)["modelV2"].getModelV2().getLeadsV3(); diff --git a/selfdrive/ui/qt/onroad.h b/selfdrive/ui/qt/onroad.h index 90a62c8771..1d95fa49f8 100644 --- a/selfdrive/ui/qt/onroad.h +++ b/selfdrive/ui/qt/onroad.h @@ -74,7 +74,7 @@ protected: void initializeGL() override; void showEvent(QShowEvent *event) override; void updateFrameMat(int w, int h) override; - void drawLaneLines(QPainter &painter, const UIScene &scene); + void drawLaneLines(QPainter &painter, const UIState *s); void drawLead(QPainter &painter, const cereal::ModelDataV2::LeadDataV3::Reader &lead_data, const QPointF &vd); inline QColor redColor(int alpha = 255) { return QColor(201, 34, 49, alpha); } inline QColor whiteColor(int alpha = 255) { return QColor(255, 255, 255, alpha); }