Results 1 to 9 of 9

Thread: Drawing multiple line segments

  1. #1
    Join Date
    Jul 2010
    Posts
    15
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Drawing multiple line segments

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Drawing multiple line segments

    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/graph...engl-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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jul 2010
    Posts
    15
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Drawing multiple line segments

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Drawing multiple line segments

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Jul 2010
    Posts
    15
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Drawing multiple line segments

    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

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Drawing multiple line segments

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Drawing multiple line segments

    And how about using a QPixmap? Just add the latest lines and redisplay?

  8. #8
    Join Date
    Jul 2010
    Posts
    15
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Drawing multiple line segments

    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

  9. #9
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: Drawing multiple line segments

    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 ?

Similar Threads

  1. Replies: 1
    Last Post: 6th May 2009, 16:29
  2. Drawing line on table
    By kocakden in forum Qt Programming
    Replies: 7
    Last Post: 29th April 2008, 10:50
  3. drawing an unfixed line?
    By tommy in forum Newbie
    Replies: 7
    Last Post: 26th January 2008, 18:18
  4. Line drawing in Designer
    By Doug Broadwell in forum Newbie
    Replies: 8
    Last Post: 28th March 2007, 01:02
  5. Line drawing
    By kiranraj in forum Qt Programming
    Replies: 1
    Last Post: 29th January 2007, 07:38

Tags for this Thread

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.