Question

I have two similar point clouds, defined by a vector with their given positions (x,y,z) in space, and I want to render both clouds simultaneously and evaluate the differences between them. This is my first application using OpenGL so I still have not much grasp using it.

I've managed to render both of them by processing each vector separately, such as:

    glBegin(GL_POINTS);GLfloat green[] = { 0.f, 1.0f, .0f, alpha[1]/10 };
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, green);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, low_shininess);
    //glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
    for (std::vector<Point3D>::iterator moit = morig_cloud.begin(); moit != morig_cloud.end(); ++moit){
        if ((moit - f_cloud.begin()) % (ptd[1]) == 0){
            glVertex3f(moit->x, moit->y, moit->z);
        }
    }
    glEnd();

However, when I overlap both, the resulting image is as follows: 1

Where both the red and the blue clouds are supposed to match perfectly. Is there any way to "merge" the points? That is, considering that the points position match, I can change the color for the matching locations? The rendering is done with points only without meshing.

I tried comparing both vectors before rendering but the algorithm ended up being too slow, as the point clouds are too big.

Was it helpful?

Solution

If you want to merge them just visually, so the overlapping parts are colored with a mix of red and blue (purple) you can enable alpha blending and use the appropriate blend functions. See here for some hints.

OTHER TIPS

What you want to do is certainly possible, however with OpenGL you can merge them only in the image. OpenGL is a mere drawing API, it doesn't offer high level methods for manipulating geometry.

If a pure image space merger suffices, then you can use the stencil buffer. Render the first point cloud without performing color writes glColorMask(0,0,0,0) and setting a bit in the stencil buffer. Then render the second point cloud with color writes enabled, but only where it passes the stencil test.

So much for doing it with OpenGL in screen image space.


However I suspect you want to geometrically merge the point clouds. Okay, here it is: Since points are infinitely small, the intersection of the two point clouds are those points, for which a point at exactly the same location can be found in the other point cloud. This boils down to a nearest neighbor search, which can be done fairly well in 3 dimensions using a Kd tree (it becomes exponentially harder for higher dimensions).

But then I think you do not actually want to intersect the point clouds, but the implicit surfaces created by them. So suppose each point creates a scalar field around it with a certain radius r. The total field of one point cloud is the saturated sum of the fields of each of its constituent points. By multiplying the fields of each point cloud you get the intersectional field. If you sample that field for every point of each point cloud and discard all the points where the field lies below a threshold you get the intersection of both point clouds.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top