Manos
Manos

Reputation: 2186

QWT: Replot without removing the previous points

I am using QWT 6 and I am trying to plot some dots every second. To do that I use the following code:

d_plot_dots->setRawSamples(_realDataPoints, _imagDataPoints, size);
plot->replot();

I want to support a hold on option, so dots from previous seconds to be still visible at the plot. One solution to this is to resize every second the arrays that hold the points, append the new values and call again the setRawSamples() and the replot(), but this solution is not memory efficient as at every seconds I have to store at least 2 * 2048 points.

Is there any, more efficient way? Thanks in advance!

Upvotes: 2

Views: 2126

Answers (2)

Manos
Manos

Reputation: 2186

The solution to that was the use of directPainter. Following the realtime example of the QWT I done the following:

First I created the helper class CurveData.

class CurveData: public QwtArraySeriesData<QPointF>
{
public:
  CurveData()
  {
  }

  virtual QRectF boundingRect() const
  {
    if ( d_boundingRect.width() < 0.0 )
      d_boundingRect = qwtBoundingRect( *this );

    return d_boundingRect;
  }


  inline void replace(double *x, double *y, int size)
  {
    if(d_samples.size() != size){
      d_samples.resize(size);
    }
    for(int i = 0; i < size; i++){
      d_samples.replace(i, QPointF(x[i], y[i]));
    }
  }


  void clear()
  {
    d_samples.clear();
    d_samples.squeeze();
    d_boundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
  }
};

And then at my plotting code:

void
PlottingClass::plotHoldOnPoints(int size)
{
   CurveData *data = static_cast<CurveData *>( d_curve->data() );
   data->replace(_realDataPoints, _imagDataPoints, size);
   d_direct_painter->drawSeries(d_curve, 0, data->size() -1);
}

And the hold on effect with minimum memory consumption is ready!

Upvotes: 2

AlexBee
AlexBee

Reputation: 368

is a simpliest way to use data containers for your data points and appending some value to them you`ll got the plot you need

something like this: in some method you accumulate data

m_vctTime.append(xTime);
m_vctValue.append(yPower);

and then

curve->setSamples(m_vctTime,m_vctValue);
curve->attach(plot);
plot->updateAxes();    
plot->replot();

Upvotes: 1

Related Questions