comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Bug in mapped polygon objects?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Bug in mapped polygon objects? [message #91905] Mon, 14 September 2015 18:52 Go to next message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
Hello,

While developing a mapping application, I found what seems to be an odd bug with fill colors for polygon objects on maps. This happens both on imaps and on Function Graphics maps - due to both of them using ipolygon. The problem only happens on some polygons, apparently due to the way they are tessellated when placed on a map projection.

This shows an example where things work as expected:

lats2=[55d0,55d0,-45d0,-45d0,35d0,35d0,-15d0,-15d0]
lons2=[15d0,65d0,75d0,25d0,-15d0,-35d0,-35d0,-15d0]
colors2=[[255,0,0],[255,0,0],[255,0,0],[255,0,0],$
[0,0,255],[0,0,255],[0,0,255],[0,0,255]]
conn2=[4,0,1,2,3,4,4,5,6,7]

imap,map_projection='equirectangular',background='cyan'
ipolygon,transpose([[lons2],[lats2]]),vert_colors=colors2,$
connectivity=conn2,/data,/visualization

However, with some polygons (in this case, straddling the 0 longitude line), the problem shows up:

lats=[55d0,55d0,-45d0,-45d0,35d0,35d0,-15d0,-15d0]
lons=[-15d0,65d0,75d0,-25d0,-15d0,-35d0,-35d0,-15d0]
colors=[[255,0,0],[255,0,0],[255,0,0],[255,0,0],$
[0,0,255],[0,0,255],[0,0,255],[0,0,255]]
conn=[4,0,1,2,3,4,4,5,6,7]

imap,map_projection='equirectangular',background='cyan'
ipolygon,transpose([[lons],[lats]]),vert_colors=colors,$
connectivity=conn,/data,/visualization

The polygons are drawn with a white fill color, instead of the specified colors.

I tracked this down to the IDLitVisPolygon::_TessellateShapes method, which at lines 540-544 (in the IDL 8.5 version) resets the colors to zero when the tessellation changes the number of vertices, causing a mismatch with the number of colors.

To get around this and make my application work, I copied the source code of that method into my own file, where I edited those 5 lines of code. My programs then compile this edited version of that method before they try to draw the polygons. If anyone is interested in seeing the edit, it is lines 117-120 of http://www.ppenteado.net/idl/pp_lib/doc/tessellateshapes_pp. html
Re: Bug in mapped polygon objects? [message #91930 is a reply to message #91905] Wed, 16 September 2015 09:15 Go to previous messageGo to next message
chris_torrence@NOSPAM is currently offline  chris_torrence@NOSPAM
Messages: 528
Registered: March 2007
Senior Member
On Monday, September 14, 2015 at 7:52:51 PM UTC-6, Paulo Penteado wrote:
> Hello,
>
> While developing a mapping application, I found what seems to be an odd bug with fill colors for polygon objects on maps. This happens both on imaps and on Function Graphics maps - due to both of them using ipolygon. The problem only happens on some polygons, apparently due to the way they are tessellated when placed on a map projection.
>
> This shows an example where things work as expected:
>
> lats2=[55d0,55d0,-45d0,-45d0,35d0,35d0,-15d0,-15d0]
> lons2=[15d0,65d0,75d0,25d0,-15d0,-35d0,-35d0,-15d0]
> colors2=[[255,0,0],[255,0,0],[255,0,0],[255,0,0],$
> [0,0,255],[0,0,255],[0,0,255],[0,0,255]]
> conn2=[4,0,1,2,3,4,4,5,6,7]
>
> imap,map_projection='equirectangular',background='cyan'
> ipolygon,transpose([[lons2],[lats2]]),vert_colors=colors2,$
> connectivity=conn2,/data,/visualization
>
> However, with some polygons (in this case, straddling the 0 longitude line), the problem shows up:
>
> lats=[55d0,55d0,-45d0,-45d0,35d0,35d0,-15d0,-15d0]
> lons=[-15d0,65d0,75d0,-25d0,-15d0,-35d0,-35d0,-15d0]
> colors=[[255,0,0],[255,0,0],[255,0,0],[255,0,0],$
> [0,0,255],[0,0,255],[0,0,255],[0,0,255]]
> conn=[4,0,1,2,3,4,4,5,6,7]
>
> imap,map_projection='equirectangular',background='cyan'
> ipolygon,transpose([[lons],[lats]]),vert_colors=colors,$
> connectivity=conn,/data,/visualization
>
> The polygons are drawn with a white fill color, instead of the specified colors.
>
> I tracked this down to the IDLitVisPolygon::_TessellateShapes method, which at lines 540-544 (in the IDL 8.5 version) resets the colors to zero when the tessellation changes the number of vertices, causing a mismatch with the number of colors.
>
> To get around this and make my application work, I copied the source code of that method into my own file, where I edited those 5 lines of code. My programs then compile this edited version of that method before they try to draw the polygons. If anyone is interested in seeing the edit, it is lines 117-120 of http://www.ppenteado.net/idl/pp_lib/doc/tessellateshapes_pp. html

Thanks Paulo,
I just incorporated a slightly-different version of your fix into the IDL code.
Cheers,
Chris
p.s. here's my code block:

if (nsubvert lt nsubcolor) then begin
; If we have fewer vertices, just keep the first nsubvert colors.
color1 = color1[*,0:nsubvert-1]
endif else if (nsubvert gt nsubcolor) then begin
; If we have more vertices, just repeat the colors.
index = LINDGEN(nsubvert) mod nsubcolor
color1 = color1[*,index]
endif
Re: Bug in mapped polygon objects? [message #91939 is a reply to message #91930] Mon, 21 September 2015 14:37 Go to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
Thanks, Chris! That fix does look better than what I wrote. When the next IDl release is out with that fix, I will add a test in my code, so that my fix only gets compiled if the IDL version is 8.5 or lower.


On Wednesday, September 16, 2015 at 9:15:09 AM UTC-7, Chris Torrence wrote:
> Thanks Paulo,
> I just incorporated a slightly-different version of your fix into the IDL code.
> Cheers,
> Chris
> p.s. here's my code block:
>
> if (nsubvert lt nsubcolor) then begin
> ; If we have fewer vertices, just keep the first nsubvert colors.
> color1 = color1[*,0:nsubvert-1]
> endif else if (nsubvert gt nsubcolor) then begin
> ; If we have more vertices, just repeat the colors.
> index = LINDGEN(nsubvert) mod nsubcolor
> color1 = color1[*,index]
> endif
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: READ IMAGE
Next Topic: To reduce an n^2 problem

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 09:09:22 PDT 2025

Total time taken to generate the page: 0.00424 seconds