Results 1 to 11 of 11

Thread: Creating clipped polygon

  1. #1
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Creating clipped polygon

    Hi guys,

    Is there a build-in method( in QPainter, for instance) that can help to create a clipped polygon?
    I have a rect(scene rectangle) + polygon that is drawn on the scene. When the whole polygon is visible it draws background really fast, but when I zoom IN it draws very slowly;
    I have already have line clip method, which increased the speed of redrawing, but now have to get a polygon clip.

    Any idea?

    Or maybe if no clipper' like method in Qt, do you know an open source C++ code implementing polygon clipping?

    Thank you,

    Kacper
    Last edited by maverick_pol; 27th August 2008 at 01:21.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Creating clipped polygon


  3. The following user says thank you to jacek for this useful post:

    maverick_pol (27th August 2008)

  4. #3
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating clipped polygon

    Thanks, strange I missed that.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  5. #4
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating clipped polygon

    Hi,

    Ok, I have checked the QPolygonF::intersected(...) method and drawing now works....slower : )
    I have checked and calculating intersection takes a while, especially when I have tree areas(polygonF) which contain about 20 000 of points.

    When I do not clip polygons and zoom in, it looks that the clipping is done automatically and it takes about 4 sec to redraw the polygons in the scene background; When I do clipping on my own it takes even longer.

    Any idea how to speed this up?
    Thanks,

    Kacper
    Last edited by maverick_pol; 27th August 2008 at 21:05.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Creating clipped polygon

    Where do you draw that polygon? Is it on canvas view?

    You can try: QPainter::setClipRect() et al.

  7. #6
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating clipped polygon

    I have custom drawBackground for my QGraphicsScene in my QGraphicsView.
    I draw a map consisting of areas(polygons), lines + point features.
    Points, lines and even the polygons are drawn very fast within 1 sec or less, but when I zoom in so not the whole polygons(they are filled with some color) are visible, it takes about 4 sec to zoom in.

    Ok, so I suppose that the clip rect should be SceneRect() ? am I right?
    painter->setClipRect(sceneRect());

    It his case, nothing is drawn in the background; clipping is enabled.

    Kacper
    Last edited by maverick_pol; 27th August 2008 at 21:28.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Creating clipped polygon

    Quote Originally Posted by maverick_pol View Post
    Ok, so I suppose that the clip rect should be SceneRect() ? am I right?
    No, sceneRect is the whole scene. You need only the visible part.

  9. #8
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating clipped polygon

    Yes I understand that.

    I set clip rect as the part that is visible and still it works slow.

    Nothing improved.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  10. #9
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating clipped polygon

    Hi,

    I have another idea: maybe I should draw polygons different that other features.
    Maybe I should not draw a set of QPolygons, but create a pixmap of that polygons( as they are the background for other features) and when the user would zoom in, then the pixmap could be cut as a rectangle( no complex cliipping) and shown.

    Just an idea.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Creating clipped polygon

    Quote Originally Posted by maverick_pol View Post
    Maybe I should not draw a set of QPolygons, but create a pixmap of that polygons( as they are the background for other features) and when the user would zoom in, then the pixmap could be cut as a rectangle( no complex cliipping) and shown.
    This way you trade CPU for memory, if the scene isn't too big it might be worth it. Have you tried using QGLWidget as the viewport yet?

    Other solution you might thy is to divide your polygons into smaller ones and redraw only those which are visible, i.e. implement a kind of poor-man's culling, but I'm not sure about the borders --- some artifacts could appear under big zoom.

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

    Default Re: Creating clipped polygon

    My five cents:

    According to Uwe (and I believe him) clipping code in Qt sucks completely If you can, avoid clipping and rely on graphics view's indexing by dividing your polygon into smaller polygons or do your own vertex based indexing and try to use it for clipping. But it might not be worth the effort - dividing the item should be simpler and you would only do it once. You can also try those brand new caching mechanisms in graphics view, but they might be ineffective when you start zooming.

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.