GraphingWindow: improve interpolation for CSV-export.
Fixes #320. Note: Interpolation is still not quite correct and may have remaining artifacts at the epsilon-T region.
This commit is contained in:
+29
-21
@@ -5,6 +5,9 @@
|
|||||||
#include "helpwindow.h"
|
#include "helpwindow.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
GraphingWindow::GraphingWindow(const QVector<CANFrame> *frames, QWidget *parent) :
|
GraphingWindow::GraphingWindow(const QVector<CANFrame> *frames, QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::GraphingWindow)
|
ui(new Ui::GraphingWindow)
|
||||||
@@ -762,15 +765,14 @@ void GraphingWindow::saveSpreadsheet()
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
QList<GraphParams>::iterator iter;
|
QList<GraphParams>::iterator iter;
|
||||||
double xMin = 10000000000000, xMax=-10000000000000;
|
double xMin = std::numeric_limits<double>::max(),
|
||||||
int maxCount = 0;
|
xMax = std::numeric_limits<double>::min();
|
||||||
int numGraphs = 0;
|
size_t maxCount = 0;
|
||||||
for (iter = graphParams.begin(); iter != graphParams.end(); ++iter)
|
size_t numGraphs = graphParams.length();
|
||||||
{
|
for (auto && graph : graphParams) {
|
||||||
if (iter->x[0] < xMin) xMin = iter->x[0];
|
xMin = std::min(xMin, graph.x[0]);
|
||||||
if (iter->x[iter->x.count() - 1] > xMax) xMax = iter->x[iter->x.count() - 1];
|
xMax = std::max(xMax, graph.x[graph.x.count() - 1]);
|
||||||
if (maxCount < iter->x.count()) maxCount = iter->x.count();
|
maxCount = std::max(maxCount, static_cast<size_t>(graph.x.count()));
|
||||||
numGraphs++;
|
|
||||||
}
|
}
|
||||||
qDebug() << "xMin: " << xMin;
|
qDebug() << "xMin: " << xMin;
|
||||||
qDebug() << "xMax: " << xMax;
|
qDebug() << "xMax: " << xMax;
|
||||||
@@ -787,22 +789,28 @@ void GraphingWindow::saveSpreadsheet()
|
|||||||
indices.reserve(numGraphs);
|
indices.reserve(numGraphs);
|
||||||
|
|
||||||
outFile->write("TimeStamp");
|
outFile->write("TimeStamp");
|
||||||
for (int zero = 0; zero < numGraphs; zero++)
|
for (auto && graph : graphParams) {
|
||||||
{
|
|
||||||
indices.append(0);
|
indices.append(0);
|
||||||
outFile->putChar(',');
|
outFile->putChar(',');
|
||||||
outFile->write(graphParams[zero].graphName.toUtf8());
|
outFile->write(graph.graphName.toUtf8());
|
||||||
}
|
}
|
||||||
outFile->write("\n");
|
outFile->write("\n");
|
||||||
|
|
||||||
for (int j = 1; j < (maxCount - 1); j++)
|
for (size_t j = 1; j < (maxCount - 1); j++)
|
||||||
{
|
{
|
||||||
currentX = xMin + (j * sliceSize);
|
currentX = xMin + (j * sliceSize);
|
||||||
qDebug() << "X: " << currentX;
|
qDebug() << "X: " << currentX;
|
||||||
outFile->write(QString::number(currentX).toUtf8());
|
outFile->write(QString::number(currentX, 'f').toUtf8());
|
||||||
for (int k = 0; k < graphParams.count(); k++)
|
for (size_t k = 0; k < numGraphs; k++)
|
||||||
{
|
{
|
||||||
value = 0.0;
|
value = 0.0;
|
||||||
|
|
||||||
|
// move cursor to last sample before currentX
|
||||||
|
while (graphParams[k].x[indices[k]+1] < currentX)
|
||||||
|
{
|
||||||
|
indices[k]++;
|
||||||
|
}
|
||||||
|
|
||||||
//five possibilities.
|
//five possibilities.
|
||||||
//1: we're at the beginning for this graph but the slice is before this graph even starts
|
//1: we're at the beginning for this graph but the slice is before this graph even starts
|
||||||
if (indices[k] == 0 && graphParams[k].x[indices[k]] > currentX)
|
if (indices[k] == 0 && graphParams[k].x[indices[k]] > currentX)
|
||||||
@@ -828,14 +836,14 @@ void GraphingWindow::saveSpreadsheet()
|
|||||||
//the two values will be indices[k] and indices[k] + 1
|
//the two values will be indices[k] and indices[k] + 1
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
double span = graphParams[k].x[indices[k] + 1] - graphParams[k].x[indices[k]];
|
// find index, where x >= currentX
|
||||||
double progress = (currentX - graphParams[k].x[indices[k]]) / span;
|
size_t cursor = indices[k];
|
||||||
value = Utility::Lerp(graphParams[k].y[indices[k]], graphParams[k].y[indices[k] + 1], progress);
|
double span = graphParams[k].x[cursor+1] - graphParams[k].x[cursor];
|
||||||
|
double progress = (currentX - graphParams[k].x[cursor]) / span;
|
||||||
|
Q_ASSERT(progress >= 0.0 && progress <= 1.0);
|
||||||
|
value = Utility::Lerp(graphParams[k].y[cursor], graphParams[k].y[cursor+1], progress);
|
||||||
qDebug() << "Span: " << span << " Prog: " << progress << " Value: " << value;
|
qDebug() << "Span: " << span << " Prog: " << progress << " Value: " << value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentX >= graphParams[k].x[indices[k]]) indices[k]++;
|
|
||||||
|
|
||||||
outFile->putChar(',');
|
outFile->putChar(',');
|
||||||
outFile->write(QString::number(value).toUtf8());
|
outFile->write(QString::number(value).toUtf8());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user