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.
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.
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...
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.
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)?
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.
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.
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.
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