Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opengl 3d point cloud render from x,y,z 2d array

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.

like image 1000
user1733628 Avatar asked Oct 10 '12 06:10

user1733628


People also ask

Is it possible to plot real time x/y/z data in OpenGL?

I’m a brand new OpenGL programmer and I have embarked on project to plot real time X,Y,Z data to generate a 3D waterfall. I am using VS 2010 C# with the SharpGL libraries. I am now dealing with plotting the data. As a first test, I have 10 arrays of 10 data points ( Y data) in an array, with the X increment being 0.1, and the z increment being 0.1.

What is gldrawarrays in OpenGL?

if you call “glDrawArrays (…)”, OpenGL starts reading your VBO, and sends te data according to the settings o your VAO to the program object the example above divides the application into 3 main phases:

How do I draw points in OpenGL?

As stated in the comments, drawing points is as simple as drawing GL_POINTS instead of GL_TRIANGLES, you'll need one vertex instead of three of course. Of course it is structured. It may not be in the format OpenGL expects, but it definitely has some sort of structure, some format you're able to parse.

Can I use a sprite sheet as a texture in OpenGL?

This can happen if you use a single image to store many sprites in a sprite sheet. Here's an example sheet from a Dwarf Fortress tileset: You coulduse a tileset in OpenGL directly as a texture simply by taking the texels from the right place in the texture:


1 Answers

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.

like image 116
Hugh Avatar answered Sep 28 '22 07:09

Hugh