Results 1 to 18 of 18

Thread: How to draw a cruve with increasing data?

  1. #1
    Join Date
    Sep 2009
    Posts
    14
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Question How to draw a cruve with increasing data?

    Hi everyone. I have a problem of how to draw a cruve with growing data. In my application, i need to draw a curve which data is collected from AD channel. I found the "realtime_plot" example, it used the draw(from,to) method. So i use this code for reference. But in my code, it doesn't work. My code like this:
    d_data->append(x, y, size);
    d_curve->setRawData(d_data->x(), d_data->y(), d_data->count());
    canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
    d_curve->draw(d_curve->dataSize() - size, d_curve->dataSize() - 1);

    used above code, the cruve desn't show, but used replot() method, the curve can display:
    d_data->append(x, y, size);
    d_curve->setRawData(d_data->x(), d_data->y(), d_data->count());
    canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
    replot();

    so i want to ask , how to used draw(from,to) method? And i want to draw a curve as quickly as it can. QPaintEngine::PaintOutsidePaintEvent feathure is needed, but it is not supported by qt4, and how i can realize?

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

    Default Re: How to draw a cruve with increasing data?

    1) Which platform are you on ?
    2) Does the realtime example work ?

    Uwe

  3. #3
    Join Date
    Sep 2009
    Posts
    14
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to draw a cruve with increasing data?

    Quote Originally Posted by Uwe View Post
    1) Which platform are you on ?
    2) Does the realtime example work ?

    Uwe
    I use linux-2.6.13 kernel on arm9 board. Qt version is qt-core-4.3.2, and qwt is 5.20
    the realtime example can work, it can show a series points, but i want to display a curve not just points, so i edit this code and and debug it, the original code is
    if ( d_curve == NULL )
    {
    d_curve = new QwtPlotCurve("Test Curve");
    d_curve->setStyle(QwtPlotCurve::NoCurve);
    d_curve->setPaintAttribute(QwtPlotCurve::PaintFiltered);

    const QColor &c = Qt::white;
    d_curve->setSymbol(QwtSymbol(QwtSymbol::XCross,
    QBrush(c), QPen(c), QSize(5, 5)) );

    d_curve->attach(this);
    }

    and i delete "d_curve->setStyle(QwtPlotCurve::NoCurve)" and "d_curve->setSymbol(QwtSymbol(QwtSymbol::XCross, QBrush(c), QPen(c), QSize(5, 5)) )";
    it can't show any points, but when i left-click the mouse in the screen , it can show the curve. other more, when i just delete "d_curve->setStyle(QwtPlotCurve::NoCurve)" sentence, it can show points but no curve and when i left-click the mouse in the screen , the cruve is also showed.
    But in my code, no matter what i do , it can not show anything.

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

    Default Re: How to draw a cruve with increasing data?

    Quote Originally Posted by anson97209 View Post
    I use linux-2.6.13 kernel on arm9 board. Qt version is qt-core-4.3.2, and qwt is 5.20
    Qt has been renamed so often - I can't remember if qt-core was Qt Embedded or Qt X11. This is important as on X11 you can paint outside of paint events - while on Qt embedded ( and all platforms with the raster paint engine like Windows ) QwtPlotCurve::draw is implemented using internal dummy paint events.

    Also Qt 4.3 is pretty old - better upgrade if possible.
    the realtime example can work,...
    Then check all the flags that are temporarily enabled in IncrementalPlot::appendData.

    You could also have a look at the new spectrogram example in Qwt SVN trunk. Maybe this is closer to your use case ( but I'm not sure if it works with Qt 4.3 ).

    Uwe

  5. #5
    Join Date
    Sep 2009
    Posts
    14
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to draw a cruve with increasing data?

    Quote Originally Posted by Uwe View Post
    Qt has been renamed so often - I can't remember if qt-core was Qt Embedded or Qt X11. This is important as on X11 you can paint outside of paint events - while on Qt embedded ( and all platforms with the raster paint engine like Windows ) QwtPlotCurve::draw is implemented using internal dummy paint events.

    Also Qt 4.3 is pretty old - better upgrade if possible.

    Then check all the flags that are temporarily enabled in IncrementalPlot::appendData.

    You could also have a look at the new spectrogram example in Qwt SVN trunk. Maybe this is closer to your use case ( but I'm not sure if it works with Qt 4.3 ).

    Uwe
    Thank you for your answer, and i find something has change of the realtime plot example of the latest version of qwt. Maybe I should try to debug again to find a suitable way to solve the problem.

  6. #6
    Join Date
    Sep 2009
    Posts
    14
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to draw a cruve with increasing data?

    In the Incrememtalplot.cpp , the orginal code is this:
    void IncrementalPlot::appendData(double *x, double *y, int size)
    {
    if ( d_data == NULL )
    d_data = new CurveData;

    if ( d_curve == NULL )
    {
    d_curve = new QwtPlotCurve("Test Curve");
    d_curve->setStyle(QwtPlotCurve::NoCurve);
    d_curve->setPaintAttribute(QwtPlotCurve::PaintFiltered);

    const QColor &c = Qt::white;
    d_curve->setSymbol(QwtSymbol(QwtSymbol::XCross,
    QBrush(c), QPen(c), QSize(5, 5)) );

    d_curve->attach(this);
    }

    d_data->append(x, y, size);
    d_curve->setRawData(d_data->x(), d_data->y(), d_data->count());
    #ifdef __GNUC__
    #endif

    const bool cacheMode =
    canvas()->testPaintAttribute(QwtPlotCanvas::PaintCached);

    #if QT_VERSION >= 0x040000 && defined(Q_WS_X11)
    // Even if not recommended by TrollTech, Qt::WA_PaintOutsidePaintEvent
    // works on X11. This has an tremendous effect on the performance..

    canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
    #endif

    canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
    d_curve->draw(d_curve->dataSize() - size, d_curve->dataSize() - 1);
    canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, cacheMode);

    #if QT_VERSION >= 0x040000 && defined(Q_WS_X11)
    canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, false);
    #endif
    }

    and I delete all the flag, and the code like this:

    void IncrementalPlot::appendData(double *x, double *y, int size)
    {
    if ( d_data == NULL )
    d_data = new CurveData;

    if ( d_curve == NULL )
    {
    d_curve = new QwtPlotCurve("Test Curve");
    d_curve->setStyle(QwtPlotCurve::NoCurve);
    d_curve->setPaintAttribute(QwtPlotCurve::PaintFiltered);

    const QColor &c = Qt::white;
    d_curve->setSymbol(QwtSymbol(QwtSymbol::XCross,
    QBrush(c), QPen(c), QSize(5, 5)) );

    d_curve->attach(this);
    }

    d_data->append(x, y, size);
    d_curve->setRawData(d_data->x(), d_data->y(), d_data->count());

    canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
    d_curve->draw(d_curve->dataSize() - size, d_curve->dataSize() - 1);
    canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, cacheMode);

    }
    the example also can work. But in my own code , it cannot show anything except using the replot() method. I guess other files (such as Randomplot.cpp) impacted the plot?

  7. #7
    Join Date
    Sep 2009
    Posts
    14
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to draw a cruve with increasing data?

    I have find the problem. when I add zoomer class in my code, use draw() method can work. But I have another two problems:
    1 the points can display in the realtime, but the curve can not display unless I left-clicked the mouse in the canvas.
    2 when I enble the Qt::WA_PaintOutsidePaintEvent and disable QwtPlotCanvas::PaintCached, it can plot very fast, but it will print the debug information
    "QWidget:aintEngine:should no nolonger be called"
    "QPainter:begin:Paint device returned engine == 0, type:1"
    "QPainter::setClipping:Painter not active, state will be reset by begin"
    "QPainter::save:Painter not active"
    "QPainter::store:Unbalanced save/restore"

  8. #8
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to draw a cruve with increasing data?

    Qwt 5.2.0 doesn't call any QWidget::paintEngine() anymore. If you are really using it try to find out, where QWidget::paintEngine() is called ( f.e setting a breakpoint in qWarning() ).

    Uwe

  9. #9
    Join Date
    Sep 2009
    Posts
    14
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to draw a cruve with increasing data?

    Thank you!
    I want to ask the frist question, why the points can display in the realtime, but the curve can't.

  10. #10
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to draw a cruve with increasing data?

    If you want to see connecting lines between the points you need to pass the start and endpoint for these lines - not only a single point. So if you want to paint point by point you always have to add the previous point to QwtPlotCurve::draw().

    Uwe

  11. #11
    Join Date
    Sep 2009
    Posts
    14
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to draw a cruve with increasing data?

    Uwe, Thank you very much, you really help me a lot!
    Follow you tips, I just changed the code like that
    d_curve->draw(d_curve->dataSize() - 2, d_curve->dataSize() - 1);
    and the curve can display in the realtime.
    But it must disable Qt::WA_PaintOutsidePaintEvent. As a result, it plot very slowly, Can i have a method to let it plot faster ?

  12. #12
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to draw a cruve with increasing data?

    Quote Originally Posted by anson97209 View Post
    But it must disable Qt::WA_PaintOutsidePaintEvent.
    No, Qt::WA_PaintOutsidePaintEvent has nothing to do with what you are painting. But even if you have Qt::WA_PaintOutsidePaintEvent disabled you shouldn't run into the slow path, where the complete plot is repainted.

    Uwe

  13. #13
    Join Date
    Sep 2009
    Posts
    14
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to draw a cruve with increasing data?

    Quote Originally Posted by Uwe View Post
    No, Qt::WA_PaintOutsidePaintEvent has nothing to do with what you are painting. But even if you have Qt::WA_PaintOutsidePaintEvent disabled you shouldn't run into the slow path, where the complete plot is repainted.

    Uwe
    I am sorry, I didn't understand what is slow path mean? Is it mean that if I want to display the curve, the complete curve will be repainted?
    In my case:
    1. when I enable Qt::WA_PaintOutsidePaintEvent , it plot faster, but it can not display the curve in the realtime unless I left-click mouse on the canvas.
    2. when I disable Qt::WA_PaintOutsidePaintEvent , it plot slower, but it can display the curve in the realtime.
    3. when I use replot() method, it plot slowest.
    How should I do, if I want to display the curve in the realtime and it can plot faster?

  14. #14
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to draw a cruve with increasing data?

    Is it mean that if I want to display the curve, the complete curve will be repainted?
    There are 3 different ways how drawCurve might paint the curve. It depends on the abilities of your environment and how you configured the operation. On X11 you can have the fastest path on the Mac you will run into full repaints of the plot ( not only the curve ).

    1. when I enable Qt::WA_PaintOutsidePaintEvent , it plot faster, but it can not display the curve in the realtime unless I left-click mouse on the canvas.
    Painting incrementally doesn't depend on what is painted. You wrote, that the realtime example works - so it's obviously a problem in your application code.

    Uwe

  15. #15
    Join Date
    Sep 2009
    Posts
    14
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to draw a cruve with increasing data?

    Quote Originally Posted by Uwe View Post
    Painting incrementally doesn't depend on what is painted. You wrote, that the realtime example works - so it's obviously a problem in your application code.

    Uwe
    when I enable Qt::WA_PaintOutsidePaintEvent, it will run faster, but it can't display anything unless I left-clicked mouse in the canvas, it is the same in the realtime_plot example not only just in my application code.

  16. #16
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to draw a cruve with increasing data?

    Quote Originally Posted by anson97209 View Post
    when I enable Qt::WA_PaintOutsidePaintEvent, it will run faster, but it can't display anything unless I left-clicked mouse in the canvas,
    No surprise, when it doesn't paint anything.
    ... it is the same in the realtime_plot example not only just in my application code.
    I explicitely asked if it is working ...

    I checked the example with Qt 4.3 on X11 with success - so I guess you are running Qt Embedded ( I also asked you which Qt you are using ... ). On Qt Embedded Qt::WA_PaintOutsidePaintEvent is not supported and of course nothing will be painted ( clicking in the canvas triggers a repaint ).

    The strategy on platforms, where the raster paint engine is used, is that each drawCurve posts a dummy event and paints inside the paint event. You have the penalty of posting/processing the paint event, but you don't need to paint anything beside the additional points. There is no way to get around this limitation of Qt4 ( Qt3 should be faster ).

    You didn't write how many points you want to paint in which time and I have no idea how fast your arm board is. But with the realtime example you can try to find out what is possible.

    One more hint: fixing performance issues of the raster paint engine was one of the main features of Qt 4.5. If painting is too slow you could try to upgrade from Qt 4.3 ( AFAIR you might have something about 20-30%).

    Uwe

  17. #17
    Join Date
    Sep 2009
    Posts
    14
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to draw a cruve with increasing data?

    Thank you very much!

  18. #18

    Default Re: How to draw a cruve with increasing data?

    Quote Originally Posted by anson97209 View Post
    Thank you very much!
    Hi anson97209,

    I'm also trying to plot running data and have referred curveplot1, curveplot2, realtimeplot and so on example but was unable to make it up to the mark.
    Can you upload your complete plotting code or mail me to sumit@sofomo.co.in?

    Thank You.

    Regards,
    Sumit

Similar Threads

  1. data rate transfer is decreasing in TCP connection
    By navi1084 in forum Qt Programming
    Replies: 3
    Last Post: 19th June 2009, 16:15
  2. Draw New data, without erasing old ones
    By linuxdev in forum Newbie
    Replies: 11
    Last Post: 7th January 2009, 08:34
  3. Best way to display lots of data fast
    By New2QT in forum Newbie
    Replies: 4
    Last Post: 16th October 2008, 22:46
  4. Replies: 4
    Last Post: 19th October 2007, 19:47
  5. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53

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.