Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Contouring in OpenGL

  1. #1
    Intern Contributor
    Join Date
    Jun 2009
    Posts
    85

    Contouring in OpenGL

    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. 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

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,106
    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.

  3. #3
    Intern Contributor
    Join Date
    Jun 2009
    Posts
    85
    Quote Originally Posted by tonyo_au View Post
    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 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.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,106
    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.

  5. #5
    Intern Contributor
    Join Date
    Jun 2009
    Posts
    85
    what do i do to get labels along with the contour lines? can you share ur algorithm for more reference?

    Thanks

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,106
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •