10

Need some direction on 3d point cloud display using openGl in c++ (vs2008). I am trying to do a 3d point cloud display with a texture. I have 3 2D arrays (each same size 1024x512) representing x,y,z of each point. I think I am on the right track with

glBegin(GL_POINTS);
for(int i=0; i<1024; i++)
{
   for(int j=0; j<512; j++)
   {
       glVertex3f(x[i][j], y[i][j], z[i][j]);
   }
 }    
}    
glEnd();

Now this loads all the vertices in the buffer (i think) but from here I am not sure how to proceed. Or I am completely wrong here.

Then I have another 2D array (same size) that contains color data (values from 0-255) that I want to use as texture on the 3D point cloud and display.

2
  • I don't have RGB for each point so I can't use glColor3*(r,g,b). I am tring to use the last array (with 0-255 values) as my texture for the 3D point cloud. From glBegin(GL_POLYGON) I take it you are suggesting creating a mesh???? Again the question is how to progress from what I have above. OR am I going in completely wrong direction. Oct 10, 2012 at 18:07
  • Well, the above code will basically draw a point cloud from your 3 coord arrays. There is no real "buffer" which is filled, you directly draw in immediate mode. For the colors: As I understand it you have one unsigned byte value per vertex? So you should define how these values represent some colors. You could direclty use them as intensity, or you could use a palette, or something completely different.
    – derhass
    Oct 10, 2012 at 19:42

1 Answer 1

2

The point drawing code is fine as is.

(Long term, you may run into performance problems if you have to draw these points repeatedly, say in response to the user rotating the view. Rearranging the data from 3 arrays into 1 with x, y, z values next to each other would allow you to use faster vertex arrays/VBOs. But for now, if it ain't broke, don't fix it.)

To color the points, you need glColor before each glVertex. It has to be before, not after, because in OpenGL glVertex loosely means that's a complete vertex, draw it. You've described the data as a point cloud, so don't change glBegin to GL_POLYGON, leave it as GL_POINTS.

OK, you have another array with one byte color index values. You could start by just using that as a greyscale level with

glColor3ub(color[i][j], color[i][j], color[i][j]);

which should show the points varying from black to white.

To get the true color for each point, you need a color lookup table - I assume there's either one that comes with the data, or one you're creating. It should be declared something like

static GLfloat ctab[256][3] = {
    1.0, 0.75, 0.33,  /* Color for index #0 */
    ...
};

and used before the glVertex with

glColor3fv(ctab[color[i][j]]);

I've used floating point colors because that's what OpenGL uses internally these days. If you prefer 0..255 values for the colors, change the array to GLubyte and the glColor3fv to glColor3ub.

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.