PDA

View Full Version : Graphics View: Millions of items on the scene. How to improve rendering speed?



Disperato
4th June 2009, 16:26
Hi,

I have to visualize a map of the Netherlands with millions of LineItems that represent roads. I have the feeling that Qt doesn't spend so much time figuring out what to draw, but actually drawing it takes way to long, especially when the view has to display the whole scene.
The user should be able to scroll the map and to zoom in/out. Now I thought that maybe I could implement a function that renders the map onto a pixmap and display that instead of the actual scene, until the users clicks the zoom button or something in the scene changes. But it should still be possible to click on a road and select it.

Okay, I'm pretty new to Qt. In the past two weeks I found that often some of the stuff I needed was already in some form implemented in Qt, I just had to look for it in the right place.
Does any of you have an idea how I could implement the above (or even something better)?

Thanks,

Daniel

caduel
4th June 2009, 21:25
i guess you will have to consider different levels of detail, depending on the zoo factor. e.g. if you show the whole netherlands then no roads other than the big "motorways" (whatever they are called there) will make sense to draw. otherwise you both overwhelm the user with lots of irrelevant details and your program which has to paint lots of items that maybe are below a pixel in size.

Disperato
4th June 2009, 22:50
i guess you will have to consider different levels of detail, depending on the zoo factor. e.g. if you show the whole netherlands then no roads other than the big "motorways" (whatever they are called there) will make sense to draw. otherwise you both overwhelm the user with lots of irrelevant details and your program which has to paint lots of items that maybe are below a pixel in size.

Yes, I've arrived at the same conclusion. But how would I do this? I can't add all the items to the same scene, because Qt still would have do decide for each single item if it should be drawn.
Do I need more than one scene?

lni
4th June 2009, 22:57
Yes, I've arrived at the same conclusion. But how would I do this? I can't add all the items to the same scene, because Qt still would have do decide for each single item if it should be drawn.
Do I need more than one scene?

Qt doesn't know what should be drawn and what should not be drawn in different level of detail. It is up to you what should or should not be drawn...

However, if an item's boundingRect is out of viewing area, Qt will know it and will not draw it... When viewing the whole scene in the view, you will need to decide what to skip, it is your map :)

wysota
4th June 2009, 22:59
Drawing nothing is not very expensive so as long as you don't do any painting operations (based on the level of detail as suggested) you should already gain performance. There is another trick you can do - once you zoom out, hide items from layers you know you don't have to render. This will significantly reduce the number of items that have to be taken into consideration while drawing. Also avoid drawing complex shapes in favour of simple ones. Cheat whenever you can (i.e. draw straight lines instead of curves for small/distant objects).

Disperato
8th June 2009, 16:02
Ok, this is what I did:

I sorted the roads according to their average travel time and created a QGraphicsItemGroup for each of the travel times. Now I have about 120 Groups and only show some of them, depending on the zoom level.

But scrolling on the highest levels is still very slow, even if it doesn't paint that many roads. :( It seems as if Graphics View would still look into all of those hidden groups.
Any suggestions?

wysota
8th June 2009, 22:44
Use a profiler to find a bottle neck. Right now you are just guessing.