ECG就像使用QPainter的波形绘画 [英] ECG like waveform painting using QPainter

查看:244
本文介绍了ECG就像使用QPainter的波形绘画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够读取ECG信号并使用QPainter绘制波形。但是,结果波形是通过移除第一个坐标并将新坐标作为最后一个点添加而形成的。所以这给了波浪的滚动效果。



我想知道是否有任何方法来描绘患者监护系统的运行方式(黑条运行波的长度和更新波如



你可以用一个生成器来测试它:

  class Gen:public QObject {
Q_OBJECT
public:
Gen(int f):time(0){
t.setInterval(30);
freq =(2 * 3.14159)/ f;
connect(& t,QTimer :: timeout,[&](){
qreal r = sin(time);
time = fmod(time + freq,2 * 3.14159) ;
发出newReading(r);
});
}
public slots:
void toggle(){t.isActive()? t.stop():t.start(); }
信号:
void newReading(qreal);
私人:
QTimer t;
qreal time,freq;
};






  int main(int argc,char * argv [])
{
QApplication a(argc,argv);
ECG e(0);
e.show();
Gen g(60);
QObject :: connect(& g,SIGNAL(newReading(qreal)),& e,SLOT(drawReading(qreal)));
g.toggle();
返回a.exec();
}


I am able to read ECG signals and plot the wave using QPainter. But the resulting wave is formed by removing the first coordinate and appending the new coordinates as the last point. So this gives a scrolling effect to the wave.

I wanted to know if there was any way to paint the wave like how a patient monitoring system does (a black bar running the length of the wave and updating the wave like this).

Code examples or snippets will be very helpful.Thanks.

解决方案

Here is a quick example in a few lines, far from perfect, but enough to get the idea:

class ECG : public QWidget {
    Q_OBJECT
public:
    ECG(QWidget * p) : QWidget(p), t(0), x(0), lastPoint(0,0) {
        setAttribute(Qt::WA_NoSystemBackground); // don't erase previous painting
    }

    void paintEvent(QPaintEvent *) {
        QPainter painter(this);
        painter.setPen(QPen(Qt::green, 2));
        painter.fillRect(x, 0, 60, height(), Qt::black);
        if (line.length() < 100) painter.drawLine(line); // don't draw a line accross the screen
    }

public slots:
    void drawReading(qreal reading) {
        x = t++ % width();
        QPointF newPoint(x, (reading * height() * 0.4) + (height() * 0.5));
        line = QLineF(lastPoint, newPoint);
        lastPoint = newPoint;
        update();
    }

private:
    quint32 t, x;
    QPointF lastPoint;
    QLineF line;
};

The widget will draw something similar to what you want, and as is it is set to accept readings in the range of -1.0 to 1.0.

You can test it with a generator:

class Gen : public QObject {
    Q_OBJECT
public:
    Gen(int f) : time(0) {
        t.setInterval(30);
        freq = (2 * 3.14159) / f;
        connect(&t, QTimer::timeout, [&](){
            qreal r = sin(time);
            time = fmod(time + freq, 2 * 3.14159);
            emit newReading(r);
        });
    }
public slots:
    void toggle() { t.isActive() ? t.stop() : t.start(); }
signals:
    void newReading(qreal);
private:
    QTimer t;
    qreal time, freq;
};


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    ECG e(0);
    e.show();
    Gen g(60);
    QObject::connect(&g, SIGNAL(newReading(qreal)), &e, SLOT(drawReading(qreal)));
    g.toggle();
    return a.exec();
}

这篇关于ECG就像使用QPainter的波形绘画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