mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-02-26 17:13:57 +08:00
* squash mapbox stuff * only hacks for pc * no hack there * only update when needed * get destination from param * no need for user agent * add athena method * change nav path color * layout cleanups * margin top * add build scripts * rename header file * set pitch * fix icon blinking * keep both options * draw on top to fix last blinking * only recomput with gps * fix include * put map in onroadwidget * update mapbox plugin to allow specifying directions url * cycle through views * dynamic resize * only when present * add map_helpers * whitespace * small fixes * let scons decide * update setup files * implicit dependency * fix alerts * Update selfdrive/ui/SConscript * move clearLayout to util.h * only build when map.cc present * move maps to own folder Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
87 lines
3.0 KiB
C++
87 lines
3.0 KiB
C++
#include "selfdrive/ui/qt/maps/map_helpers.h"
|
|
|
|
|
|
QGeoCoordinate to_QGeoCoordinate(const QMapbox::Coordinate &in) {
|
|
return QGeoCoordinate(in.first, in.second);
|
|
}
|
|
|
|
QMapbox::CoordinatesCollections model_to_collection(
|
|
const cereal::LiveLocationKalman::Measurement::Reader &calibratedOrientationECEF,
|
|
const cereal::LiveLocationKalman::Measurement::Reader &positionECEF,
|
|
const cereal::ModelDataV2::XYZTData::Reader &line){
|
|
|
|
Eigen::Vector3d ecef(positionECEF.getValue()[0], positionECEF.getValue()[1], positionECEF.getValue()[2]);
|
|
Eigen::Vector3d orient(calibratedOrientationECEF.getValue()[0], calibratedOrientationECEF.getValue()[1], calibratedOrientationECEF.getValue()[2]);
|
|
Eigen::Matrix3d ecef_from_local = euler2rot(orient).transpose();
|
|
|
|
QMapbox::Coordinates coordinates;
|
|
auto x = line.getX();
|
|
auto y = line.getY();
|
|
auto z = line.getZ();
|
|
for (int i = 0; i < x.size(); i++){
|
|
Eigen::Vector3d point_ecef = ecef_from_local * Eigen::Vector3d(x[i], y[i], z[i]) + ecef;
|
|
Geodetic point_geodetic = ecef2geodetic((ECEF){.x = point_ecef[0], .y = point_ecef[1], .z = point_ecef[2]});
|
|
QMapbox::Coordinate coordinate(point_geodetic.lat, point_geodetic.lon);
|
|
coordinates.push_back(coordinate);
|
|
}
|
|
|
|
QMapbox::CoordinatesCollection collection;
|
|
collection.push_back(coordinates);
|
|
|
|
QMapbox::CoordinatesCollections collections;
|
|
collections.push_back(collection);
|
|
return collections;
|
|
}
|
|
|
|
QMapbox::CoordinatesCollections coordinate_to_collection(QMapbox::Coordinate c){
|
|
QMapbox::Coordinates coordinates;
|
|
coordinates.push_back(c);
|
|
|
|
QMapbox::CoordinatesCollection collection;
|
|
collection.push_back(coordinates);
|
|
|
|
QMapbox::CoordinatesCollections collections;
|
|
collections.push_back(collection);
|
|
return collections;
|
|
}
|
|
|
|
QMapbox::CoordinatesCollections coordinate_list_to_collection(QList<QGeoCoordinate> coordinate_list) {
|
|
QMapbox::Coordinates coordinates;
|
|
|
|
for (auto &c : coordinate_list){
|
|
QMapbox::Coordinate coordinate(c.latitude(), c.longitude());
|
|
coordinates.push_back(coordinate);
|
|
}
|
|
|
|
QMapbox::CoordinatesCollection collection;
|
|
collection.push_back(coordinates);
|
|
|
|
QMapbox::CoordinatesCollections collections;
|
|
collections.push_back(collection);
|
|
return collections;
|
|
}
|
|
|
|
static QGeoCoordinate sub(QGeoCoordinate v, QGeoCoordinate w){
|
|
return QGeoCoordinate(v.latitude() - w.latitude(), v.longitude() - w.longitude());
|
|
}
|
|
|
|
static QGeoCoordinate add(QGeoCoordinate v, QGeoCoordinate w){
|
|
return QGeoCoordinate(v.latitude() + w.latitude(), v.longitude() + w.longitude());
|
|
}
|
|
|
|
static QGeoCoordinate mul(QGeoCoordinate v, float c){
|
|
return QGeoCoordinate(c * v.latitude(), c * v.longitude());
|
|
}
|
|
|
|
static float dot(QGeoCoordinate v, QGeoCoordinate w){
|
|
return v.latitude() * w.latitude() + v.longitude() * w.longitude();
|
|
}
|
|
|
|
float minimum_distance(QGeoCoordinate a, QGeoCoordinate b, QGeoCoordinate p) {
|
|
const QGeoCoordinate ap = sub(p, a);
|
|
const QGeoCoordinate ab = sub(b, a);
|
|
const float t = std::clamp(dot(ap, ab) / dot(ab, ab), 0.0f, 1.0f);
|
|
const QGeoCoordinate projection = add(a, mul(ab, t));
|
|
return projection.distanceTo(p);
|
|
}
|