Re: Polygon filling oddities [message #26936] |
Thu, 04 October 2001 05:01  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Mark Hadfield (m.hadfield@niwa.cri.nz) writes:
> I guess POLYFILLV and IDLanROI are intended for dealing with regions of
> interest on images and it is anticipated that the vertices of the ROI will
> be in the positive quarter-plane. But I don't see any reason why they
> shouldn't be able to work with negative vertex coordinates.
>
> So is what I've found a bug or a feature? Can others reproduce my results?
> (I've been using IDL 5.4.)
I can reproduce your results. But I can also
get the PolyFillV code to work by making this
change:
p = polyfillv(0 > x < (!D.X_Size-1), 0 > y < (!D.Y_Size-1), 500, 500)
Although, I do notice a small problem in
the very corner of the image. There is always
a pixel or two that is not filled properly.
I'm not sure whether your problem is a bug
or not, but I'm sure *this* is. :-)
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: Polygon filling oddities [message #26943 is a reply to message #26936] |
Wed, 03 October 2001 18:18   |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
Hi Mark--
I can verify that your program works as you describe for the following
cases:
option = 1: IDL 5.0, 5.1, 5.2, 5,3
option = 3: 5.2, 5.3 (ROI object didn't exist in 5.1)
I can see your gripe, and the polygons should probably be clipped
rather than simply discarded completely.� The hard part will be to
convince RSI that this is so :-)
Craig
"Mark Hadfield" <m.hadfield@niwa.cri.nz> writes:
> Hello all
>
> I have been experimenting with different methods of generating images
> representing filled polygons. (My motivation comes from attempts at drawing
> filled coastlines on various devices.) I have found some oddities when using
> the POLYFILLV routine and the IDLanROI object. Before I take this issue to
> RSI tech support I thought I'd show it to the group and ask whether what I
> am doing makes sense.
>
> The procedure below (and attached) illustrates the problem. It displays a
> 500 x 500 image with a centred circle of radius 300 using several methods,
> controlled by the option argument:
>
> 0 Call POLYFILL directly to window
> 1 Use POLYFILLV to create an image then display image
> 2 Use POLYFILL to create the image in a Z buffer then display image
> 3 Create an IDLanROI object and use its ComputeMask method to create an
> image, then display image.
>
> These all seem to work and to give identical results, except perhaps for
> some minor differences around the edge of the polygon.
>
> The routine also accepts a SHIFT keyword that lets the caller shift the
> circle around on the image plane. With options 0 and 2 this works exactly as
> expected: as SHIFT is increased the circle moves to the edge of the window
> and eventually disappears. But with options 1 and 3 the results are
> unexpected: as SHIFT is made more negative the circle vanishes abruptly when
> it passes a threshold.
>
> For example "mgh_test_polyfill, 1, -143" (using POLYFILLV) produces a circle
> with its edge not quite touching the lower left corner of the image and
> "mgh_test_polyfill, 1, -144" produces a blank image. Similarly
> "mgh_test_polyfill, 3, -101" (using IDLanROI::ComputeMask) produces a circle
> with its edges touching the bottom and left sides of the image and
> "mgh_test_polyfill, 3, -101" produces a blank image.
>
> I guess POLYFILLV and IDLanROI are intended for dealing with regions of
> interest on images and it is anticipated that the vertices of the ROI will
> be in the positive quarter-plane. But I don't see any reason why they
> shouldn't be able to work with negative vertex coordinates.
>
> So is what I've found a bug or a feature? Can others reproduce my results?
> (I've been using IDL 5.4.)
>
> ---
> Mark Hadfield
> m.hadfield@niwa.cri.nz http://katipo.niwa.cri.nz/~hadfield
> National Institute for Water and Atmospheric Research
>
> ------ mgh_test_polyfill -----------
>
> ; Testing various methods of polygon filling
>
> pro mgh_test_polyfill, option, SHIFT=shift
>
> compile_opt IDL2
>
> if n_elements(option) eq 0 then option = 0
>
> if n_elements(shift) eq 0 then shift = 0
> if n_elements(shift) eq 1 then shift = [shift,shift]
>
> ; Create a window dimensioned [500,500]
>
> window, XSIZE=500, YSIZE=500
>
> ; Set up coordinates defining a circle, radius 150, centred at 250
>
> n_vert = 50
>
> angle = 2.*!pi*findgen(n_vert+1)/float(n_vert)
>
> x = 250 + 150*sin(angle)
> y = 250 + 150*cos(angle)
>
> ; Shift the circle
>
> x = x + shift[0]
> y = y + shift[1]
>
> ; Generate & display and image using different methods depending on
> option argument
>
> case option of
>
> 0: polyfill, x, y, /DEVICE
>
> 1: begin
> image = replicate(0B, 500, 500)
> p = polyfillv(x, y, 500, 500)
> if min(p) gt 0 then image[p] = 255B
> tv, image
> end
>
> 2: begin
> dname = !d.name
> set_plot, 'Z'
> device, SET_RESOLUTION=[500,500]
> erase
> polyfill, x, y, /DEVICE
> image = tvrd()
> set_plot, dname
> tv, image
> end
>
> 3: begin
> roi = obj_new('IDLanROI', x, y)
> image = roi->ComputeMask(DIMENSIONS=[500,500])
> obj_destroy, roi
> tv, image
> end
>
> endcase
>
> end
>
>
> --
> Posted from clam.niwa.cri.nz [202.36.29.1]
> via Mailgate.ORG Server - http://www.Mailgate.ORG
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
Re: Polygon filling oddities [message #27068 is a reply to message #26943] |
Thu, 04 October 2001 16:04  |
Mark Hadfield
Messages: 783 Registered: May 1995
|
Senior Member |
|
|
From: "Craig Markwardt" <craigmnet@cow.physics.wisc.edu>
> I can see your gripe, and the polygons should probably be clipped
> rather than simply discarded completely. The hard part will be to
> convince RSI that this is so :-)
Especially since the POLYFILLV documentation forbids negative vertex
coordinates...
"...The X and Y parameters are vectors that contain the subscripts of the
vertices that define the polygon in the coordinate system of the
two-dimensional Sx by Sy array. The Sx and Sy parameters define the number
of columns and rows in the array enclosing the polygon. At least three
points must be specified, and all points should lie within the limits: 0 <=
Xi < Sx and 0 <= Yi < Sy for all i."
I *did* read the documentation but I missed that bit!
On the other hand I don't see any such restriction in IDLanROI.
---
Mark Hadfield
m.hadfield@niwa.cri.nz http://katipo.niwa.cri.nz/~hadfield
National Institute for Water and Atmospheric Research
--
Posted from clam.niwa.cri.nz [202.36.29.1]
via Mailgate.ORG Server - http://www.Mailgate.ORG
|
|
|
Re: Polygon filling oddities [message #27070 is a reply to message #26936] |
Thu, 04 October 2001 14:40  |
Mark Hadfield
Messages: 783 Registered: May 1995
|
Senior Member |
|
|
From: "David Fanning" <david@dfanning.com>
> Mark Hadfield (m.hadfield@niwa.cri.nz) writes:
>
>> I guess POLYFILLV and IDLanROI are intended for dealing with regions of
>> interest on images and it is anticipated that the vertices of the ROI
will
>> be in the positive quarter-plane. But I don't see any reason why they
>> shouldn't be able to work with negative vertex coordinates.
>>
>> So is what I've found a bug or a feature? Can others reproduce my
results?
>> (I've been using IDL 5.4.)
>
> I can reproduce your results. But I can also
> get the PolyFillV code to work by making this
> change:
>
> p = polyfillv(0 > x < (!D.X_Size-1), 0 > y < (!D.Y_Size-1), 500, 500)
Two comments/questions:
1. Do you think you need !D.X_Size and !D.Y_Size in there? What has the
current graphics device got to do with it? (Not arguing just curious.)
2. Clipping x and y before calculating the filled polygon generally won't
give the same answer as clipping the polygon, at least not when the vertex
spacing is large. Eg think of replacing the circle in my example with a
triangle.
BTW I thought of another method using IDLanROI:ContainsPoints instead of
IDLanROI:ComputeMask...
4: begin
roi = obj_new('IDLanROI', x, y)
xx = rebin(findgen(500),500,500)
yy = rebin(findgen(1,500),500,500)
inside = roi->ContainsPoints(xx[*],yy[*])
obj_destroy, roi
image = bytarr(500,500)
image[where(inside)] = 255B
tv, image
end
It gives the correct results (i.e. the circle doesn't vanish abruptly) but
the CPU time increases by a factor of ~ 500 (from 0.12 to 6 seconds on my
machine).
I will raise this with RSI. I'm sure they'll call back all the IDL 5.5
CD-ROMs :-)
---
Mark Hadfield
m.hadfield@niwa.cri.nz http://katipo.niwa.cri.nz/~hadfield
National Institute for Water and Atmospheric Research
--
Posted from clam.niwa.cri.nz [202.36.29.1]
via Mailgate.ORG Server - http://www.Mailgate.ORG
|
|
|