add speeding violation reporting
This commit is contained in:
parent
472e291ca8
commit
0c28d9dc80
12
src/drone.cc
12
src/drone.cc
@ -31,6 +31,10 @@ Drone::Drone(const QJsonObject &json)
|
||||
for (const QJsonValue &o : ja) {
|
||||
waypoints.append(Waypoint(o.toObject()));
|
||||
}
|
||||
for (int i = 0; i < waypoints.size() - 1; i++) {
|
||||
waypoints[i].computed_speed = (waypoints[i + 1].pos - waypoints[i].pos).length()
|
||||
/ (waypoints[i + 1].frame - waypoints[i].frame);
|
||||
}
|
||||
setTo(0);
|
||||
}
|
||||
|
||||
@ -55,10 +59,13 @@ void Drone::setTo(int frame) {
|
||||
}
|
||||
if (next > -1 && prev == -1) {
|
||||
pos = next_wp->pos;
|
||||
speed = next_wp->computed_speed;
|
||||
} else if (prev > -1 && next == -1) {
|
||||
pos = prev_wp->pos;
|
||||
speed = prev_wp->computed_speed;
|
||||
} else {
|
||||
pos = lerp(prev_wp->pos, next_wp->pos, (double) (frame-prev) / (next-prev));
|
||||
speed = prev_wp->computed_speed;
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,6 +80,11 @@ int Drone::getId() const {
|
||||
}
|
||||
|
||||
|
||||
double Drone::getSpeed() const {
|
||||
return speed;
|
||||
}
|
||||
|
||||
|
||||
const OpenGLMesh *Drone::getMesh() const {
|
||||
return mesh;
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ class Drone {
|
||||
QVector<Waypoint> waypoints;
|
||||
QVector3D pos;
|
||||
int id;
|
||||
double speed = 0;
|
||||
|
||||
public:
|
||||
Drone(int id);
|
||||
@ -30,6 +31,7 @@ public:
|
||||
void setTo(int frame);
|
||||
const QVector3D getPos() const;
|
||||
int getId() const;
|
||||
double getSpeed() const;
|
||||
const OpenGLMesh *getMesh() const;
|
||||
};
|
||||
|
||||
|
@ -261,6 +261,23 @@ void DroneController::computeCollisions(double sphere_radius) {
|
||||
}
|
||||
|
||||
|
||||
void DroneController::computeSpeedingViolations(double speed) {
|
||||
speed_violations.clear();
|
||||
for (int i = 0; i < duration; i++) {
|
||||
for (Drone &d : drones) {
|
||||
d.setTo(i);
|
||||
if (d.getSpeed() > speed) {
|
||||
speed_violations[i].append(d.getId());
|
||||
emit speedViolation(d.getId(), d.getSpeed(), i);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Drone &d : drones) {
|
||||
d.setTo(frame);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DroneController::displaySpheres(double sphere_radius) {
|
||||
draw_spheres = true;
|
||||
this->sphere_radius = sphere_radius;
|
||||
|
@ -25,6 +25,8 @@ class DroneController : public QObject, public Painter {
|
||||
QMap<int, QVector<QPair<int, int>>> collisions;
|
||||
bool draw_trajectories = false;
|
||||
bool draw_guides = false;
|
||||
QMap<int, QVector<int>> speed_violations;
|
||||
double speed_limit = 0;
|
||||
|
||||
static OpenGLMesh *sphere;
|
||||
static const unsigned char sphere_neutral[];
|
||||
@ -44,6 +46,7 @@ signals:
|
||||
void playing();
|
||||
void pausing();
|
||||
void collision(int idA, int idB, int frame);
|
||||
void speedViolation(int id, double speed, int frame);
|
||||
|
||||
private slots:
|
||||
void step();
|
||||
@ -55,6 +58,7 @@ public slots:
|
||||
void resume();
|
||||
void seek(int frame);
|
||||
void computeCollisions(double sphere_radius);
|
||||
void computeSpeedingViolations(double speed);
|
||||
void displaySpheres(double sphere_radius);
|
||||
void setDrawTrajectories(bool enable);
|
||||
void setDrawGuides(bool enable);
|
||||
|
@ -82,17 +82,27 @@ void MainWindow::open(const QString &path) {
|
||||
// Settings pane
|
||||
connect(settings_pane, &SettingsPane::bookmarkClicked,
|
||||
slider, &QSlider::setValue);
|
||||
|
||||
connect(dc, &DroneController::collision, settings_pane, &SettingsPane::addCollision);
|
||||
connect(dc, &DroneController::speedViolation, settings_pane, &SettingsPane::addSpeedingViolation);
|
||||
|
||||
connect(settings_pane, &SettingsPane::sphereRadiusChanged,
|
||||
[&](double _) { Q_UNUSED(_); settings_pane->clearCollisions(); });
|
||||
connect(settings_pane, &SettingsPane::sphereRadiusChanged,
|
||||
dc, &DroneController::computeCollisions);
|
||||
connect(settings_pane, &SettingsPane::sphereRadiusChanged,
|
||||
dc, &DroneController::displaySpheres);
|
||||
|
||||
connect(settings_pane, &SettingsPane::speedLimitChanged,
|
||||
[&](double _) { Q_UNUSED(_); settings_pane->clearSpeedingViolations(); });
|
||||
connect(settings_pane, &SettingsPane::speedLimitChanged,
|
||||
dc, &DroneController::computeSpeedingViolations);
|
||||
|
||||
connect(settings_pane, &SettingsPane::toggledTrajectories,
|
||||
dc, &DroneController::setDrawTrajectories);
|
||||
connect(settings_pane, &SettingsPane::toggledGuides,
|
||||
dc, &DroneController::setDrawGuides);
|
||||
|
||||
settings_pane->setEnabled(true);
|
||||
|
||||
glw.setPainter(dc);
|
||||
|
@ -12,6 +12,8 @@ SettingsPane::SettingsPane(QWidget *parent)
|
||||
:QWidget(parent) {
|
||||
QDoubleSpinBox *sphere_radius = new QDoubleSpinBox();
|
||||
sphere_radius->setSingleStep(.1);
|
||||
QDoubleSpinBox *speed_limit = new QDoubleSpinBox();
|
||||
speed_limit->setSingleStep(.1);
|
||||
QCheckBox *show_trajectories = new QCheckBox();
|
||||
QCheckBox *show_guides = new QCheckBox();
|
||||
collisions = new QListWidget();
|
||||
@ -19,6 +21,8 @@ SettingsPane::SettingsPane(QWidget *parent)
|
||||
|
||||
connect(sphere_radius, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
|
||||
this, &SettingsPane::sphereRadiusChanged);
|
||||
connect(speed_limit, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
|
||||
this, &SettingsPane::speedLimitChanged);
|
||||
connect(show_trajectories, &QCheckBox::stateChanged,
|
||||
this, &SettingsPane::toggledTrajectories);
|
||||
connect(show_guides, &QCheckBox::stateChanged,
|
||||
@ -32,6 +36,7 @@ SettingsPane::SettingsPane(QWidget *parent)
|
||||
|
||||
QFormLayout *layout = new QFormLayout;
|
||||
layout->addRow("Taille de la sphère de collision", sphere_radius);
|
||||
layout->addRow("Limite de vitesse", speed_limit);
|
||||
layout->addRow("Afficher les trajectoires", show_trajectories);
|
||||
layout->addRow("Afficher les guides", show_guides);
|
||||
|
||||
@ -52,7 +57,7 @@ void SettingsPane::addCollision(int idA, int idB, int frame) {
|
||||
}
|
||||
|
||||
|
||||
void SettingsPane::addSpeedingViolation(int id, int frame, double speed) {
|
||||
void SettingsPane::addSpeedingViolation(int id, double speed, int frame) {
|
||||
BookmarkItem *item = new BookmarkItem("Frame " + QString::number(frame) + ": #"
|
||||
+ QString::number(id) + " (" + QString::number(speed) + ")",
|
||||
frame);
|
||||
|
@ -28,7 +28,7 @@ public:
|
||||
|
||||
public slots:
|
||||
void addCollision(int idA, int idB, int frame);
|
||||
void addSpeedingViolation(int id, int frame, double speed);
|
||||
void addSpeedingViolation(int id, double speed, int frame);
|
||||
void clearCollisions();
|
||||
void clearSpeedingViolations();
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
struct Waypoint {
|
||||
int frame;
|
||||
QVector3D pos;
|
||||
double computed_speed = 0;
|
||||
|
||||
Waypoint(unsigned frame, QVector3D pos);
|
||||
Waypoint(const QJsonObject &json);
|
||||
|
Loading…
Reference in New Issue
Block a user