1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-30 22:51:16 +01:00

Split DEM setting for data and POI + only load DEM data for visible POIs

This commit is contained in:
Martin Tůma 2019-01-22 23:01:40 +01:00
parent 98c4fb2037
commit 442f4deee2
13 changed files with 98 additions and 44 deletions

View File

@ -13,7 +13,6 @@
#include "map/gcs.h"
#include "map/pcs.h"
#include "data/dem.h"
#include "data/data.h"
#include "opengl.h"
#include "gui.h"
#include "settings.h"
@ -65,8 +64,6 @@ App::App(int &argc, char **argv) : QApplication(argc, argv)
#endif // ENABLE_HTTP2
Downloader::setTimeout(settings.value(CONNECTION_TIMEOUT_SETTING,
CONNECTION_TIMEOUT_DEFAULT).toInt());
Data::useDEMElevation(settings.value(USE_DEM_ELEVATION_SETTING,
USE_DEM_ELEVATION_DEFAULT).toBool());
settings.endGroup();
_gui = new GUI();

View File

@ -918,18 +918,24 @@ void GUI::openOptions()
SET_TRACK_OPTION(pauseSpeed, setPauseSpeed);
SET_TRACK_OPTION(pauseInterval, setPauseInterval);
SET_TRACK_OPTION(useReportedSpeed, useReportedSpeed);
SET_DATA_OPTION(useDEMElevation, useDEMElevation);
SET_DATA_OPTION(dataUseDEM, useDEM);
if (options.poiRadius != _options.poiRadius)
_poi->setRadius(options.poiRadius);
if (options.poiUseDEM != _options.poiUseDEM)
_poi->useDEM(options.poiUseDEM);
if (options.pixmapCache != _options.pixmapCache)
QPixmapCache::setCacheLimit(options.pixmapCache * 1024);
if (options.connectionTimeout != _options.connectionTimeout)
Downloader::setTimeout(options.connectionTimeout);
#ifdef ENABLE_HTTP2
if (options.enableHTTP2 != _options.enableHTTP2)
Downloader::enableHTTP2(options.enableHTTP2);
#endif // ENABLE_HTTP2
#ifdef ENABLE_HIDPI
if (options.hidpiMap != _options.hidpiMap)
_mapView->setDevicePixelRatio(devicePixelRatioF(),
@ -1762,10 +1768,12 @@ void GUI::writeSettings()
settings.setValue(PAUSE_INTERVAL_SETTING, _options.pauseInterval);
if (_options.useReportedSpeed != USE_REPORTED_SPEED_DEFAULT)
settings.setValue(USE_REPORTED_SPEED_SETTING, _options.useReportedSpeed);
if (_options.useDEMElevation != USE_DEM_ELEVATION_DEFAULT)
settings.setValue(USE_DEM_ELEVATION_SETTING, _options.useDEMElevation);
if (_options.dataUseDEM != DATA_USE_DEM_DEFAULT)
settings.setValue(DATA_USE_DEM_SETTING, _options.dataUseDEM);
if (_options.poiRadius != POI_RADIUS_DEFAULT)
settings.setValue(POI_RADIUS_SETTING, _options.poiRadius);
if (_options.poiUseDEM != POI_USE_DEM_DEFAULT)
settings.setValue(POI_USE_DEM_SETTING, _options.poiUseDEM);
if (_options.useOpenGL != USE_OPENGL_DEFAULT)
settings.setValue(USE_OPENGL_SETTING, _options.useOpenGL);
#ifdef ENABLE_HTTP2
@ -2002,12 +2010,14 @@ void GUI::readSettings()
PAUSE_SPEED_DEFAULT).toFloat();
_options.useReportedSpeed = settings.value(USE_REPORTED_SPEED_SETTING,
USE_REPORTED_SPEED_DEFAULT).toBool();
_options.useDEMElevation = settings.value(USE_DEM_ELEVATION_SETTING,
USE_DEM_ELEVATION_DEFAULT).toBool();
_options.dataUseDEM = settings.value(DATA_USE_DEM_SETTING,
DATA_USE_DEM_DEFAULT).toBool();
_options.pauseInterval = settings.value(PAUSE_INTERVAL_SETTING,
PAUSE_INTERVAL_DEFAULT).toInt();
_options.poiRadius = settings.value(POI_RADIUS_SETTING, POI_RADIUS_DEFAULT)
.toInt();
_options.poiUseDEM = settings.value(POI_USE_DEM_SETTING,
POI_USE_DEM_DEFAULT).toBool();
_options.useOpenGL = settings.value(USE_OPENGL_SETTING, USE_OPENGL_DEFAULT)
.toBool();
#ifdef ENABLE_HTTP2
@ -2082,9 +2092,10 @@ void GUI::readSettings()
Track::setPauseSpeed(_options.pauseSpeed);
Track::setPauseInterval(_options.pauseInterval);
Track::useReportedSpeed(_options.useReportedSpeed);
Data::useDEMElevation(_options.useDEMElevation);
Data::useDEM(_options.dataUseDEM);
_poi->setRadius(_options.poiRadius);
_poi->useDEM(_options.poiUseDEM);
QPixmapCache::setCacheLimit(_options.pixmapCache * 1024);

