Page 1 of 1

Draw Polygon not positioned at top right

Posted: 2013-09-15T21:34:02-07:00
by deadpickle
I am using Magick++ 6.7.7 Q16 to try and draw a ploygon on an image. Here is the code (it is a function of a larger program):

Code: Select all

void DoublyConnectedEdgeList::MakeImage()
{
	extern const double BOUNDBOX[4];
	extern const int XPIXELS;
	extern const int YPIXELS;
	int gridWidthX;
	int gridWidthY;

	Image voronoiImage( Geometry(XPIXELS, YPIXELS), Color(MaxRGB, MaxRGB, MaxRGB, 0));
	voronoiImage.strokeColor("black");
	voronoiImage.fillColor("white");
	voronoiImage.strokeWidth(10);

	//calc pixels per grid
	gridWidthX = XPIXELS / (BOUNDBOX[2] - BOUNDBOX[0]+2);
	gridWidthY = YPIXELS / (BOUNDBOX[3] - BOUNDBOX[1]+2);

	list<Coordinate> vorCoords;
	list<Drawable> vorPolygon;

	vorCoords.push_back(Coordinate(1*gridWidthX,1*gridWidthY));
	vorCoords.push_back(Coordinate(9*gridWidthX,1*gridWidthY));
	vorCoords.push_back(Coordinate(9*gridWidthX,9*gridWidthY));
	vorCoords.push_back(Coordinate(1*gridWidthX,9*gridWidthY));
	vorCoords.push_back(Coordinate(1*gridWidthX,1*gridWidthY));
	vorPolygon.push_back(DrawablePolygon(vorCoords));
	voronoiImage.draw(vorPolygon);

	//since Magick upper left is 0,0 this will set it to a standard Cartesian
	voronoiImage.flip();

	cout << "Write Image..." << '\n';
	voronoiImage.magick("png");
	voronoiImage.write("voronoidiagram.png");
}
When I look at the image the top right of the polygon is skewed as well as the bottom left. This seems to only happen with polylines and polygons, if I draw 4 lines everything is as expected
Image

BOUNDBOX is [0,0,8,8] and YPIXELS = 480, XPIXELS = 640. I cant figure why this is happening and I hope its something someone else has had happen to them. Thanks for the help.

Re: Draw Polygon not positioned at top right

Posted: 2013-09-16T00:10:25-07:00
by Bonzo
I would try something simple like drawing the polygon without all your variables. A simple convert with hard coded positions would be the best place to and see what happens. This will prove if it is an Imagemagick problem or a problem with your code.

Re: Draw Polygon not positioned at top right

Posted: 2013-09-16T06:11:00-07:00
by deadpickle
I hardcoded the same box:

Code: Select all

vorCoords.push_back(Coordinate(64.0,48.0));
	vorCoords.push_back(Coordinate(576.0,48.0));
	vorCoords.push_back(Coordinate(576.0,432.0));
	vorCoords.push_back(Coordinate(64.0,432.0));
	vorCoords.push_back(Coordinate(64.0,48.0));
and got the same results. Which I guess does not make me insane but is still not correct. Could this be an ImageMagick issue?

Re: Draw Polygon not positioned at top right

Posted: 2013-09-16T08:22:12-07:00
by dlemstra
What happens when you don't do the flip?

Re: Draw Polygon not positioned at top right

Posted: 2013-09-16T09:48:49-07:00
by Bonzo
Probably does not help but this works for me using version 6.8.5 Q16

Code: Select all

convert -size 600x500 xc:none -fill none -stroke black -strokewidth 5 ^
-draw " polyline 64.0,48.0 576.0,48.0 576.0,432.0 64.0,432.0 64.0,48.0 " ^
result.png
This proves that Imagemagick version I used is working OK.

I suppose the only difference is all my co ordinates are on the same line in between the " " I know that the code can break sometimes if you split it over multiple lines in the wrong place.

Re: Draw Polygon not positioned at top right

Posted: 2013-09-16T11:05:40-07:00
by deadpickle
Image

not much change. Coordinate call for the point to be of type double and the call to draw is one line, so I dont think that is the issue since the method used is the same as the examples.