Results 1 to 5 of 5

Thread: QwtPlotCurve->sample() in Qwt 6 & qt 4.7

  1. #1
    Join Date
    Nov 2010
    Posts
    7
    Thanks
    4

    Default QwtPlotCurve->sample() in Qwt 6 & qt 4.7

    I have drawn a curve and I want to get the y-value on the curve corresponding to a given x-value.

    I am using a QwtPlot and QwtPlotCurve.

    QwtPlotCurve no longer supports

    "double y (int i) const ".

    Am I correct in thinking that this functionality has been replaced by

    "T QwtPlotSeriesItem< T >::sample ( int index ) const" ?

    When I try to use this "sample" utility, I get a "Runtime Error" :-

    int currentPosX = pos.x();
    QPointF d = curve1->sample(currentPosX);
    qreal value = d.y();

    I have assumed that "sample" returns QPointF because that's the error message I get when I tried it with a double.

    Is this the best way to get the curve value?
    Why do I get the runtime error?

    Any help you can provide will be much appreciated, thanks.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlotCurve->sample() in Qwt 6 & qt 4.7

    Quote Originally Posted by micc13 View Post
    When I try to use this "sample" utility, I get a "Runtime Error" :-

    int currentPosX = pos.x();
    QPointF d = curve1->sample(currentPosX);
    qreal value = d.y();
    QwtPlotCurve is representing a series of points and "QwtPlotCurve::sample(int index) const" returns the point at a specific index ( like an index in an array ) of this series.

    When the x-coordinates of your series corresponds to the indexes your code might be o.k. but in general a x-coordinate is not an index.

    But this is not different to Qwt 5.x, beside that you had 2 different methods for retrieving the coordinates of a point.

    Uwe

  3. #3
    Join Date
    Nov 2010
    Posts
    7
    Thanks
    4

    Default Re: QwtPlotCurve->sample() in Qwt 6 & qt 4.7

    Thanks Uwe.
    Looks like I'll have to do a bit more work to get the value I need.

    I'm implementing a vertical selection bar which the user can move to any point along the x-axis.
    Wherever the bar is positioned, I want to display the co-ordinates of the point where this vertical bar intersects the curve.

    I know the x-value (from pos.x()).
    I suppose I will need to use this value to look up my data set and find the points before and after this one, then extrapolate to find the y-value at this point.

    By the way, do you think that the runtime error happened because I tried to call "sample" with an x co-ordinate which does not correspond to one of the points used to draw the curve?

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlotCurve->sample() in Qwt 6 & qt 4.7

    Quote Originally Posted by micc13 View Post
    By the way, do you think that the runtime error happened because I tried to call "sample" with an x co-ordinate which does not correspond to one of the points used to draw the curve?
    Normally the x-coordinates have nothing to do with the size of an array. If you have 20 points indexes from 0-19 are valid. A x coordinate of f.e. 1000.0 used as index into this array will be out of bound.

    Uwe

  5. The following user says thank you to Uwe for this useful post:

    micc13 (18th November 2010)

  6. #5
    Join Date
    Nov 2010
    Posts
    7
    Thanks
    4

    Default Re: QwtPlotCurve->sample() in Qwt 6 & qt 4.7

    Ah, I get it now, thanks again Uwe.

    I am now using the following solution, which works :-

    cursorPosition= ui->analysisQwtPlot->invTransform(QwtPlot::xBottom, pos.x());
    QPointF pointOnCurve1 = curve1->sample(round(cursorPosition)-1);
    qreal value1 = pointOnCurve1.y();
    ui->positionLabel1->setText(tr("Curve 1 Time = %1 seconds, Value = %2 units").arg(round(cursorPosition)).arg(value1, 0, 'f', 2));

Similar Threads

  1. UTF-8 Issues in Sample
    By trevelyan in forum Newbie
    Replies: 6
    Last Post: 19th May 2011, 01:41
  2. Sample for Mutithreading
    By HugoHiasl in forum Qt Programming
    Replies: 19
    Last Post: 1st July 2010, 07:43
  3. Different symbol on a QwtPlotCurve
    By jomarin in forum Qwt
    Replies: 3
    Last Post: 24th March 2010, 10:27
  4. QwtPlotCurve Selection
    By WXNSNW in forum Qwt
    Replies: 1
    Last Post: 5th August 2009, 07:41
  5. set QwtPlotCurve invisible
    By gyre in forum Qwt
    Replies: 2
    Last Post: 19th December 2007, 07:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.