PDA

View Full Version : Scaling too much on a graphics view



natnan
15th September 2009, 12:14
I build a huge maps with lots of polygons,texts and stuff.
Now, I'd like to be able to zoom lots of time without any limits.

To be clear I should be able to look at,let's say, a port closely on a Europe Map.
However, after some scale commands of GraphicsView, it starts to slow down and then freezes.

I'm guessing after some scaling, polygons of European lands become too large and drawing or creating them consumes too much CPU.

Is there a solution for this kind of thing in Qt (like cache mode - I tried -,x mode etc..) or do I have to find a workaround for this?

If workaround, can you suggest something? Screen will be interactive, so pixmap stuff doesn't seem to be a solution. Drawing that part of the map again is also not a complete solution, because intersecting polygons doesn't do a great job.

Thank you.

Trivial question :) : Subtracting small(doesn't matter though) polygons from huge polygons with thousands of points... This action sometimes takes several seconds,and I need to do this lots of times. Right now, I'm painting small polygons onto huge polygons but I'm not sure it's safe in the long run. Again, any workaround or fix?

yogeshgokul
15th September 2009, 12:28
See QPixmapCache and .
If I compare the functionality of your application with google maps.
Google uses manual caching, means google doesn't keeps full image in memory coz that is expensive and in a map application caching is most important feature. So keep the image in memory what is visible and very near to that. You need to unload the part of the image which is not comes withing current view port.
Good Luck !:)

natnan
15th September 2009, 12:34
The problem is I can't use QPixmap or image like google map does. I have to use QGraphicsPolygonItem kind of things because next step in my project will be making them clickable and interactive.
thanks to the graphics view, even though I scale like crazy, the image I don't see is cached(?). So, there isn't any problem with memory.

yogeshgokul
15th September 2009, 12:42
So for further enhancement can play with :

QGraphicsView::OptimizationFlags
QGraphicsView::CacheModeFlag
QGraphicsView::ViewportUpdateMode



QGraphicsView::MinimalViewportUpdate
This is proven to be best performance booster.

natnan
15th September 2009, 13:40
I see. Although those are useful boosts, that's not the solution I'm looking for.
thanks.

scascio
15th September 2009, 13:48
I am using QGraphicsView and the best optimization I have found is to write my own QGraphicsItem.

For instance, I manage multi resolution huge images, and I overloaded the paintEvent of a QGraphicsItem derived like this :


void QGraphicsItemResource::paint(QPainter * painter,
const QStyleOptionGraphicsItem * options,
QWidget *) {
painter->setClipping(true);
painter->setClipRect(options->exposedRect);
painter->drawImage(options->exposedRect, sourceImage, sourceRect);
}

The thing I want to point out is the use of QPainter::drawImage, that prevent from QPixmap copies and do the scaling automatically during the paint. So the performances are better.

And if you are not using image, but only polygons, try to enable Clipping top minimize painting operation. Another solution is to simplify the geometry according to the scale displayed defore painting the item. In all cases, you will need to implement your own QGraphicsItem.

S.Cascio