Results 1 to 5 of 5

Thread: Curve tracking example is very slowly

  1. #1
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    308
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Curve tracking example is very slowly

    Hi all.

    I have faced with the problem of very slow movements of "rubber band" lines when more than 3-curves are attached.
    I have implemented the code from the "qwt-6.1.3\playground\curvetracker\" example:

    Qt Code:
    1. struct compareX
    2. {
    3. inline bool operator()(const double x, const QPointF &pos) const
    4. {
    5. return (x < pos.x());
    6. }
    7. };
    8.  
    9. CurveTracker::CurveTracker(QWidget *canvas)
    10. : QwtPlotPicker(canvas)
    11. {
    12. }
    13.  
    14. QRect CurveTracker::trackerRect(const QFont &font) const
    15. {
    16. QRect r = QwtPlotPicker::trackerRect(font);
    17. // Always show the info on left-top of window.
    18. r.moveTo(0, 0);
    19. return r;
    20. }
    21.  
    22. QwtText CurveTracker::trackerTextF(const QPointF &pos) const
    23. {
    24. // Inverse iterations over all attached curves.
    25. QString info;
    26. const auto curves = plot()->itemList(QwtPlotItem::Rtti_PlotCurve);
    27. for (auto curveIt = curves.crbegin(); curveIt != curves.crend(); ++curveIt) {
    28.  
    29. // Show info only for visible curves.
    30. if (!(*curveIt)->isVisible())
    31. continue;
    32.  
    33. const QString curveInfo = curveInfoAt(static_cast<const QwtPlotCurve *>(*curveIt), pos);
    34. if (!curveInfo.isEmpty()) {
    35. if (!info.isEmpty())
    36. info += tr("<br>");
    37. info += curveInfo;
    38. }
    39. }
    40. return info;
    41. }
    42.  
    43. QString CurveTracker::curveInfoAt(const QwtPlotCurve *qwtcurve, const QPointF &pos) const
    44. {
    45. const QLineF line = curveLineAt(qwtcurve, pos.x());
    46. if (line.isNull())
    47. return QString();
    48.  
    49. const double y = line.pointAt((pos.x() - line.p1().x()) / line.dx()).y();
    50. QString info(tr("<font color=""%1"">%2</font>"));
    51. return info.arg(qwtcurve->pen().color().name()).arg(y);
    52. }
    53.  
    54. QLineF CurveTracker::curveLineAt(const QwtPlotCurve *qwtcurve, double x) const
    55. {
    56. QLineF line;
    57. const auto samplesCount = qwtcurve->dataSize();
    58. if (samplesCount >= 2) {
    59. const QRectF boundingRect = qwtcurve->boundingRect();
    60. if ((boundingRect.width() > 0)
    61. && (x >= boundingRect.left())
    62. && (x <= boundingRect.right())) {
    63.  
    64. auto lessfunc = [](const double x, const QPointF &pos) { return (x < pos.x()); };
    65. int sampleIndex = qwtUpperSampleIndex<QPointF>(*qwtcurve->data(), x, lessfunc);
    66.  
    67. if (sampleIndex == -1) {
    68. const auto lastSample = qwtcurve->sample(samplesCount - 1);
    69. if (x == lastSample.x())
    70. sampleIndex = samplesCount - 1;
    71. }
    72. if (sampleIndex > 0) {
    73. line.setP1(qwtcurve->sample(sampleIndex - 1));
    74. line.setP2(qwtcurve->sample(sampleIndex));
    75. }
    76. }
    77. }
    78. return line;
    79. }
    To copy to clipboard, switch view to plain text mode 

    And I see that if I use 3 and more curves, then the rubber band's crosshair isn't in time behind movements of the
    mouse cursor, it lags behind on speed. And with the 15-curves or more, the delay of a sight is stronger.

    I see this delay even with "pure" QwtPlotPicker...

    So, is any tricks to solve it?

    PS: Qwt6.3-multiaxes, Qt 5.7, MSVC2015x86.

    BR,
    Denis


    Added after 13 minutes:


    I found, that even this code brings to lags:

    Qt Code:
    1. QwtText CurveTracker::trackerTextF(const QPointF &pos) const
    2. {
    3. QString info;
    4. for (int i = 0; i < 15; ++i) {
    5. info += tr("<br>");
    6. info += QString::number(qrand() % 1000);
    7. }
    8. return info;
    9. }
    To copy to clipboard, switch view to plain text mode 


    Added after 11 minutes:


    UPD: Seems, that source of issue in HTML tags:

    Qt Code:
    1. QString info(tr("<font color=""%1"">%2</font>"));
    To copy to clipboard, switch view to plain text mode 

    So... seems, we need to avoid to use the trackerTextF() method.

    Seems, we need to draw the tracker's rect with all contents manually, directly in QwtPicker::drawTracker..

    Or, I am mistaken ?
    Last edited by kuzulis; 13th November 2016 at 15:05.

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

    Default Re: Curve tracking example is very slowly

    Using rich text is slow and there is nothing you can do about it, but it is not that slow to explain the effects you describe.
    The only obvious thing I can see in your code is, that you are running the text through tr ( what doesn't make any sense to me ) - maybe it does something in your context.

    I increased the curvetracker example to 10 curves and I can't see any difference.

    Qt Code:
    1. insertCurve( "Curve 3", Qt::darkCyan, points2 );
    2. insertCurve( "Curve 4", Qt::darkYellow, points2 );
    3. insertCurve( "Curve 5", Qt::darkRed, points2 );
    4. insertCurve( "Curve 6", Qt::darkRed, points2 );
    5. insertCurve( "Curve 7", Qt::darkRed, points2 );
    6. insertCurve( "Curve 8", Qt::darkRed, points2 );
    7. insertCurve( "Curve 9", Qt::darkRed, points2 );
    8. insertCurve( "Curve 1o", Qt::darkRed, points2 );
    To copy to clipboard, switch view to plain text mode 

    • Are you running on a slow piece of hardware - like the raspi ?
    • Did you build Qt in debug mode ?
    • Anything else what explains, why you are that much slower than my desktop system ( Linux, OpenSuse 12.2, bogomips : 4988.86 )



    Uwe

  3. #3
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    308
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Curve tracking example is very slowly

    Hi Uwe,

    thanks for your answer.

    Now I too use the curvetracker with this simplification:

    Qt Code:
    1. Plot::Plot( QWidget *parent ):
    2. QwtPlot( parent)
    3. {
    4. // curves
    5. for (int i = 0; i < 15; ++i) {
    6. QPolygonF points(2000);
    7. for (int p = 0; p < 2000; ++p) {
    8. points.append({ double(p), double(qrand() % 100) });
    9. }
    10.  
    11. insertCurve( tr("Curve %1").arg(i), qrand() % 255, points );
    12. }
    13.  
    14. CurveTracker* tracker = new CurveTracker( this->canvas() );
    15.  
    16. // for the demo we want the tracker to be active without
    17. // having to click on the canvas
    18. tracker->setStateMachine( new QwtPickerTrackerMachine() );
    19. tracker->setRubberBandPen( QPen( "MediumOrchid" ) );
    20. }
    21.  
    22. void Plot::insertCurve( const QString &title,
    23. const QColor &color, const QPolygonF &points )
    24. {
    25. QwtPlotCurve *curve = new QwtPlotCurve();
    26. curve->setTitle( title );
    27. curve->setPen(color),
    28. curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
    29. curve->setSamples( points );
    30. curve->attach( this );
    31. }
    To copy to clipboard, switch view to plain text mode 

    and I got same result. When I expand the plot to the whole Display width, I got lags of a crosshair from the mouse position (this depends on mouse moving speed).

    Are you running on a slow piece of hardware - like the raspi ?
    No, I use the Desktop PC with Windows 10 (64bit) + Qwt 6.3 (yes? multiaxes) + Qt 5.7.0 + MSVC2015x86

    Did you build Qt in debug mode ?
    Yes, in debug mode.

    Anything else what explains, why you are that much slower than my desktop system ( Linux, OpenSuse 12.2, bogomips : 4988.86 )
    I have Desktop i5-3470@3.2GHzx8GB RAM .

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

    Default Re: Curve tracking example is very slowly

    Quote Originally Posted by kuzulis View Post
    Yes, in debug mode.
    When Qt has been built in debug mode lots of assertions and extra tests are compiled in. AFAIR this has a significant slow down effect on text rendering.
    So the first thing I would do is to try a release version.

    Uwe

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

    kuzulis (13th November 2016)

  6. #5
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    308
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Curve tracking example is very slowly

    Yes, you are right. Using the Release mode improves the performance.
    But, anyway, If I move the mouse quickly, then crosshair lags behind, but to a lesser extent.
    But, OK, many thanks, it is enougth for me.

Similar Threads

  1. why Qt5.5.1 qDebug so slowly?
    By tiaoweiliao in forum Qt Programming
    Replies: 1
    Last Post: 16th May 2016, 09:23
  2. Replies: 1
    Last Post: 29th September 2013, 09:12
  3. Replies: 4
    Last Post: 29th April 2010, 06:11
  4. Replies: 1
    Last Post: 22nd January 2010, 14:34
  5. very slowly apps
    By swiety in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2008, 11:05

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.