Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: replace line_vertices_data with QPolygonF #25001

Merged
merged 1 commit into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions selfdrive/ui/qt/onroad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,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 @@ -455,7 +455,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 @@ -84,11 +85,6 @@ 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 {
bool calibration_valid = false;
mat3 view_from_calib = DEFAULT_CALIBRATION;
Expand All @@ -97,9 +93,9 @@ typedef struct UIScene {
// 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