PDA

View Full Version : Problem With Texture Wrapping [Equirectangular to Azimuthal Equidistant Projection]



felixrulz
07-25-2012, 06:36 PM
Hello all.

I have been trying to write a program to perform the named projection but am having some problems where the texture is joined. I posted a thread on this cartography site http://www.cartotalk.com/index.php?showtopic=8330 as I was having problems with mapping initially but I think my mapping is now working I just have a problem with repeating texture coordinates.

Here are some screenshots. There is just some detracting distortion where the image is joined along the date line (the edge of the image):
http://dl.dropbox.com/u/49415695/distortion.png

I think the problem problem is due to the wrapping of texture coordinates. I have tried to illustrate the problem in the figure below. The program is currently mapping from A-->B so the distorted sectors are displaying a compressed version of nearly the entire map. What should happen instead is to map from A wrapping to B (to the right). In OpenGL I think this can be achieved by enabling GL_REPEAT and simple using that B'=B+1 to get the correct texture response.
http://dl.dropbox.com/u/49415695/TextureWrappingProb.PNG

But when I added this check:

if (p_d[n].u < p_d[n-1].u)
p_d[n].u += 1;
only the problem from one of the polar aspects was fixed (and not at all from oblique aspects).

Any ideas? Here is a link to the program I have so far if it will help with diagnoses: http://dl.dropbox.com/u/49415695/Desktop5%...ery.close%5D.7z (http://dl.dropbox.com/u/49415695/Desktop5%5BAzimuthalEqui-very.close%5D.7z)
You will need the data folder with the image (and maybe some dll files I haven't included). The arrow keys control the centre of the projection, 't' toggles the texture, 'up-pg' 'dn-pg' zoom in and out.

Thanks
Felix

felixrulz
07-28-2012, 12:36 AM
I have nearly fixed the problem by searching for jumps (above some threshold) in the texture coordinates. I have made this short video to illustrate the method I have used: http://dl.dropbox.com/u/49415695/Map...Wrap%20Fix.mp4 (Video (1mb))

The only problem is that the distortion still appears but after you move the centre point around (using the arrow keys) the problem appears to vanish. Here is the new version of my program: http://dl.dropbox.com/u/49415695/Desktop6%5BEvenCloser%5D.7z

I am lost as to why this happens. If I pause the program and manually edit the centre back to the original latitude and longitude the image displays correctly.

sqrt[-1]
07-30-2012, 05:03 AM
I think your problem is that you have to duplicate the vertices along the seam so that you don't have texture coordinates that go from 0.9..0 (as you mention in the above thread link)

So instead of having tex coords that go 0.0, 0.2, 0.4, 0.6, 0.8 (when wrapping that would go back to 0.0) you need to add another set of vertices that go
0.0, 0.2, 0.4, 0.6, 0.8, 1.0 (duplicate vertex in same position as 0.0)


This thread also might be of some help to you
http://www.opengl.org/discussion_boards/showthread.php/177271-Radial-Equirectangular-environment-mapping

felixrulz
07-30-2012, 09:43 PM
;1240900']
This thread also might be of some help to you
http://www.opengl.org/discussion_boards/showthread.php/177271-Radial-Equirectangular-environment-mapping

That program looks pretty cool, fancier than anything i've written in OpenGL

I think you haven't seen my second post as it took some time before it was approved. I'm pretty sure I implemented the method you outlined (I have tried to explain in more detail in the video I made).
Hopfully someone has experiance with the problem I am now having, and/or a better way to solve the problem than the method I took.

Thanks

sqrt[-1]
07-31-2012, 05:32 AM
I would help more, but the video link is broken and the example app you posted contains no code (and the exe depends on debug dlls I don't have installed)

felixrulz
07-31-2012, 07:19 PM
;1240931'] the video link is broken
Sorry about that I'm not sure about how to edit previous posts but here is the Fixed Video Link (https://www.dropbox.com/s/si9e0pc7dycr4mg/MappingWrapFix.mp4)
[I can edit here but not others... I think these are the posts that had to be approved before they were posted]


;1240931'] the example app you posted contains no code
Yes, I will try and put code in the future. I did post code at the link in the first post link but it was limited since I was just trying to solve my initial problem with mapping.
I will post some code at the end of this post if you wanted to suggest any improvments (i'm sure there would be a better way... as I got told 'I am using old-school OpenGL'.
(I've just been doing the tuts from NeHe that look interesting)


;1240931'] and the exe depends on debug dlls I don't have installed
I have compiled the fixed program in 'release' mode. I'm not sure if this solves the problem?


Ok, fist this is the embarising bug that I found on the train this morning:

for (i=0; i<4; i++) { // FOR THE FOUR VERTICES OF QUAD.

// disk coordinates
p_d[n].x = b2[i] * cos(a2[i]) + x0;
p_d[n].y = b2[i] * sin(a2[i]) + y0;

// calcuate texture coordinates
AziCalc (lat_p, long_p, b2[i], a2[i], p_d[n].x, R);
p_d[n].u = 0.5 - longitude/PI2;
p_d[n].v = latitude/PI;

// I HAD THE TEXTURE WRAPPING CODE HERE!

n++;
}

// THE CODE WHOULD HAVE BEEN HERE!
// Wrap bad texture coordinates
getmax2(n-4, n-1, &max, &index); //get max value for last quad
getmin2(n-4, n-1, &min, &index); //get min value for last quad
while (max - min > 0.5){ // if texture coordinates too far apart
p_d[index].u += 1; //wrap coordinates
getmax2(n-4, n-1, &min, &index); //get max value for last quad
getmin2(n-4, n-1, &min, &index); //get min value for last quad
}
}


The program now works well. Here is the fixed version: Fixed version (http://dl.dropbox.com/u/49415695/Desktop7%5BWorking%5D.7z)
(I compiled this version as 'Release' as this should hopfully get rid of some dll dependencies - not sure though)

Controls:
Arrow Keys: Adjust the centre of projection
'T': toggles the texture
'F': changes filters

Here is the section of code that creates the disk: Source1.c (http://dl.dropbox.com/u/49415695/Source1.c)

Thanks for your help. You will probably think my code isn't very good but at least it is working now ;)

I was also wndering if there was a way to add '[SOLVED]' to thread title?

sqrt[-1]
07-31-2012, 11:43 PM
I don't think I helped at all, but glad you sorted it out - It ran fine.
You probably need a few more posts on these forums before you can do more things.