Project

General

Profile

Plot and opengl » History » Version 1

Anonymous, 19/07/2016 10:11 AM

1 1 Anonymous
h1. Plot and OpenGL in QtCharts
2
3
The following test has been used to test the limits of OpenGL :
4
5
 typedef struct __attribute__((packed)) dbl_str{
6
    uint64_t mant:52;
7
    uint64_t exp:11;
8
    uint64_t sign:1;
9
}dbl_str;
10
11
typedef union dbl{
12
    double dblval;
13
    uint64_t intval;
14
    dbl_str strval;
15
}dbl;
16
17
#define PI 3.14159265
18
19
QT_CHARTS_USE_NAMESPACE
20
21
int main(int argc, char *argv[])
22
{
23
    QApplication a(argc, argv);
24
    dbl testDbl;
25
    testDbl.strval.sign=0;
26
    testDbl.strval.exp=0b01111111111;
27
    testDbl.strval.mant=0b11000011010100111111011111001110110110010001011010001;
28
    
29
30
    QVector<double> timeVector;
31
    dbl offset;
32
    offset.strval.sign=0;
33
    offset.strval.exp=0b01111111111;
34
    offset.strval.mant=0b10000000000000000000000000000000000000000000000000000;
35
    for(int i = 0; i<(1<<20);i++)
36
    {
37
        timeVector.append(offset.dblval);
38
        offset.strval.mant+=1<<(52-24);
39
    }
40
41
    QLineSeries *seriesOGL = new QLineSeries();
42
    seriesOGL->setUseOpenGL(true);
43
44
    for(int i=0;i<timeVector.count();i++)
45
    {
46
        double LUT[]={0.0,1.0,-1.0,2.0,-2.0,3.0};
47
        seriesOGL->append(timeVector.at(i), LUT[i%6]);
48
    }
49
50
    Chart *chart = new Chart();
51
    chart->legend()->hide();
52
53
    chart->addSeries(seriesOGL);
54
55
    chart->createDefaultAxes();
56
    chart->setTitle("Simple line chart example");
57
58
    ChartView *chartView = new ChartView(chart);
59
    chartView->setRenderHint(QPainter::Antialiasing);
60
61
    QMainWindow window;
62
    window.setCentralWidget(chartView);
63
    window.resize(1400, 1300);
64
    window.show();
65
    return a.exec();
66
}
67
68
By changing this line :
69
    offset.strval.mant+=1<<(52-23); 
70
to offset.strval.mant+=1<<(52-24);
71
we observed that the plot did not take into account any changes in the double mantissa after 28 bits (52-24), 
72
i.e. some points are stacked because the plot cannot make the difference between two different abscissa values.
73
74
This corresponds to the size of the float mantissa.
75
We can then assume that the OpenGL plot uses floats.
76
77
We found the lines where the doubles are casted to floats in the QtCharts code.
78
This take place in glxyseriesdata.cpp in GLXYSeriesDataManager::setPoints : each x and y of the points are casted to floats.
79
80
The new float vector is then used by glwidget.cpp  in vertex and fragment source code called by GLWidget::paintGL