Results 1 to 11 of 11

Thread: Performance with many filled polygons on screen

  1. #1
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Performance with many filled polygons on screen

    Hi,

    I am plotting 5000 polygons, each containing 250 points. It is very slow. The program freezes several seconds whenever repaint is made.

    Any advice on how to improve the performance?

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Performance with many filled polygons on screen

    Find the bottleneck first, then fix it.

    If you want more details, provide more details yourself.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Performance with many filled polygons on screen

    Quote Originally Posted by wysota View Post
    Find the bottleneck first, then fix it.

    If you want more details, provide more details yourself.
    I have done the profiling and the cause is identified, it is in
    painter->drawPolygon( QPolygonF ), it is called 5000 times, each QPolygonF having 250 points..

    When I switch to painter->drawPolyline( QPolygonF ), it is very fast, but of course it is not what I want, because it don't fill the enclosing polygon area.

    The QBrush used for the painter is just a Qt::SolidPattern style (It is worse if I use custom QImage as the filling pattern).

    I am not sure if this information is enough. The coding itself is very simple...

  4. #4
    Join Date
    Feb 2006
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Performance with many filled polygons on screen

    Try painting it to an off-screen bitmap, then blit that bitmap to the screen. Some drivers may have bad performance with certain drawing operations, especially on X11.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Performance with many filled polygons on screen

    Do those polygons change in any way or do they remain constant all the time? How about using QGraphicsView instead of pure painter? Do you redraw all of the polygons in every paint event or only those that actually need redrawing? Do you have any optimizations in your code (like culling) or do you simply use the "painter's algorithm" (it's very far from being optimal)?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Performance with many filled polygons on screen

    Quote Originally Posted by Remenic View Post
    Try painting it to an off-screen bitmap, then blit that bitmap to the screen. Some drivers may have bad performance with certain drawing operations, especially on X11.
    That is what I am thinking now. But it needs a lot of work. In addition, the view can be zoom in and details would be lost.

    Quote Originally Posted by wysota View Post
    Do those polygons change in any way or do they remain constant all the time? How about using QGraphicsView instead of pure painter? Do you redraw all of the polygons in every paint event or only those that actually need redrawing? Do you have any optimizations in your code (like culling) or do you simply use the "painter's algorithm" (it's very far from being optimal)?
    Paint event is controlled by Qt, and redraw will be made when QGraphicsItem:aint is called. I do not do any culling so all polygons will be plotted. I am using QPainter class. How do I use QGraphicsView in replace of QPainter?

    Thanks.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Performance with many filled polygons on screen

    Quote Originally Posted by lni View Post
    Paint event is controlled by Qt, and redraw will be made when QGraphicsItem::paint is called.
    How do I use QGraphicsView in replace of QPainter?
    So are you using graphics view or not?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Performance with many filled polygons on screen

    Quote Originally Posted by wysota View Post
    So are you using graphics view or not?
    Yes, I am using QGraphicsView and QGraphicsScene. The scene contains 5000 polygons.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Performance with many filled polygons on screen

    Did you enable caching for the items? Also how did you define shape() and boundingRect() for your items? Did you make a QGLWidget the viewport of your view to enable hardware accelleration? To make things faster you can also mark the view as non-interactive, if you can afford it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Performance with many filled polygons on screen

    Quote Originally Posted by wysota View Post
    Did you enable caching for the items? Also how did you define shape() and boundingRect() for your items? Did you make a QGLWidget the viewport of your view to enable hardware accelleration? To make things faster you can also mark the view as non-interactive, if you can afford it.
    I didn't call setCacheMode so it is using NoCache. The graphics is zoomable and the xy scale can be changed interactively, so I suppose caching is not useful.

    The shape is not defined, and the bundingRect is properly computed. I don't use QGLWidget and have never used it. Does it work for both Linux and Window?

    I don't understand "mark the view as non-interactive". My graphics display is very interactive, such as zoom, scale changes, object selection, pen and brush can also be edited...

    When zoom in to small portion, it is fast because I recompute all sub-boundingRect so only render the portion of object really on screen. But not on "view all" mode.

  11. #11
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Performance with many filled polygons on screen

    Interactive means thats your QGraphicsView is read only.

    Another advice for your problem :
    if you overload the paint method of your QGraphicsItem, you will find a QStyleOptionGraphicsItem as argument

    It stores the rect that need to be repaint, according to the ViewportUpdateMode of your view
    and the lod, that is the scale factor of your scene.

    Since the painter draw all edges of yours polygons, even if reduced all to one pixel, maybe you need to simplify it before displaying it

    S.Cascio

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.