Search code examples
c++openglpoint-clouds

Draw Intersection between two point clouds in OpenGL


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.


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.