PDA

View Full Version : Multi curves plotting issue



fallen
4th May 2008, 15:03
Hi!

I am making a program plotting more than a curve in one QwtPlot. This program is plotting real time data and allows the user to set the size of aquisition, so the number of plots in a curve. Resizing the curves works perfectly but I have some issues printing the curves, only the last one has the correct number of plots.

For example I ask 20 points per curve and I have 3 curves. The last curve I created will print 20 points, the second will print 10 and the first will print less.
Here is the snapshot: http://www.box.net/shared/q09jvw1ycohttp://www.box.net/shared/q09jvw1yco

In the code I am regularly updating each curve before replotting in a timer:

setRawData (d_x, d_y, nCurPlotsY); //nCurPlotsY the current nb of plots

Any ideas?

Cheers,

ben

Uwe
4th May 2008, 17:33
...but I have some issues printing the curves, only the last one has the correct number of plots.
You mean points ?


For example I ask 20 points per curve and I have 3 curves. The last curve I created will print 20 points, the second will print 10 and the first will print less. Here is the snapshot: ...

Showing 3 curves - one with 20 points, the second with 10 and the third with less.

So what exactly is the problem ?

Uwe

fallen
4th May 2008, 17:59
...but I have some issues printing the curves, only the last one has the correct number of plots.
You mean points ?
Yeah of course... sorry for the mistake.


For example I ask 20 points per curve and I have 3 curves. The last curve I created will print 20 points, the second will print 10 and the first will print less.
So I want 20 points on each curve.
Each curve is really attached to the plot with the same number of points, but doesn't show those points (except the last curve created).

Uwe
5th May 2008, 07:27
Without knowing your code it's hard to say what you are doing wrong.

Uwe

fallen
5th May 2008, 14:10
Ok here is the code concerning the creation and modifications of the curves, I tried to extract the most important parts.

Definition of the plot:


class DataPlot
: public QwtPlot
{
Q_OBJECT

public:
void newCurve (QString, QString); //create a new curve
void updateCurves (); //update all curves (called by a thread)

private:
std::vector <Curve*> curves; //vector of curves
};


Definition of a curve:


class Curve
: public QwtPlotCurve, QWidget
{
public:
void updaterX (Message&); //update X values
void updaterY (Message&); //update Y values

void updateNPoints (int); //update nb of points
void reattach (); //reattach with the correct nb of points

private:

int nPoints; //nb of points asked

int nCurPointsX; //current nb of values on X called in a thread
int nCurPointsY; //current nb of values on Y called in a thread

double d_x[MAX_PLOT_SIZE]; //values on X
double d_y[MAX_PLOT_SIZE]; //values on Y

QColor color; //curve color
QwtSymbol symbol; //curve symbol
};



Interesting code in DataPlot:

//////////////////////////////////
// create a new curve
//////////////////////////////////
void
DataPlot::newCurve (QString _varX,
QString _varY)
{
[...]
//create a new curve
curves.push_back (new Curve (_name, robot,
nbCurves++, col,
nbPlots, this));

//attach the new curve to the plot
curves.back ()->attach (this);
curves.back ()->setPen (col);
[...]
}

//////////////////////////////////
// update the curves
//////////////////////////////////
void
DataPlot::updateCurves()
{
[...]
//for each curve
for (unsigned int i=0; i<curves.size (); i++)
{
[...]
//reattach the curve with an updated number of points
curves[i]->reattach (this);
}

// update the display
replot ();
}


Interesting code in Curve:


////////////////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////////////////
Curve::Curve (const QString& s,
QColor _color,
int _nPoints,
QWidget* _parent) :
QwtPlotCurve (s),
QWidget (_parent),
s_error (false),
id (_id),
nPoints (_nPoints),
nCurPointsX (0),
nCurPointsY (0),
color (_color),
symbol (QwtSymbol::Cross,
QBrush (),
QPen (_color),
QSize (5,5))
{
//initiate values to 0
for (int i = 0; i< MAX_PLOT_SIZE; i++)
{
d_x[i] = 0;
d_y[i] = 0;
}

setSymbol (symbol);
}

////////////////////////////////////////////////////////////
// updates Y values
////////////////////////////////////////////////////////////
void
Curve::updaterY (Message &msg)
{
//when we receive a correct message
if (msg.value->type == DATA_DOUBLE)
{
//the following code allows a fluent printing of the
//points, increasing 1 by 1 when more points are asked
//or decreasing and keeping the last points when less
//points are requiered

//if we have to decrease the size of the curve
if (nCurPointsY > nPoints)
{
for (int i = (nCurPointsY - nPoints); i <= nCurPointsY; i++)
d_y[i-(nCurPointsY - nPoints)] = d_y[i];

nCurPointsY = nPoints ;
}

//if we have to increase it
if (nCurPointsY < nPoints)
{
nCurPointsY++;
}

//move the array to left
else
{
for (int j = 1; j <= nCurPointsY; j++)
d_y[j-1] = d_y[j];
}

//add the new value in the end
if (nCurPointsY >= 0)
d_y[nCurPointsY-1] = msg.value->val;
}

////////////////////////////////////////////////////////////
// updates X values
////////////////////////////////////////////////////////////
void
Curve::updaterX (Message &msg)
{
//same with X instead of Y....
[...]
}

////////////////////////////////////////////////////////////
// reattach the curve with the correct nb of points
////////////////////////////////////////////////////////////
void
Curve::reattach ()
{
setRawData (d_x, d_y, nCurPointsY);
}



I hope this can help... thanks!

Uwe
6th May 2008, 06:47
The code looks o.k. to me.

So it's time to start your debugger and to check the number of points.

Uwe