How to obtain values of a zoomed curve ?
I need to obtain the values of a part of a curve, determined by a zoom.
I could achieve this by obtaining the indexes of the curve,determining the curve segment being shown, to use the sample function of QwtPlotSeriesItem and assuming that the curve values ​​were inserted in order, according to the passage of time. So far I could not do that. I know I could use the function QwtPlotZoomer::zoomRect(), and others but all efforts have been unsuccessful. I'm ussing Qwt 6.0
I know this has been asked before, but maybe in qwt 6.0 is easier to achieve this or there is another way.
Any help is welcome.
pd: sorry my english.
Re: How to obtain values of a zoomed curve ?
Assuming that data in vector is in function of time then you can easily get first and last index of vector points on the edges of visible area:
Code:
curve->setSamples( x_vector.data(), y_vector.data(), qMin( x_vector.size(), y_vector.size() ) );
int idx_start = findIndex( zoomer->zoomRect().left(), curve );
int idx_end = findIndex( zoomer->zoomRect().right(), curve );
QVector< double > data = x_vector.mid( idx_start, idx_end );
int findIndex( double worldX, const QwtPlotCurve& curve ) const
{
int idx = 0;
int low = 0;
int high = curve.dataSize() - 1;
while( true )
{
int size = high-low;
int mid = low+size/2;
double mid_value = curve.sample( mid ).x();
if( size <= 1 || worldX == mid_value )
{
idx = mid;
break;
}
else
{
if( worldX < mid_value )
{
high -= size/2;
}
else
{
low += size/2;
}
}
}
return idx;
}
Re: How to obtain values of a zoomed curve ?
First of all thanks for responding
Your fuction partially solves what I need, because it works correctly if the curve does not have points with the same x values, otherwise it is not. My curve values ​​were inserted in order, according to the passage of time, but, at the same time maybe I need to insert more than one value.
Moreover, not necessarily all points of the curve are inside of the segment determinated by the x values of the rectangle [zoomer->zoomRect() ( left() and right() fuctions )],
because it may have points above or below the zoomed rectangle. I hope to explain myself.
Actually, I want to implement a function that allows me to get all the points within the zoomed area, because in the near future I will need it, but, for the time being, I will continue assuming that the values are inserted in order, according to the passage of time.
Any help is welcome.
Thanks again for your answer
pd: Sorry my English
Re: How to obtain values of a zoomed curve ?
The function above is just a start.
I didn't account for the case when at single x vaule there's more than one y value but that can be easily remedied.
Simple validation of returned indexes would solve the issue:
Code:
int prev = idx_start-1;
while( prev >= 0 && curve.sample( idx_start ) == curve.sample( prev ) )
{
--prev;
--idx_start;
}
int next = idx_end+1;
while( next < curve.dataSize() && curve.sample( idx_end ) == curve.sample( next ) )
{
++next;
++idx_end;
}
As to your second issue.
If you want all points acroos x axis regardless if they fit on y axis in current zoom rectangle - above function can be used.
If you want points acroos x axis only if they fit on y axis in current zoom rectangle - above function can be used.
In the second case only work required on your part is to remove from the cut-out *data* segment points that overshoot upper and lower values of the zoom rectangle.