View File

@ -352,12 +352,12 @@ QWidget *OptionsDialog::createDataPage()
else
_computedSpeed->setChecked(true);
_gpsElevation = new QRadioButton(tr("GPS data"));
_demElevation = new QRadioButton(tr("DEM data"));
if (_options->useDEMElevation)
_demElevation->setChecked(true);
_dataGPSElevation = new QRadioButton(tr("GPS data"));
_dataDEMElevation = new QRadioButton(tr("DEM data"));
if (_options->dataUseDEM)
_dataDEMElevation->setChecked(true);
else
_gpsElevation->setChecked(true);
_dataGPSElevation->setChecked(true);
QWidget *sourceTab = new QWidget();
@ -387,8 +387,8 @@ QWidget *OptionsDialog::createDataPage()
QGroupBox *speedBox = new QGroupBox(tr("Speed"));
speedBox->setLayout(speedLayout);
elevationLayout->addWidget(_gpsElevation);
elevationLayout->addWidget(_demElevation);
elevationLayout->addWidget(_dataGPSElevation);
elevationLayout->addWidget(_dataDEMElevation);
QGroupBox *elevationBox = new QGroupBox(tr("Elevation"));
elevationBox->setLayout(elevationLayout);
@ -410,6 +410,13 @@ QWidget *OptionsDialog::createDataPage()
QWidget *OptionsDialog::createPOIPage()
{
_poiGPSElevation = new QRadioButton(tr("GPS data"));
_poiDEMElevation = new QRadioButton(tr("DEM data"));
if (_options->poiUseDEM)
_poiDEMElevation->setChecked(true);
else
_poiGPSElevation->setChecked(true);
_poiRadius = new QDoubleSpinBox();
_poiRadius->setSingleStep(1);
_poiRadius->setDecimals(1);
@ -424,8 +431,13 @@ QWidget *OptionsDialog::createPOIPage()
_poiRadius->setSuffix(UNIT_SPACE + tr("km"));
}
QVBoxLayout *elevationLayout = new QVBoxLayout();
elevationLayout->addWidget(_poiGPSElevation);
elevationLayout->addWidget(_poiDEMElevation);
QFormLayout *poiLayout = new QFormLayout();
poiLayout->addRow(tr("POI radius:"), _poiRadius);
poiLayout->addRow(tr("Radius:"), _poiRadius);
poiLayout->addRow(tr("Elevation:"), elevationLayout);
QWidget *poiTab = new QWidget();
poiTab->setLayout(poiLayout);
@ -644,13 +656,14 @@ void OptionsDialog::accept()
_options->pauseSpeed = pauseSpeed;
_options->pauseInterval = _pauseInterval->value();
_options->useReportedSpeed = _reportedSpeed->isChecked();
_options->useDEMElevation = _demElevation->isChecked();
_options->dataUseDEM = _dataDEMElevation->isChecked();
qreal poiRadius = (_options->units == Imperial)
? _poiRadius->value() * MIINM : (_options->units == Nautical)
? _poiRadius->value() * NMIINM : _poiRadius->value() * KMINM;
if (qAbs(poiRadius - _options->poiRadius) > 0.01)
_options->poiRadius = poiRadius;
_options->poiUseDEM = _poiDEMElevation->isChecked();
_options->useOpenGL = _useOpenGL->isChecked();
#ifdef ENABLE_HTTP2

View File

