0

I've programmed a simulation, which solves a few equations and draws the result in an OpenGL window. The simulation evolves with time continuously. I would like to add points dynamically. I'm using some code like the following:

QwtPlot* plot = new...;
QwtPlotCurve* plotdata = new...;
QVector<QPoint> data = getData();
plotdata->setSamples(data);

This gets the plot to reset all the points. Can I just simply add points?

Thanks for any efforts :-)


If there's no way ever to do it, I'd love to hear that. Just tell me, please!

The Quantum Physicist
  • 24,987
  • 19
  • 103
  • 189

2 Answers2

0

How about using a QTimer with an adjustable interval with a QSpinBox?

    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(updatePlot()));
    timer->start(5000); //adjust from GUI with timer->setInterval(newValue)


    ...

    void updatePlot(){
        // QSettings initialized somewhere
        int maxSamples = settings.value("plot/maxSamples", 100).toInt();
        QVector<QPoint> data = getData(maxSamples);  // get this many samples
        plotdata->setSamples(data);

    }
dschulz
  • 4,666
  • 1
  • 31
  • 31
  • Isn't this gonna just replot the whole plot again and again? my program would plot like 50 points per second, i.e., every new point needs 20 ms more or less...! It doesn't have to be that fast, but conceptually, the simulation has a lot of points to plot with time, and I expect an accumulation of 20000 points before having to use a FIFO technique to remove points when they exceed 20000. What do you think? – The Quantum Physicist Apr 21 '12 at 07:28
0

I got it. There's no way to do it in that abstract way. But one could recall the method:

void QwtPlotCurve::setRawSamples();

with a replot(), and this would be the cheapest way to do it. It doesn't involve any data copying.

Cheers :)

The Quantum Physicist
  • 24,987
  • 19
  • 103
  • 189
  • As rubenvb wrote, the example named "realtime" in Qwt shows how you can repaint only the new points of the graph with [`QwtPlotDirectPainter`](http://qwt.sourceforge.net/class_qwt_plot_direct_painter.html). – alexisdm Apr 22 '12 at 01:58