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
|