From f9c593e6d1b49c797e9189055ffb579246af9be3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Thu, 29 Aug 2019 20:15:03 +0200 Subject: [PATCH] Fixed the "DEM values not used in route points" issue --- src/GUI/routeitem.cpp | 2 +- src/data/data.cpp | 32 ++++++++++++++++++++++++++------ src/data/data.h | 3 +-- src/data/route.cpp | 17 ++--------------- src/data/route.h | 6 +----- src/data/track.cpp | 16 ++-------------- src/data/track.h | 2 -- 7 files changed, 33 insertions(+), 45 deletions(-) diff --git a/src/GUI/routeitem.cpp b/src/GUI/routeitem.cpp index 22f502e6..201b4423 100644 --- a/src/GUI/routeitem.cpp +++ b/src/GUI/routeitem.cpp @@ -24,7 +24,7 @@ QString RouteItem::toolTip(Units units) const RouteItem::RouteItem(const Route &route, Map *map, QGraphicsItem *parent) : PathItem(route.path(), map, parent) { - const QVector &waypoints = route.waypoints(); + const RouteData &waypoints = route.data(); _waypoints.resize(waypoints.size()); for (int i = 0; i < waypoints.size(); i++) diff --git a/src/data/data.cpp b/src/data/data.cpp index 684eab42..bc3e202f 100644 --- a/src/data/data.cpp +++ b/src/data/data.cpp @@ -71,13 +71,35 @@ static QHash parsers() QHash Data::_parsers = parsers(); bool Data::_useDEM = false; -void Data::processData(const QList &trackData, - const QList &routeData) +void Data::processData(QList &trackData, QList &routeData) { - for (int i = 0; i < trackData.count(); i++) + for (int i = 0; i < trackData.count(); i++) { + TrackData &track = trackData[i]; + for (int j = 0; j < track.size(); j++) { + SegmentData &segment = track[j]; + for (int k = 0; k < segment.size(); k++) { + Trackpoint &t = segment[k]; + if (!t.hasElevation() || _useDEM) { + qreal elevation = DEM::elevation(t.coordinates()); + if (!std::isnan(elevation)) + t.setElevation(elevation); + } + } + } _tracks.append(Track(trackData.at(i))); - for (int i = 0; i < routeData.count(); i++) + } + for (int i = 0; i < routeData.count(); i++) { + RouteData &route = routeData[i]; + for (int j = 0; j < route.size(); j++) { + Waypoint &w = route[j]; + if (!w.hasElevation() || _useDEM) { + qreal elevation = DEM::elevation(w.coordinates()); + if (!std::isnan(elevation)) + w.setElevation(elevation); + } + } _routes.append(Route(routeData.at(i))); + } for (int i = 0; i < _waypoints.size(); i++) { if (!_waypoints.at(i).hasElevation() || _useDEM) { qreal elevation = DEM::elevation(_waypoints.at(i).coordinates()); @@ -181,6 +203,4 @@ QStringList Data::filter() void Data::useDEM(bool use) { _useDEM = use; - Route::useDEM(use); - Track::useDEM(use); } diff --git a/src/data/data.h b/src/data/data.h index d651f67d..48e490ee 100644 --- a/src/data/data.h +++ b/src/data/data.h @@ -31,8 +31,7 @@ public: static void useDEM(bool use); private: - void processData(const QList &trackData, - const QList &routeData); + void processData(QList &trackData, QList &routeData); bool _valid; QString _errorString; diff --git a/src/data/route.cpp b/src/data/route.cpp index 378906ee..b0bb5cb1 100644 --- a/src/data/route.cpp +++ b/src/data/route.cpp @@ -2,8 +2,6 @@ #include "route.h" -bool Route::_useDEM = false; - Route::Route(const RouteData &data) : _data(data) { qreal dist = 0; @@ -34,19 +32,8 @@ Graph Route::elevation() const graph.append(GraphSegment()); GraphSegment &gs = graph.last(); - for (int i = 0; i < _data.size(); i++) { - if (_data.at(i).hasElevation() && !_useDEM) - gs.append(GraphPoint(_distance.at(i), NAN, - _data.at(i).elevation())); - else { - qreal elevation = DEM::elevation(_data.at(i).coordinates()); - if (!std::isnan(elevation)) - gs.append(GraphPoint(_distance.at(i), NAN, elevation)); - else if (_data.at(i).hasElevation()) - gs.append(GraphPoint(_distance.at(i), NAN, - _data.at(i).elevation())); - } - } + for (int i = 0; i < _data.size(); i++) + gs.append(GraphPoint(_distance.at(i), NAN, _data.at(i).elevation())); return graph; } diff --git a/src/data/route.h b/src/data/route.h index 65b69265..b41c1c44 100644 --- a/src/data/route.h +++ b/src/data/route.h @@ -13,7 +13,7 @@ public: Path path() const; - const QVector &waypoints() const {return _data;} + const RouteData &data() const {return _data;} Graph elevation() const; @@ -24,13 +24,9 @@ public: bool isValid() const {return _data.size() >= 2;} - static void useDEM(bool use) {_useDEM = use;} - private: RouteData _data; QVector _distance; - - static bool _useDEM; }; #endif // ROUTE_H diff --git a/src/data/track.cpp b/src/data/track.cpp index cf3be062..080fd789 100644 --- a/src/data/track.cpp +++ b/src/data/track.cpp @@ -13,7 +13,6 @@ int Track::_pauseInterval = 10; bool Track::_outlierEliminate = true; bool Track::_useReportedSpeed = false; -bool Track::_useDEM = false; static qreal median(QVector &v) @@ -180,19 +179,8 @@ Graph Track::elevation() const for (int j = 0; j < sd.size(); j++) { if (seg.outliers.contains(j)) continue; - - if (sd.at(j).hasElevation() && !_useDEM) - gs.append(GraphPoint(seg.distance.at(j), seg.time.at(j), - sd.at(j).elevation())); - else { - qreal elevation = DEM::elevation(sd.at(j).coordinates()); - if (!std::isnan(elevation)) - gs.append(GraphPoint(seg.distance.at(j), seg.time.at(j), - elevation)); - else if (sd.at(j).hasElevation()) - gs.append(GraphPoint(seg.distance.at(j), seg.time.at(j), - sd.at(j).elevation())); - } + gs.append(GraphPoint(seg.distance.at(j), seg.time.at(j), + sd.at(j).elevation())); } ret.append(filter(gs, _elevationWindow)); diff --git a/src/data/track.h b/src/data/track.h index d185814c..9dbbfdd9 100644 --- a/src/data/track.h +++ b/src/data/track.h @@ -45,7 +45,6 @@ public: static void setOutlierElimination(bool eliminate) {_outlierEliminate = eliminate;} static void useReportedSpeed(bool use) {_useReportedSpeed = use;} - static void useDEM(bool use) {_useDEM = use;} private: struct Segment { @@ -71,7 +70,6 @@ private: static qreal _pauseSpeed; static int _pauseInterval; static bool _useReportedSpeed; - static bool _useDEM; }; #endif // TRACK_H