PDA

View Full Version : Contouring in OpenGL



rakeshthp
05-19-2013, 07:47 AM
Hi,

I Need to display contours for a given grid. The grid what I have is triangulated. I also have an algorithm for generating contours for a given range. Now one option is to use this generated contour values to display the contour lines using VBOs. I want to know whether there is more easier way to do the same using opengl shaders? I guess it is possible after reading this thread (http://www.opengl.org/discussion_boards/showthread.php/159800-Contour-algorithm). I didn't completely understand that. Is it that algorithm what I have written should be written in the shader itself?

Please guide me.

Thanks

Regards
Rakesh Patil

tonyo_au
05-20-2013, 12:06 AM
A relatively easy way is to write to a buffer the contour level of each pixel based on it's world height value as you render the terrain. Then do an edge detection algorithm on this texture buffer and overlay it on your terrain. You can also use this to display solid filled contour regions.

rakeshthp
05-20-2013, 02:17 AM
A relatively easy way is to write to a buffer the contour level of each pixel based on it's world height value as you render the terrain. Then do an edge detection algorithm on this texture buffer and overlay it on your terrain. You can also use this to display solid filled contour regions.

OMG! I am confused :confused: Well, I did understand the first half. But how can I change the number of contour lines? Will Edge detection algorithm help me in displaying 100 contour lines next time, if the current number of contour lines is say 20? I mean user is provided with an interface to change the number of contour lines. So every time the contouring must go through this procedure what you mentioned? The overlaying over terrain is not compulsory for me right now.

tonyo_au
05-20-2013, 06:32 AM
You collect the contour values for a pixel when ever you render the screen (the overhead on the shader is trival but you do need any extra texture buffer). The number of contours if effective unlimited since you simple divide the height (minus a contour base if you want) by the contour step size and store the floor of the result. If the user changes the step size you just refresh the view.

If the step is say 10 meters, any height between 0 < 10 will store 0, 10 < 20 will store 1 etc.

Now every pixel belongs to exactly 1 contour level. Using an edge detection algorithm you can draw the contours. I use a simple algorithm which gives me a contour line 2 pixels wide. I use different colours for major and minor contours.

I don't use this for contouring when different line thickness are required or contours have to be labels but you can probably extend it to work in these cases.

rakeshthp
05-22-2013, 06:22 PM
what do i do to get labels along with the contour lines? can you share ur algorithm for more reference?

Thanks

tonyo_au
05-24-2013, 01:08 AM
I brute force mine. Look at the triangle, see what contours cross it, save them - now I have poly lines and I can label along the length of the poly line. There are probably better methods but it is usually for plotting where speed is not an issue