Project

General

Profile

Plot and opengl » History » Version 2

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