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

Home » Public Forums » archive » Re: Texture Map problems when using IDLgrPolygon
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Texture Map problems when using IDLgrPolygon [message #80419 is a reply to message #80411] Mon, 04 June 2012 07:18 Go to previous message
Karl[1] is currently offline  Karl[1]
Messages: 79
Registered: October 2005
Member
On Sunday, June 3, 2012 9:08:46 PM UTC-6, mikrin wrote:
> Hi All, I've been trying to develop an IDL object graphics approach
> of putting image swaths onto a 2D Orthographic
> projection of the globe. It seems I've got most of it in place put
> the image that is currently texture mapped does
> not look correct. My images are bytarr's of 1354x2030. My approach
> was to texture map the image onto a IDLgrPolygon
> object. I use the known latitude and longitude grid (1354x2030) to
> convert to an xy grid. These xy grid points
> are the polygon vertices. I then normalize these to (0.0 -> 1.0) and
> use them as the texture_coords.
> The code snippet below shows the relevant part of the process,
>
> ------------------ code snippet below ----------------------
>
> ; Scale the image to a byte
> scaledImage = BytScl(image, Top=254) + 1B
> sz = size(scaledImage,/dimensions)
>
> ; Define a texture image byte array (next power of 2 larger)
> ; to hold scaledImage. This is preferable because of a vaguery
> in how
> ; a texture map is warped onto an image. If not a power of 2
> then texture
> ; mapping introduces sampling artifacts into the image
> pwr2Sz = findNextPwr2(sz)
> textureImg = bytarr(pwr2Sz[0],pwr2Sz[1])
> textureImg[0:sz[0]-1, 0:sz[1]-1] = scaledImage
>
> ;
> ; Make a pallete object for the image
> oPal = OBJ_NEW('IDLgrPalette')
> oPal->LOADCT, 33
>
> ;
> ; Use the 1354x2030 bytarr the image object. Attempt 2
> described below
> ;oImg = obj_new('IDLgrImage', scaledImage, PALETTE=oPal,
> ORDER=1)
>
> ; Or
>
> ; Use a 2048x2048 expanded bytarr the image object. Attempt 3
> described below.
> oImg = obj_new('IDLgrImage', textureImg, PALETTE=oPal, ORDER=1)
>
> ;
> ; Create the polygon vertices and texture coordinates from the
> lats lons arrays. Uses
> ; map_proj_forward to convert lat lons to x,y
> makePolyVerts, lats, lons, MAP=map, vertexes, textureCoords
>
> ;
> ; Create a polygon object to hold the texture mapped image to.
> oPoly = obj_new('IDLgrPolygon', DATA=vertexes, TEXTURE_MAP=oImg,
> $
> Texture_Coord=textureCoords, COLOR=[255,255,255])
>
> ;
> ;Add the image to the model
> oModel->add, oPoly
>
> ; Draw image
> window->draw, oView
>
> ---------------------- code snippet above --------------------
>
>
> The code snippet above where I use 'scaledImage' (a 1354x2030 bytarr)
> results in an image that is not correct. Is this due to the known
> texture mapping sampling problem when using non power of 2 arrays?
>
>
> The code snippet above where I use 'textureImg' (a 2048x2048 bytarr)
> is my attempt to follow the suggestion that texture maps work best
> when the array is a power 2 multiple. The results here actually look
> worse.
>
> Can anyone suggest how to fix this problem? Is my implementation of
> the larger 2^n array wrong?
>
> Thanks for any help, Mike

It is hard to tell because not all of the code is here, but...

I think you still have to go with the power of two size for the textures.

When you go this route, you have to normalize the texture coordinates differently and not to the [0.0, 1.0] range. It is not clear if your makePolyVerts procedure handles this.

In your case, you'll want to normalize to [0, 1354.0/2048] in x and [0, 2030.0/2048] in y. The idea is that you want to limit your texture coordinates to the "active" area of the texture.

Karl
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: avhrr data extraction
Next Topic: INTERPOLATE Function

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

Current Time: Thu Oct 09 20:44:35 PDT 2025

Total time taken to generate the page: 1.76416 seconds