Project

General

Profile

Plot and opengl » History » Version 4

Anonymous, 19/07/2016 10:15 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 3 Anonymous
<pre><code class="c">
6 1 Anonymous
 typedef struct __attribute__((packed)) dbl_str{
7
    uint64_t mant:52;
8
    uint64_t exp:11;
9
    uint64_t sign:1;
10
}dbl_str;
11
12
typedef union dbl{
13
    double dblval;
14
    uint64_t intval;
15
    dbl_str strval;
16
}dbl;
17
18
QT_CHARTS_USE_NAMESPACE
19
20
int main(int argc, char *argv[])
21
{
22
    QApplication a(argc, argv);
23
    dbl testDbl;
24
    testDbl.strval.sign=0;
25
    testDbl.strval.exp=0b01111111111;
26
    testDbl.strval.mant=0b11000011010100111111011111001110110110010001011010001;
27
    
28
29
    QVector<double> timeVector;
30
    dbl offset;
31
    offset.strval.sign=0;
32
    offset.strval.exp=0b01111111111;
33
    offset.strval.mant=0b10000000000000000000000000000000000000000000000000000;
34
    for(int i = 0; i<(1<<20);i++)
35
    {
36
        timeVector.append(offset.dblval);
37
        offset.strval.mant+=1<<(52-24);
38
    }
39
40
    QLineSeries *seriesOGL = new QLineSeries();
41
    seriesOGL->setUseOpenGL(true);
42
43
    for(int i=0;i<timeVector.count();i++)
44
    {
45
        double LUT[]={0.0,1.0,-1.0,2.0,-2.0,3.0};
46
        seriesOGL->append(timeVector.at(i), LUT[i%6]);
47
    }
48
49
    Chart *chart = new Chart();
50
    chart->legend()->hide();
51
52
    chart->addSeries(seriesOGL);
53
54
    chart->createDefaultAxes();
55
    chart->setTitle("Simple line chart example");
56
57
    ChartView *chartView = new ChartView(chart);
58
    chartView->setRenderHint(QPainter::Antialiasing);
59
60
    QMainWindow window;
61
    window.setCentralWidget(chartView);
62
    window.resize(1400, 1300);
63
    window.show();
64
    return a.exec();
65
}
66 2 Anonymous
</code></pre>
67 1 Anonymous
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 2 Anonymous
This takes place in glxyseriesdata.cpp in GLXYSeriesDataManager::setPoints : each x and y of the points are casted to floats.
79 1 Anonymous
80
The new float vector is then used by glwidget.cpp  in vertex and fragment source code called by GLWidget::paintGL