[Interest] [QGV] Asynchronous painting of millions QGPathItem
Ch'Gans
chgans at gna.org
Wed Dec 7 00:05:12 CET 2016
On 6 December 2016 at 15:53, Ch'Gans <chgans at gna.org> wrote:
> Something else I had in mind, is to use QPainterPath::simplified()
> and/or QPainterPath::toFillPolygons() to paint a "far" item and use
> the "real" painter path to paint a "close" item. Basically as you zoom
> in, there are less items to draw, so you can use the true (and more
> expensive) painter path, when you zoom out, there are more items to
> draw, but you don't need the details, hence the used of the simplified
> path (a set of polygons where arcs/bezier curves are converted to
> poly-lines).
> In the same vein, you could as well transform your painter path into a
> QRegion. The idea would be to create a pixelated representation of the
> path with "big pixels", but i haven't find anything to achieve that in
> the Qt graphical API, QRegion seems to be geared toward painting
> management of QWidget, if anyone knows a way to convert a QPainterPath
> into a QRegion, please share!
> Combined with the scene's minimal render size (or something similar
> implemented manually), this could give me 4 level of details:
> - Not rendered (too small)
> - Rendered as a QRegion (small)
> - Rendered as QPolygon (small-ish)
> - Rendered as QPainterPath (not small)
>
> Thinking about this (sorry but as I read my message again and again
> before hitting 'send' I get more and more ideas!), it could be "as
> simple" as this pseudo code:
> QPainterPath path = buildPath(documentData);
> QList<QPolygonF> polygons = path.toFillPolygons();
> QList<QRectF> region = [poly.boundingRect() for poly in polygons]
So I had a quick go at it yesterday evening, and the results were
very, very encouraging!
The main difficulty is how to quantify the smallness of a shape.
I used some naive approach, based on QPainter world transform, and the
width, height and area of the bounding box.
I even pushed further, by pre-calculating the shape of the stroked
path (my scene is static, so items are never changed in any way).
The time spent painting the items was drastically reduce, and the
graphical artifacts were acceptable.
The only exception i was annoyed with, is that when a "big" visual
feature disappear because it's actually made of lot of small graphics
item.
Encouraging results!
Chris
More information about the Interest
mailing list