forked from romixlab/cnc-vision
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linedetectordatasource.cpp
56 lines (48 loc) · 1.46 KB
/
linedetectordatasource.cpp
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
#include "linedetectordatasource.h"
#include <QDebug>
LineDetectorDataSource::LineDetectorDataSource(QObject *parent) : QObject(parent),
m_integratedSeries(nullptr), m_thresholdSeries(nullptr)
{
}
void LineDetectorDataSource::setIntegratedPlotSeries(QAbstractSeries *series)
{
QXYSeries *xySeries = static_cast<QXYSeries *>(series);
if (xySeries) {
m_integratedSeries = xySeries;
connect(xySeries, &QObject::destroyed,
this, &LineDetectorDataSource::integratedSeriesDestroyed);
}
}
void LineDetectorDataSource::setThresholdPlotSeries(QAbstractSeries *series)
{
QXYSeries *xySeries = static_cast<QXYSeries *>(series);
if (xySeries) {
m_thresholdSeries = xySeries;
}
}
void LineDetectorDataSource::updateIntegratedPlot(const QVector<float> &data)
{
if (!m_integratedSeries)
return;
float normalizedStep = 1.0f / data.size();
float x = 0.0;
QVector<QPointF> points;
for (int i = 0; i < data.size(); i++) {
points.push_back(QPointF(x, data[i]));
x += normalizedStep;
}
m_integratedSeries->replace(points);
}
void LineDetectorDataSource::drawBeamThickness(const QPointF &pt1, const QPointF &pt2)
{
if (!m_thresholdSeries)
return;
QVector<QPointF> points;
points << pt1 << pt2;
m_thresholdSeries->replace(points);
}
void LineDetectorDataSource::integratedSeriesDestroyed()
{
m_integratedSeries = nullptr;
m_thresholdSeries = nullptr;
}