PDA

View Full Version : Creating clipped polygon



maverick_pol
27th August 2008, 00:46
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

jacek
27th August 2008, 20:22
See QPolygon::intersected().

maverick_pol
27th August 2008, 21:26
Thanks, strange I missed that.

Kacper

maverick_pol
27th August 2008, 21:57
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

jacek
27th August 2008, 22:19
Where do you draw that polygon? Is it on canvas view?

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

maverick_pol
27th August 2008, 22:23
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

jacek
27th August 2008, 22:49
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.

maverick_pol
27th August 2008, 22:56
Yes I understand that.

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

Nothing improved.

Kacper

maverick_pol
27th August 2008, 22:59
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

jacek
27th August 2008, 23:27
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.

wysota
28th August 2008, 00:15
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.