Results 1 to 6 of 6

Thread: Multi curves plotting issue

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    Default Re: Multi curves plotting issue

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

    Uwe

  2. #2
    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!

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    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
  •  
Qt is a trademark of The Qt Company.