Results 1 to 4 of 4

Thread: How to obtain values of a zoomed curve ?

  1. #1
    Join Date
    Feb 2010
    Location
    Cuba
    Posts
    35
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default 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.
    Last edited by Hogwarts; 5th June 2012 at 17:38. Reason: updated contents

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default 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:
    Qt Code:
    1. QwtPlotCurve* curve = new QwtPlotCurve();
    2. curve->setSamples( x_vector.data(), y_vector.data(), qMin( x_vector.size(), y_vector.size() ) );
    3. int idx_start = findIndex( zoomer->zoomRect().left(), curve );
    4. int idx_end = findIndex( zoomer->zoomRect().right(), curve );
    5.  
    6. QVector< double > data = x_vector.mid( idx_start, idx_end );
    7.  
    8. int findIndex( double worldX, const QwtPlotCurve& curve ) const
    9. {
    10. int idx = 0;
    11.  
    12. int low = 0;
    13. int high = curve.dataSize() - 1;
    14.  
    15. while( true )
    16. {
    17. int size = high-low;
    18. int mid = low+size/2;
    19. double mid_value = curve.sample( mid ).x();
    20.  
    21. if( size <= 1 || worldX == mid_value )
    22. {
    23. idx = mid;
    24. break;
    25. }
    26. else
    27. {
    28. if( worldX < mid_value )
    29. {
    30. high -= size/2;
    31. }
    32. else
    33. {
    34. low += size/2;
    35. }
    36. }
    37. }
    38.  
    39. return idx;
    40. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Spitfire for this useful post:

    Hogwarts (7th June 2012)

  4. #3
    Join Date
    Feb 2010
    Location
    Cuba
    Posts
    35
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default 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

  5. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default 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:
    Qt Code:
    1. int prev = idx_start-1;
    2. while( prev >= 0 && curve.sample( idx_start ) == curve.sample( prev ) )
    3. {
    4. --prev;
    5. --idx_start;
    6. }
    7.  
    8. int next = idx_end+1;
    9. while( next < curve.dataSize() && curve.sample( idx_end ) == curve.sample( next ) )
    10. {
    11. ++next;
    12. ++idx_end;
    13. }
    To copy to clipboard, switch view to plain text mode 
    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.

  6. The following user says thank you to Spitfire for this useful post:

    Hogwarts (7th June 2012)

Similar Threads

  1. Replies: 11
    Last Post: 29th May 2012, 16:00
  2. Replies: 1
    Last Post: 1st June 2011, 08:39
  3. Replies: 2
    Last Post: 14th February 2011, 14:42
  4. Replies: 4
    Last Post: 29th April 2010, 07:11
  5. Retrieve Curve values
    By nenukino in forum Qwt
    Replies: 2
    Last Post: 26th February 2008, 15:33

Tags for this Thread

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.