Skip to content

Commit

Permalink
ui: replace line_vertices_data with QPolygonF (commaai#25001)
Browse files Browse the repository at this point in the history
use QPolygonF

use push_front
  • Loading branch information
deanlee authored and spektor56 committed Jul 1, 2022
1 parent 3f3834d commit 31b1edc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
6 changes: 3 additions & 3 deletions selfdrive/ui/qt/onroad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -427,13 +427,13 @@ void NvgWindow::drawLaneLines(QPainter &painter, const UIState *s) {
// 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<float>(scene.lane_line_probs[i], 0.0, 0.7)));
painter.drawPolygon(scene.lane_line_vertices[i].v, scene.lane_line_vertices[i].cnt);
painter.drawPolygon(scene.lane_line_vertices[i]);
}

// road edges
for (int i = 0; i < std::size(scene.road_edge_vertices); ++i) {
painter.setBrush(QColor::fromRgbF(1.0, 0, 0, std::clamp<float>(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);
painter.drawPolygon(scene.road_edge_vertices[i]);
}

// paint path
Expand All @@ -452,7 +452,7 @@ void NvgWindow::drawLaneLines(QPainter &painter, const UIState *s) {
bg.setColorAt(0.75 / 1.5, QColor::fromHslF(curve_hue / 360., 1.0, 0.68, 0.35));
bg.setColorAt(1.0, QColor::fromHslF(curve_hue / 360., 1.0, 0.68, 0.0));
painter.setBrush(bg);
painter.drawPolygon(scene.track_vertices.v, scene.track_vertices.cnt);
painter.drawPolygon(scene.track_vertices);

painter.restore();
}
Expand Down
20 changes: 7 additions & 13 deletions selfdrive/ui/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ static void update_leads(UIState *s, const cereal::RadarState::Reader &radar_sta
}

static void update_line_data(const UIState *s, const cereal::ModelDataV2::XYZTData::Reader &line,
float y_off, float z_off, line_vertices_data *pvd, int max_idx, bool allow_invert=true) {
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();

std::vector<QPointF> left_points, right_points;
QPolygonF left_points, right_points;
left_points.reserve(max_idx + 1);
right_points.reserve(max_idx + 1);

for (int i = 0; i <= max_idx; i++) {
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);
Expand All @@ -69,19 +72,10 @@ static void update_line_data(const UIState *s, const cereal::ModelDataV2::XYZTDa
continue;
}
left_points.push_back(left);
right_points.push_back(right);
right_points.push_front(right);
}
}

pvd->cnt = 2 * left_points.size();
assert(left_points.size() == right_points.size());
assert(pvd->cnt <= std::size(pvd->v));

for (int left_idx = 0; left_idx < left_points.size(); left_idx++){
int right_idx = 2 * left_points.size() - left_idx - 1;
pvd->v[left_idx] = left_points[left_idx];
pvd->v[right_idx] = right_points[left_idx];
}
*pvd = left_points + right_points;
}

static void update_model(UIState *s, const cereal::ModelDataV2::Reader &model) {
Expand Down
12 changes: 4 additions & 8 deletions selfdrive/ui/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QTimer>
#include <QColor>
#include <QFuture>
#include <QPolygonF>
#include <QTransform>

#include "cereal/messaging/messaging.h"
Expand Down Expand Up @@ -87,21 +88,16 @@ const QColor bg_colors [] = {
[STATUS_ALERT] = QColor(0xC9, 0x22, 0x31, 0xf1),
};

typedef struct {
QPointF v[TRAJECTORY_SIZE * 2];
int cnt;
} line_vertices_data;

typedef struct UIScene {
mat3 view_from_calib;
cereal::PandaState::PandaType pandaType;

// modelV2
float lane_line_probs[4];
float road_edge_stds[2];
line_vertices_data track_vertices;
line_vertices_data lane_line_vertices[4];
line_vertices_data road_edge_vertices[2];
QPolygonF track_vertices;
QPolygonF lane_line_vertices[4];
QPolygonF road_edge_vertices[2];

// lead
QPointF lead_vertices[2];
Expand Down

0 comments on commit 31b1edc

Please sign in to comment.