Multi curves plotting issue
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:
Code:
setRawData (d_x, d_y, nCurPlotsY); //nCurPlotsY the current nb of plots
Any ideas?
Cheers,
ben
Re: Multi curves plotting issue
Quote:
...but I have some issues printing the curves, only the last one has the correct number of plots.
You mean points ?
Quote:
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
Re: Multi curves plotting issue
Quote:
Quote:
...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.
Quote:
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).
Re: Multi curves plotting issue
Without knowing your code it's hard to say what you are doing wrong.
Uwe
Re: Multi curves plotting issue
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:
Code:
class DataPlot
{
Q_OBJECT
public:
void updateCurves (); //update all curves (called by a thread)
private:
std::vector <Curve*> curves; //vector of curves
};
Definition of a curve:
Code:
class Curve
{
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
};
Interesting code in DataPlot:
Code:
//////////////////////////////////
// create a new curve
//////////////////////////////////
void
{
[...]
//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:
Code:
////////////////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////////////////
Curve::Curve (const QString& s,
int _nPoints,
s_error (false),
id (_id),
nPoints (_nPoints),
nCurPointsX (0),
nCurPointsY (0),
color (_color),
{
//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!
Re: Multi curves plotting issue
The code looks o.k. to me.
So it's time to start your debugger and to check the number of points.
Uwe