PDA

View Full Version : Drawing multiple line segments



twells5
18th May 2011, 14:09
Hi All,

I am working on a project where multiple line segments need to be draw very quickly. Continually drawing a line from the end point of the previous line to a new point. There can be up to 105 of these lines and and the total amount of segments can reach up to as many as 3 million. For other reasons and features I am trying to use the QGraphicsFramework. I have tried creating the line segments using QPainterPath's. QPainterPath works fine until I get up to around 500,000 segments and then as more segments are added there is a very noticable slow down in gui performance.

I know this is a lot of line segments to be drawn, so first I am wondering if I am asking more of the graphics framework than it can handle? If not, how can I speed it up? My application receives a new batch of 105 points to process every 70ms from another thread. I have turned off auto background drawing and tried a variety of the different optimizations but as yet nothing has worked sufficiently. I am also wondering if the way the QPainterPath works is that the entire path is being redrawn everytime I add a new segment, and if so, can it be configured to only redraw the newest segment while still displaying all the previous segments instead? I am new to using both the Graphics framework and QPainterPaths...

If this is too many points too quickly for the graphics framework to handle, any suggestions on possible ways to do this most efficientlywould be very appreciated.

Thanks in advance,

tim

high_flyer
19th May 2011, 10:06
I know this is a lot of line segments to be drawn, so first I am wondering if I am asking more of the graphics framework than it can handle? If not, how can I speed it up?
QGraphicsView is made to be able to handle large number of items.
But there are operations that are costly.
For example, try turning off bounding rect calculation for your path, and collision detection, and similar operations.
Also, you could use OpenGL for the rendering, which will run the rendering on your graphic card.
http://doc.qt.nokia.com/latest/graphicsview.html#opengl-rendering

Anther issue is that your path is actually only one item, but a very complex one.
Try creating individual line items instead of a path.

twells5
19th May 2011, 16:32
Thank you for the quick response. I tried your suggest of rendering with opengl and got a pretty good performance boost, but still not quite enough for this project.
So each path is only one item....this means that each time I add a new segment to the path item the entire path with all it's previous segments are re-drawn? If so,
that is probably at the heart of the problem. If I change to drawing individual line items, can the Graphics Framework be configured so that it only draws the latest,
new segments without redrawing all the previous segments each time?

I must say that even with my current problem, I'm pretty impressed with the Graphics Framework. Currently I'm able to draw ~1 million line segments in my path
items with only a very brief delay when interacting with the gui while drawing is going on....and the framework itself seems very flexible and easy to work with....

Thanks again for your quick response...

tim

high_flyer
19th May 2011, 16:58
If I change to drawing individual line items, can the Graphics Framework be configured so that it only draws the latest,
new segments without redrawing all the previous segments each time?
This is up to you.
If you change your drawing to individual line objects, you can control when and which are drawn.

twells5
26th May 2011, 13:19
high_flyer,

I changed to drawing individual line segments using QGraphicLineItems and thought I would get a good performance boost by only updating the bounding rect for each line segment as I draw them, but I didn't get a boost as I expected. It seems like the entire line is still always updating instead of only the current segment as I had hoped. As more segments are added, gui performance gets slower and slower. I also tried modifying the cache settings and update modes but that didn't have any great effect either. This is my first attempt at using the Graphics Framework and either it is the wrong choice for this task or I am still doing something very wrong....the latter being a very real possibility given my experience level with the framework.... Any thoughts or advice you could offer would be very much appreciated.

tim

high_flyer
26th May 2011, 13:53
Its hard to say where the problem is whiteout profiling and knowing your code in detail.
You can try playing around with QGraphicsView::ViewportUpdateMode, see if this helps.
Otherwise, I'd do some profiling to identify the bottleneck, and then you can take action to correct it.

Cruz
26th May 2011, 13:58
And how about using a QPixmap? Just add the latest lines and redisplay?

twells5
3rd June 2011, 15:09
high_flyer, Cruz,

Thanks for your replies. Sorry for the delay, I have a couple of projects going on.... I've played with just about every config setting I can find including the ViewportUpdateModes but so far nothing has made any significant difference. Even though I'm using individual line segments instead of paths, it still seems like every segment is getting redrawn on every update. So eventually as more segments are added, things start to slow down and gui performance boggs down. But then as soon as all segments to be drawn are drawn (~1-2 million segments), performance returns to normal because the redrawing is no longer occuring...

Cruz, I had thought about drawing a pixmap in another thread and updating the main thread as necessary, but in addition to displaying the lines, I also need to be able to select them
individually.

The system is like a radar scope display where you have multiple tracks being updated in time with new points as things move around. But unlike a radar display which can drop off
the oldest historical points as time goes on, I have to keep all points of all tracks for the entire duration. So I can get millions of points/segments. And as I said, the tracks need to be
individually selectable.

tim

totem
3rd June 2011, 15:23
Some thought, if you use a high number of little graphics items :

- check if your segments' ::shape() and ::boundingRect() methods are returning correct values
- turn off mouse hover support if not needed
- use MinimalViewportUpdate
- try optimization flags (like DontSavePainterState) if you are sure to correctly manage all your paint() methods


maybe you could post an example reproducing the problem ?