2015-10-05 01:43:48 +02:00
|
|
|
#include <QFile>
|
|
|
|
#include <QLineF>
|
|
|
|
#include "ll.h"
|
|
|
|
#include "gpx.h"
|
|
|
|
|
|
|
|
|
2015-10-12 01:12:12 +02:00
|
|
|
#define ALPHA_E 0.5
|
2015-10-05 01:43:48 +02:00
|
|
|
#define ALPHA_S 0.1
|
|
|
|
|
|
|
|
bool GPX::loadFile(const QString &fileName)
|
|
|
|
{
|
|
|
|
QFile file(fileName);
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
_data.clear();
|
|
|
|
_error.clear();
|
|
|
|
|
|
|
|
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
|
|
|
_error = qPrintable(file.errorString());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(ret = _parser.loadFile(&file, _data)))
|
|
|
|
_error = _parser.errorString();
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-12 01:12:12 +02:00
|
|
|
void GPX::elevationGraph(QVector<QPointF> &graph) const
|
2015-10-05 01:43:48 +02:00
|
|
|
{
|
|
|
|
qreal dist = 0, ds, dh, acc;
|
|
|
|
|
|
|
|
if (!_data.size())
|
2015-10-12 01:12:12 +02:00
|
|
|
return;
|
2015-10-05 01:43:48 +02:00
|
|
|
|
|
|
|
graph.append(QPointF(0, _data.at(0).elevation));
|
|
|
|
for (int i = 1; i < _data.size(); i++) {
|
|
|
|
ds = llDistance(_data.at(i).coordinates, _data.at(i-1).coordinates);
|
|
|
|
dh = _data.at(i).elevation;
|
|
|
|
dist += ds;
|
|
|
|
acc = (i == 1) ? dh : (ALPHA_E * dh) + (1.0 - ALPHA_E) * acc;
|
|
|
|
graph.append(QPointF(dist, acc));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-12 01:12:12 +02:00
|
|
|
void GPX::speedGraph(QVector<QPointF> &graph) const
|
2015-10-05 01:43:48 +02:00
|
|
|
{
|
|
|
|
qreal dist = 0, v, ds, dt, acc;
|
|
|
|
|
|
|
|
if (!_data.size())
|
2015-10-12 01:12:12 +02:00
|
|
|
return;
|
2015-10-05 01:43:48 +02:00
|
|
|
|
|
|
|
graph.append(QPointF(0, 0));
|
|
|
|
for (int i = 1; i < _data.size(); i++) {
|
|
|
|
ds = llDistance(_data.at(i).coordinates, _data.at(i-1).coordinates);
|
|
|
|
dt = _data.at(i-1).timestamp.msecsTo(_data.at(i).timestamp) / 1000.0;
|
2015-10-12 01:12:12 +02:00
|
|
|
if (dt == 0)
|
|
|
|
continue;
|
2015-10-05 01:43:48 +02:00
|
|
|
dist += ds;
|
|
|
|
v = ds / dt;
|
|
|
|
acc = (i == 1) ? v : (ALPHA_S * v) + (1.0 - ALPHA_S) * acc;
|
|
|
|
graph.append(QPointF(dist, acc));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-12 01:12:12 +02:00
|
|
|
void GPX::track(QVector<QPointF> &track) const
|
2015-10-05 01:43:48 +02:00
|
|
|
{
|
|
|
|
QPointF p;
|
|
|
|
|
|
|
|
for (int i = 0; i < _data.size(); i++) {
|
|
|
|
ll2mercator(_data.at(i).coordinates, p);
|
|
|
|
track.append(p);
|
|
|
|
}
|
|
|
|
}
|