Results 1 to 6 of 6

Thread: Multi curves plotting issue

  1. #1
    Join Date
    May 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Question Multi curves plotting issue

    Hi!

    I am making a program plotting more than a curve in one QwtPlot. This program is plotting real time data and allows the user to set the size of aquisition, so the number of plots in a curve. Resizing the curves works perfectly but I have some issues printing the curves, only the last one has the correct number of plots.

    For example I ask 20 points per curve and I have 3 curves. The last curve I created will print 20 points, the second will print 10 and the first will print less.
    Here is the snapshot: http://www.box.net/shared/q09jvw1yco

    In the code I am regularly updating each curve before replotting in a timer:
    Qt Code:
    1. setRawData (d_x, d_y, nCurPlotsY); //nCurPlotsY the current nb of plots
    To copy to clipboard, switch view to plain text mode 

    Any ideas?

    Cheers,

    ben

  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: Multi curves plotting issue

    ...but I have some issues printing the curves, only the last one has the correct number of plots.
    You mean points ?
    For example I ask 20 points per curve and I have 3 curves. The last curve I created will print 20 points, the second will print 10 and the first will print less. Here is the snapshot: ...
    Showing 3 curves - one with 20 points, the second with 10 and the third with less.

    So what exactly is the problem ?

    Uwe

  3. #3
    Join Date
    May 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Multi curves plotting issue

    ...but I have some issues printing the curves, only the last one has the correct number of plots.
    You mean points ?
    Yeah of course... sorry for the mistake.

    For example I ask 20 points per curve and I have 3 curves. The last curve I created will print 20 points, the second will print 10 and the first will print less.
    So I want 20 points on each curve.
    Each curve is really attached to the plot with the same number of points, but doesn't show those points (except the last curve created).

  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: Multi curves plotting issue

    Without knowing your code it's hard to say what you are doing wrong.

    Uwe

  5. #5
    Join Date
    May 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Multi curves plotting issue

    Ok here is the code concerning the creation and modifications of the curves, I tried to extract the most important parts.

    Definition of the plot:

    Qt Code:
    1. class DataPlot
    2. : public QwtPlot
    3. {
    4. Q_OBJECT
    5.  
    6. public:
    7. void newCurve (QString, QString); //create a new curve
    8. void updateCurves (); //update all curves (called by a thread)
    9.  
    10. private:
    11. std::vector <Curve*> curves; //vector of curves
    12. };
    To copy to clipboard, switch view to plain text mode 

    Definition of a curve:

    Qt Code:
    1. class Curve
    2. {
    3. public:
    4. void updaterX (Message&); //update X values
    5. void updaterY (Message&); //update Y values
    6.  
    7. void updateNPoints (int); //update nb of points
    8. void reattach (); //reattach with the correct nb of points
    9.  
    10. private:
    11.  
    12. int nPoints; //nb of points asked
    13.  
    14. int nCurPointsX; //current nb of values on X called in a thread
    15. int nCurPointsY; //current nb of values on Y called in a thread
    16.  
    17. double d_x[MAX_PLOT_SIZE]; //values on X
    18. double d_y[MAX_PLOT_SIZE]; //values on Y
    19.  
    20. QColor color; //curve color
    21. QwtSymbol symbol; //curve symbol
    22. };
    To copy to clipboard, switch view to plain text mode 


    Interesting code in DataPlot:
    Qt Code:
    1. //////////////////////////////////
    2. // create a new curve
    3. //////////////////////////////////
    4. void
    5. DataPlot::newCurve (QString _varX,
    6. QString _varY)
    7. {
    8. [...]
    9. //create a new curve
    10. curves.push_back (new Curve (_name, robot,
    11. nbCurves++, col,
    12. nbPlots, this));
    13.  
    14. //attach the new curve to the plot
    15. curves.back ()->attach (this);
    16. curves.back ()->setPen (col);
    17. [...]
    18. }
    19.  
    20. //////////////////////////////////
    21. // update the curves
    22. //////////////////////////////////
    23. void
    24. DataPlot::updateCurves()
    25. {
    26. [...]
    27. //for each curve
    28. for (unsigned int i=0; i<curves.size (); i++)
    29. {
    30. [...]
    31. //reattach the curve with an updated number of points
    32. curves[i]->reattach (this);
    33. }
    34.  
    35. // update the display
    36. replot ();
    37. }
    To copy to clipboard, switch view to plain text mode 

    Interesting code in Curve:

    Qt Code:
    1. ////////////////////////////////////////////////////////////
    2. // Constructor
    3. ////////////////////////////////////////////////////////////
    4. Curve::Curve (const QString& s,
    5. QColor _color,
    6. int _nPoints,
    7. QWidget* _parent) :
    8. QWidget (_parent),
    9. s_error (false),
    10. id (_id),
    11. nPoints (_nPoints),
    12. nCurPointsX (0),
    13. nCurPointsY (0),
    14. color (_color),
    15. symbol (QwtSymbol::Cross,
    16. QBrush (),
    17. QPen (_color),
    18. QSize (5,5))
    19. {
    20. //initiate values to 0
    21. for (int i = 0; i< MAX_PLOT_SIZE; i++)
    22. {
    23. d_x[i] = 0;
    24. d_y[i] = 0;
    25. }
    26.  
    27. setSymbol (symbol);
    28. }
    29.  
    30. ////////////////////////////////////////////////////////////
    31. // updates Y values
    32. ////////////////////////////////////////////////////////////
    33. void
    34. Curve::updaterY (Message &msg)
    35. {
    36. //when we receive a correct message
    37. if (msg.value->type == DATA_DOUBLE)
    38. {
    39. //the following code allows a fluent printing of the
    40. //points, increasing 1 by 1 when more points are asked
    41. //or decreasing and keeping the last points when less
    42. //points are requiered
    43.  
    44. //if we have to decrease the size of the curve
    45. if (nCurPointsY > nPoints)
    46. {
    47. for (int i = (nCurPointsY - nPoints); i <= nCurPointsY; i++)
    48. d_y[i-(nCurPointsY - nPoints)] = d_y[i];
    49.  
    50. nCurPointsY = nPoints ;
    51. }
    52.  
    53. //if we have to increase it
    54. if (nCurPointsY < nPoints)
    55. {
    56. nCurPointsY++;
    57. }
    58.  
    59. //move the array to left
    60. else
    61. {
    62. for (int j = 1; j <= nCurPointsY; j++)
    63. d_y[j-1] = d_y[j];
    64. }
    65.  
    66. //add the new value in the end
    67. if (nCurPointsY >= 0)
    68. d_y[nCurPointsY-1] = msg.value->val;
    69. }
    70.  
    71. ////////////////////////////////////////////////////////////
    72. // updates X values
    73. ////////////////////////////////////////////////////////////
    74. void
    75. Curve::updaterX (Message &msg)
    76. {
    77. //same with X instead of Y....
    78. [...]
    79. }
    80.  
    81. ////////////////////////////////////////////////////////////
    82. // reattach the curve with the correct nb of points
    83. ////////////////////////////////////////////////////////////
    84. void
    85. Curve::reattach ()
    86. {
    87. setRawData (d_x, d_y, nCurPointsY);
    88. }
    To copy to clipboard, switch view to plain text mode 


    I hope this can help... thanks!

  6. #6
    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: Multi curves plotting issue

    The code looks o.k. to me.

    So it's time to start your debugger and to check the number of points.

    Uwe

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.