@ -48,9 +48,10 @@ struct Options {
qreal pauseSpeed;
int pauseInterval;
bool useReportedSpeed;
bool useDEMElevation;
bool dataUseDEM;
// POI
int poiRadius;
bool poiUseDEM;
// System
bool useOpenGL;
#ifdef ENABLE_HTTP2
@ -125,10 +126,12 @@ private:
QSpinBox *_pauseInterval;
QRadioButton *_computedSpeed;
QRadioButton *_reportedSpeed;
QRadioButton *_gpsElevation;
QRadioButton *_demElevation;
QRadioButton *_dataGPSElevation;
QRadioButton *_dataDEMElevation;
// POI
QDoubleSpinBox *_poiRadius;
QRadioButton *_poiGPSElevation;
QRadioButton *_poiDEMElevation;
// System
QSpinBox *_pixmapCache;
QSpinBox *_connectionTimeout;

View File

@ -126,10 +126,12 @@
#define PAUSE_INTERVAL_DEFAULT 10 /* s */
#define USE_REPORTED_SPEED_SETTING "useReportedSpeed"
#define USE_REPORTED_SPEED_DEFAULT false
#define USE_DEM_ELEVATION_SETTING "useDEMElevation"
#define USE_DEM_ELEVATION_DEFAULT false
#define DATA_USE_DEM_SETTING "dataUseDEM"
#define DATA_USE_DEM_DEFAULT false
#define POI_RADIUS_SETTING "poiRadius"
#define POI_RADIUS_DEFAULT (int)(IMPERIAL_UNITS() ? MIINM : KMINM)
#define POI_USE_DEM_SETTING "poiUseDEM"
#define POI_USE_DEM_DEFAULT false
#define USE_OPENGL_SETTING "useOpenGL"
#define USE_OPENGL_DEFAULT false
#define ENABLE_HTTP2_SETTING "enableHTTP2"

View File

@ -51,7 +51,7 @@ static QHash<QString, Parser*> parsers()
QHash<QString, Parser*> Data::_parsers = parsers();
bool Data::_useDEMElevation = false;
bool Data::_useDEM = false;
Data::~Data()
{
@ -68,7 +68,7 @@ void Data::processData()
for (int i = 0; i < _routeData.count(); i++)
_routes.append(new Route(_routeData.at(i)));
for (int i = 0; i < _waypoints.size(); i++) {
if (!_waypoints.at(i).hasElevation() || _useDEMElevation) {
if (!_waypoints.at(i).hasElevation() || _useDEM) {
qreal elevation = DEM::elevation(_waypoints.at(i).coordinates());
if (!std::isnan(elevation))
_waypoints[i].setElevation(elevation);
@ -76,7 +76,7 @@ void Data::processData()
}
}
Data::Data(const QString &fileName)
Data::Data(const QString &fileName, bool poi)
{
QFile file(fileName);
QFileInfo fi(fileName);
@ -92,7 +92,8 @@ Data::Data(const QString &fileName)
QHash<QString, Parser*>::iterator it;
if ((it = _parsers.find(fi.suffix().toLower())) != _parsers.end()) {
if (it.value()->parse(&file, _trackData, _routeData, _waypoints)) {
processData();
if (!poi)
processData();
_valid = true;
return;
} else {
@ -102,7 +103,8 @@ Data::Data(const QString &fileName)
} else {
for (it = _parsers.begin(); it != _parsers.end(); it++) {
if (it.value()->parse(&file, _trackData, _routeData, _waypoints)) {
processData();
if (!poi)
processData();
_valid = true;
return;
}
@ -148,9 +150,9 @@ QStringList Data::filter()
return filter;
}
void Data::useDEMElevation(bool use)
void Data::useDEM(bool use)
{
_useDEMElevation = use;
Route::useDEMElevation(use);
Track::useDEMElevation(use);
_useDEM = use;
Route::useDEM(use);
Track::useDEM(use);
}

View File

@ -14,7 +14,7 @@
class Data
{
public:
Data(const QString &fileName);
Data(const QString &fileName, bool poi = false);
~Data();
bool isValid() const {return _valid;}
@ -28,7 +28,7 @@ public:
static QString formats();
static QStringList filter();
static void useDEMElevation(bool use);
static void useDEM(bool use);
private:
void processData();
@ -45,7 +45,7 @@ private:
QList<RouteData> _routeData;
static QHash<QString, Parser*> _parsers;
static bool _useDEMElevation;
static bool _useDEM;
};
#endif // DATA_H

View File

@ -3,6 +3,7 @@
#include "common/rectc.h"
#include "common/greatcircle.h"
#include "data.h"
#include "dem.h"
#include "poi.h"
@ -14,7 +15,7 @@ POI::POI(QObject *parent) : QObject(parent)
bool POI::loadFile(const QString &path, bool dir)
{
Data data(path);
Data data(path, true);
FileIndex index;
index.enabled = true;
@ -107,6 +108,17 @@ void POI::search(const RectC &rect, QSet<int> &set) const
_tree.Search(min, max, cb, &set);
}
void POI::appendElevation(QList<Waypoint> &points) const
{
for (int i = 0; i < points.size(); i++) {
if (!points.at(i).hasElevation() || _useDEM) {
qreal elevation = DEM::elevation(points.at(i).coordinates());
if (!std::isnan(elevation))
points[i].setElevation(elevation);
}
}
}
QList<Waypoint> POI::points(const Path &path) const
{
QList<Waypoint> ret;
@ -137,6 +149,8 @@ QList<Waypoint> POI::points(const Path &path) const
for (it = set.constBegin(); it != set.constEnd(); ++it)
ret.append(_data.at(*it));
appendElevation(ret);
return ret;
}
@ -158,6 +172,8 @@ QList<Waypoint> POI::points(const Waypoint &point) const
for (it = set.constBegin(); it != set.constEnd(); ++it)
ret.append(_data.at(*it));
appendElevation(ret);
return ret;
}
@ -203,3 +219,10 @@ void POI::setRadius(unsigned radius)
emit pointsChanged();
}
void POI::useDEM(bool use)
{
_useDEM = use;
emit pointsChanged();
}

View File

@ -24,6 +24,7 @@ public:
unsigned radius() const {return _radius;}
void setRadius(unsigned radius);
void useDEM(bool use);
QList<Waypoint> points(const Path &path) const;
QList<Waypoint> points(const Waypoint &point) const;
@ -45,6 +46,7 @@ private:
bool loadFile(const QString &path, bool dir);
void search(const RectC &rect, QSet<int> &set) const;
void appendElevation(QList<Waypoint> &points) const;
POITree _tree;
QVector<Waypoint> _data;
@ -52,6 +54,7 @@ private:
QList<FileIndex> _indexes;
unsigned _radius;
bool _useDEM;
QString _errorString;
int _errorLine;

View File

@ -2,7 +2,7 @@
#include "route.h"
bool Route::_useDEMElevation = false;
bool Route::_useDEM = false;
Route::Route(const RouteData &data) : _data(data)
{
@ -31,7 +31,7 @@ Graph Route::elevation() const
Graph graph;
for (int i = 0; i < _data.size(); i++) {
if (_data.at(i).hasElevation() && !_useDEMElevation)
if (_data.at(i).hasElevation() && !_useDEM)
graph.append(GraphPoint(_distance.at(i), NAN,
_data.at(i).elevation()));
else {

View File

@ -24,13 +24,13 @@ public:
bool isNull() const {return (_data.count() < 2);}
static void useDEMElevation(bool use) {_useDEMElevation = use;}
static void useDEM(bool use) {_useDEM = use;}
private:
const RouteData &_data;
QVector<qreal> _distance;
static bool _useDEMElevation;
static bool _useDEM;
};
#endif // ROUTE_H

View File

@ -13,7 +13,7 @@ int Track::_pauseInterval = 10;
bool Track::_outlierEliminate = true;
bool Track::_useReportedSpeed = false;
bool Track::_useDEMElevation = false;
bool Track::_useDEM = false;
static qreal median(QVector<qreal> &v)
@ -154,7 +154,7 @@ Graph Track::elevation() const
if (_outliers.contains(i))
continue;
if (_data.at(i).hasElevation() && !_useDEMElevation)
if (_data.at(i).hasElevation() && !_useDEM)
raw.append(GraphPoint(_distance.at(i), _time.at(i),
_data.at(i).elevation()));
else {

View File

@ -45,7 +45,7 @@ public:
static void setOutlierElimination(bool eliminate)
{_outlierEliminate = eliminate;}
static void useReportedSpeed(bool use) {_useReportedSpeed = use;}
static void useDEMElevation(bool use) {_useDEMElevation = use;}
static void useDEM(bool use) {_useDEM = use;}
private:
bool discardStopPoint(int i) const;
@ -70,7 +70,7 @@ private:
static qreal _pauseSpeed;
static int _pauseInterval;
static bool _useReportedSpeed;
static bool _useDEMElevation;
static bool _useDEM;
};
#endif // TRACK_H