drawing contour lines

Started by
10 comments, last by LilBudyWizer 18 years, 3 months ago
Hi All, I am trying to draw a surface chart using opengl. I am able to draw it properly but i just wondering how will be possible for me to draw the contouyr lines for the surface chart. Just not able to found the right API for doing so? Can any buddy able to give me any hint regarding the same? Thanks in advance. -kiran
Advertisement
Could you give more detail, maybe a pic of a specific example of the effect you're trying to achieve?

If by contour lines you mean something like a heightmap, then I think you'll have to improvise by processing your internal data and plotting points or short line segments. Or you might find that using evaluators can help you, but I wouldn't know where to start with those.
Hi,
yeah you are correct i want to draw height map where i want to identify each section with different color. I am currently using GL_QUARDS mode to connect the point which are closer to each other.
So i am just wondering there if there will be any api avaliable out of the box where i can use it directly to paint the section with the required color directly.
If the regions are convex (that's a pretty big if), then you probably could use GL_POLYGON to connect them (set different color for each polygon) and position the lower regions further away into the screen to prevent overwrite. (You've probably already thought of that with your quad method.)
If you aren't too concerned with speed and just want it implemented quickly I have one solution for you:

1. Create a clipping plane at the bottom of the heightmap.
2. Set color to contour color.
3. Render heightmap.
3. Move clipping plane up as high as you want your contour line.
4. Set color to nomal.
5. Render heightmap.
6. Move clipping plane up to the base of your next contour line.
7. Repeat step 2 to step 6 for each contour.

Easy to implement, looks good, but probably very slow :)
-Skiller
Hi Skiller,
Thank you very much for your reply it would be a great help if you could provide me with some code snippet for drawing the contour regions.

Following is the code i am using to draw the surface chart

glDraw()
{
#region Matrix SetUp
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

GL.glLoadIdentity();
#endregion

GL.glPushMatrix();


#region SurfaceReleated
//====== Set the polygon filling mode
InteropAPI.glPolygonMode( InteropAPI.GL_FRONT_AND_BACK, InteropAPI.GL_FILL );
//====== Image grid sizes
int nx = m_xSize-1,
nz = m_zSize-1;

int i = 0;
for (int z=0; z <
Hi Skiller,
Please find below the code snippet i am using to draw the Surface chart
void glDraw()
{
#region Matrix SetUp
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

GL.glLoadIdentity();
#endregion

GL.glPushMatrix();


#region SurfaceReleated
//====== Set the polygon filling mode
InteropAPI.glPolygonMode( InteropAPI.GL_FRONT_AND_BACK, InteropAPI.GL_FILL );
//====== Image grid sizes
int nx = m_xSize-1,
nz = m_zSize-1;

int i = 0;
for (int z=0; z < nz; z++, i++)
{

InteropAPI.glBegin ( InteropAPI.GL_QUADS );


//====== Turn on the primitive connection mode (connected)
//====== The strip of connected quads begins here
for (int x=0; x < nx; x++, i++)
{
// i, j, k, n — 4 indices of a quad
// Counter Clockwise direction

int j = i + m_xSize, // Other vertices indices
k = j+1,
n = i+1;

//=== Get coordinates of 4 vertices


//====== Vertices are given in counter clockwise direction order

InteropAPI.glVertex3f (xi, yi, -zi);

InteropAPI.glVertex3f (xj, yj, -zj);

InteropAPI.glVertex3f (xk, yk, -zk);

InteropAPI.glVertex3f (xn, yn, -zn);
}
//====== Close block of GL_QUAD_STRIP commands
InteropAPI.glEnd();
}


#endregion SurfaceReleated

GL.glPopMatrix();
GL.glFlush();
}
My guess is it would look something like this, tho it looks like you have wrapped up your gl commands so you'd need to do that to this code too.

#define MAX_CONTOURS 10float clipHeight = 0.0f;glColor4f(0.0f, 1.0f, 0.0f, 1.0f);for (int c = 0; c < MAX_CONTOURS; ++c) {	double clipPlane[4] = {0.0f,1.0f, 0.0f, 0.0f};		//Define Clip plane	glPushMatrix();	glTranslatef(0.0f, clipHeight, 0.0f);			// Set position of clip plane	glEnable(GL_CLIP_PLANE0);				//Enable clip plane	glClipPlane(GL_CLIP_PLANE0, clipPlane);			//Create clip plane	glPopMatrix();	//Insert code between "#region SurfaceReleated" and "#endregion SurfaceReleated" here	//Will create green contour 0.1f high every 10.0f units	clipHeight += 0.1f;	glColor4f(0.0f, 1.0f, 0.0f, 1.0f);	if (c % 2 == 1) {		clipHeight += 9.8f;		glColor4f(1.0f, 1.0f, 1.0f, 1.0f);	}}


Havn't checked it but that should work. You might need to turn of writing to the depth buffer for it to work right tho, and you'll probably wan to disable the clipping plane at some point too.
It should give you some place to start though :)

And dont forget this will probably run pretty slow :(

A better way I just thaught of would be using a pixel shader, would be a little harder to implement but it would be MUCH faster :)

BTW you should read this
-Skiller
Hi Skiller,
Thanks a lot for your reply, but still i am not able to do draw the height map.
I think my logic is not exactly fitting with ur code.Can it be possible for me to specify the color for a particular region so that anything drawn in that area will get filled with the color what i have already set.

Thanks in advance.


-kiran
You can use glTexGen and a 1D texture to shade the heightmap according to height. The 1D texture would generally be a color gradiant. Since it's 1D you have one component, the s component. If you want to shade by height then the parameters are basically (0,1,0,0). That would make y translate directly to the s component. Chances are your y's don't run from 0 to 1 though. Rather they go from min to max and you want to map that to 0 to 1. So you want (0,1/(max-min),0,-min/(max-min)). So for (x,max,z,1) you get 0*x + max/(max-min) + 0*z - min/(max-min) = (max-min) / (max-min) = 1 and for (x,min,z,1) you get 0*x + min/(max-min) + 0*z - min/(max-min) = (min-min) / (max-min) = 0.
Keys to success: Ability, ambition and opportunity.

This topic is closed to new replies.

Advertisement