Question

I have a problem when I draw a curve in Qt thanks to the Qwt library.

The curve drawing is fine, excepted for the fact that the last point and the first point are connected, the QwtPlot actually draws a polygon with the data I provide...

I've looked into the QwtPlotCurve settings and parameters, but couldn't find anything relevant that could fix that.

The other hint I have thanks to this thread (which sadly is unanswered) is that it has to do with the data I provide.

Currently, I'm using a circular fixed-size buffer (an std::array) to store values I poll continuously. Then, I use the member function

setRawSamples(const double* xData, const double* yData, int size);

to set my curve's data (with the pointers I get with std::array::data()). It means that the list of points to draw isn't ordered (i.e. the point which has the smallest abscissa isn't the first point in the double*).

Could it be the source of the problem ? How can I fix that and just draw a curve and not a polygon ?

Was it helpful?

Solution

A curve draws as a non-closed polygon by default. Each sample point is connected to the previous sample point in provided array (but the first sample isn't connected to the last sample). Qwt doesn't care about ordering of your points by abscissa values. For example, if you provide samples (0, 0), (0, 1), (1, 1), (1, 0), (0, 0), it will draw a rectangle. If you want to avoid self-intersections in curve, you need to provide samples ordered by abscissa.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top