PDA

View Full Version : Creating a pixmap



maverick_pol
29th September 2008, 21:11
Hi guys,

How to draw a polygon like:


QPolygonF polygon;
polygon<<QPointF(-10.0,-10.0);
polygon<<QPointF(-5.0,10.0);
polygon<<QPointF(0.0,5.0);
polygon<<QPointF(5,-10.0);
// It is important that the polygon contains negative lat/long values


Thanks,

Kacper

maverick_pol
30th September 2008, 17:35
I am drawing complex graphics scene background (containing hundreds thousands of polygons) and would like to first create a pixmap containing that filled polygons(with solid color, no edges) and then, I believe, it would redraw the background faster.

That's why I need to draw this kind of polygons.

Maybe it's very simple. Excuse me if it is trivial.

Kacper

spud
30th September 2008, 17:55
#include <QtGui>

int main()
{
QPolygonF polygon;
polygon<<QPointF(-10.0,-10.0);
polygon<<QPointF(-5.0,10.0);
polygon<<QPointF(0.0,5.0);
polygon<<QPointF(5,-10.0);

QImage image(360, 360, QImage::Format_ARGB32);
image.fill(Qt::transparent);
QPainter painter(&image);
painter.setPen(Qt::NoPen);
painter.setBrush(Qt::red);
painter.translate(180,180);
painter.drawPolygon(polygon);
image.save("test.png");
}

It works the same with QPixmap.

maverick_pol
6th October 2008, 16:06
Simple is that.

Thanks

maverick_pol
7th October 2008, 12:16
Hi,

A bit different question, also connected with pixmaps.
What if I want to draw polygons( let's say 5000) inside one pixel? Mose of the time I have to draw a lot of polygons inside 1 degree of a coordinates, so polygon points only different by 0.001. For example, drawing a polygonF:
A) -32.333 -170.555
B) -32,334 - 170.556
C) -32,534 - 170, 777

etc


Thanks

spud
8th October 2008, 18:26
I'm sorry, but what was the question? Do you want to avoid drawing the polygons when they are smaller than a pixel?

maverick_pol
8th October 2008, 19:04
THe question is:

How to avoid drawing thousands of polygon in the QGraphicsScene when in Qt 4.4.1 polygon clipping is pretty slow. I am looking for any solution that would speed up drawing of that polygons; As this polygons do not have edges and are filled with solid color, I thought about drawing them to a pixmap or any other device and then drawing pixmap in the background what would no involve polygon clipping.

Do you have any ideas, how to do this ?

Most of the polygons coordinates are inside one degreee, like:
-32.544
-32.543
-32 634
-32 533;
etc.

Thank you for any help, I apologize if the problem is trivial.

Kacper

spud
8th October 2008, 19:17
I definitely wouldn't say the problem is trivial.
You could reimplement QGraphicsPolygonItem:: paint in a subclass and check QStyleOptionGraphicsItem:: levelOfDetail and then decide whether to call the base implementaion or drawing a simpler shape(or none at all).

See 40000 chips (http://doc.trolltech.com/4.4/demos-chip-chip-cpp.html)

maverick_pol
8th October 2008, 19:24
Good ideas, but I am almost sure it will not help.
It would if I was working mostly with items, but the background/foreground drawing is the issue.
Just to add sth, I do not draw QGraphicsPolygonItem, but use painter for the background to draw polygons: (painter->drawPolygon(...)). etc.

Polygon clipping is slow, and this is the week point of drawing. I am also thinking about moving clipping calculation to another thread; this might help. But these are just ideas.


Any other ideas, anyone?

Kacper

spud
8th October 2008, 19:38
Which begs the question: Why don't you use items for drawing the background(a map I assume).
The only other alternative I can think of is preprocessing the polygons, sort of like mipmapping (http://en.wikipedia.org/wiki/Mipmap). Then you would have a differently complex for each zoom level.

maverick_pol
8th October 2008, 20:27
I have a lot of things being drawn in the foreground/background/item layer.
I just have an idea of doing sth like this;
When the library is being drawn for the first time (whole lib is visible) is ok. What about grabbing the viewport background to an image when whole libs is visible, and when the user zoom into the lib I can cut a part of that image and draw the needed part of the image.
Ok.... maybe it will work...


Kacper

P.S

Thank you very much spud for throwing your ideas!!!! : )

[EDITED]
The idea connected with using QPixmap to grabbing the viewport() is naive.
If you have a lot of items and the order of drawing different elements is important it is not the best idea. Too complicated to achieve the result.