-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhistogramview.cpp
More file actions
63 lines (50 loc) · 1.32 KB
/
histogramview.cpp
File metadata and controls
63 lines (50 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "histogramview.h"
QT_CHARTS_USE_NAMESPACE
HistogramView::HistogramView(QWidget *parent) : QChartView(parent)
{
this->setRenderHint(QPainter::Antialiasing);
chart = new QChart();
chart->setBackgroundVisible(false);
series = new QSplineSeries();
chart->legend()->hide();
chart->addSeries(series);
chart->setMargins(QMargins());
axisX = new QValueAxis;
axisX->setTickCount(5);
axisX->setLabelFormat("%i");
QFont font;
font.setPointSize(10);
axisX->setLabelsFont( font );
axisX->setMax(255);
chart->addAxis(axisX, Qt::AlignBottom);
series->attachAxis(axisX);
axisY = new QValueAxis;
axisY->setMax(100);
axisY->hide();
chart->addAxis(axisY, Qt::AlignLeft);
series->attachAxis(axisY);
this->setChart(chart);
}
void HistogramView::setSlice(Slice *slice)
{
this->slice = slice;
}
void HistogramView::update()
{
int histogram[256];
slice->getHistogram(histogram);
series->clear();
float sum = 0.0;
for( int i = 0; i < 256; i++ ) {
sum += histogram[i];
}
const int step = 16;
for( int i = 0; i < 256; i+=step ) {
int histVal = 0;
for( int a = 0; a < step; a++ ) {
histVal += histogram[i+a];
}
*series << QPointF(i, histVal/sum * 100);
}
// chart->update();
}