Results 1 to 2 of 2

Thread: limits for drawing a QwtPlotCurve

  1. #1
    Join Date
    Nov 2009
    Posts
    94
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question limits for drawing a QwtPlotCurve

    Hello,

    I'm drawing some curves onto the spectrogram and want to adapt/limit the bounds of curve to the bounds of spectrogram. As you can see in the attached image, the bound for x2 in spectrogram is 4, but the curve has bigger x2 values than 4, thus the image is not nice, because the plot should be only filled with spectrogramdata ( without grey areas) and on it there should be curves, which should respect the bounds of spectrogram. How to do the limitations?

    best regards,

    Vitali

    I set the curve data with this class:

    Qt Code:
    1. class SimpleData: public QwtData
    2. {
    3. // The x values depend on its index and the y values
    4. // can be calculated from the corresponding x value.
    5. // So we don't need to store the values.
    6. // Such an implementation is slower because every point
    7. // has to be recalculated for every replot, but it demonstrates how
    8. // QwtData can be used.
    9.  
    10. public:
    11. SimpleData( double (*b)(double), double rang1[2], double step)
    12. {
    13. constraintFunc = b;
    14. _step = step;
    15. rangeX[0]= rang1[0]; rangeX[1] = rang1[1];
    16. range = (rang1[1] - rang1[0])/step;
    17. if(range<0){
    18. range = range *(-1);
    19. }
    20. d_size = size_t(range);
    21. }
    22.  
    23. virtual QwtData *copy() const
    24. {
    25. return new SimpleData(*this);
    26. }
    27.  
    28. virtual size_t size() const
    29. {
    30. return d_size;
    31. }
    32.  
    33. virtual double x(size_t i) const
    34. {
    35. if(rangeX[0]<0){
    36. return (-(range- i) + i)/ range;
    37. }
    38. else
    39. return ((range + i) + i)/ range;
    40. }
    41.  
    42. virtual double y(size_t i) const
    43. {
    44. return (*constraintFunc)(x(i));
    45. }
    46. private:
    47. size_t d_size;
    48. double range;
    49. double _step;
    50. double (*constraintFunc)(double); // function pointer for constraint function
    51. double rangeX[2];
    52. };
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  2. #2
    Join Date
    Nov 2009
    Posts
    94
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: limits for drawing a QwtPlotCurve

    ok, I solved it myself by "if" and "else if" conditions:

    Qt Code:
    1. class SimpleData: public QwtData
    2. {
    3. // The x values depend on its index and the y values
    4. // can be calculated from the corresponding x value.
    5. // So we don't need to store the values.
    6. // Such an implementation is slower because every point
    7. // has to be recalculated for every replot, but it demonstrates how
    8. // QwtData can be used.
    9.  
    10. public:
    11. SimpleData( double (*b)(double), double rang1[2], double rang2[2], double step)
    12. {
    13. constraintFunc = b;
    14. _step = step;
    15. rangeX[0]= rang1[0]; rangeX[1] = rang1[1];
    16. rangeY[0]= rang2[0]; rangeY[1] = rang2[1];
    17. range = (rang1[1] - rang1[0])/step;
    18. if(range<0){
    19. range = range *(-1);
    20. }
    21. d_size = size_t(range);
    22. }
    23.  
    24. virtual QwtData *copy() const
    25. {
    26. return new SimpleData(*this);
    27. }
    28.  
    29. virtual size_t size() const
    30. {
    31. return d_size;
    32. }
    33.  
    34. virtual double x(size_t i) const
    35. {
    36. if(rangeX[0]<0){
    37. return (-(range- i) + i)/ range;
    38. }
    39. else
    40. return ((range + i) + i)/ range;
    41. }
    42.  
    43. virtual double y(size_t i) const
    44. {
    45. if((*constraintFunc)(x(i)) > rangeY[1]){
    46. return rangeY[1];
    47. }
    48. else if((*constraintFunc)(x(i)) < rangeY[0]){
    49. return rangeY[0];
    50. }
    51. else return (*constraintFunc)(x(i));
    52. }
    53. private:
    54. size_t d_size;
    55. double range;
    56. double _step;
    57. double (*constraintFunc)(double); // function pointer for constraint function
    58. double rangeX[2];
    59. double rangeY[2];
    60. };
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Selecting a QwtPlotCurve object.
    By mah_singh1 in forum Qwt
    Replies: 1
    Last Post: 21st April 2009, 07:12
  2. Replies: 2
    Last Post: 18th December 2008, 07:43

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.