0

I am pretty new to Qt so sorry if this is a straight forward question.

I am using Qt 5.5 and trying to visualize a point cloud in QOpenGLWidget.

This is my header:

class PointCloudWindow : public QOpenGLWidget
{
public:
    void setDepthMap(DepthMapGrabber* grabber);

protected:
    void initializeGL();
    void paintGL();

private:
    QMatrix4x4 m_projection;
    DepthMapGrabber* m_grabber;
};

and here is the corresponding cpp:

void PointCloudWindow::setDepthMap(DepthMapGrabber* grabber) {
    m_grabber = grabber;

    QTimer* updatePointCloud = new QTimer(this);
    connect(updatePointCloud, SIGNAL(timeout()), SLOT(update()));
    updatePointCloud->start();
}

void PointCloudWindow::initializeGL() {
    glewInit(); // TODO: check for return value if error occured

    glEnable(GL_DEPTH_TEST);

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}

void PointCloudWindow::paintGL() {
    m_grabber->getNextDepthFrame(); // TODO: check for return value if error occured

    m_projection.setToIdentity();
    m_projection.perspective(45.0f, width() / (float)height(), 0.01f, 100.0f);

    if (m_grabber->getDepthMap()->cloud) {
        glBegin(GL_POINTS);
        glColor3f(0.8f, 0.8f, 0.8f);
        for (UINT i = 0; i < m_grabber->getDepthMap()->size; ++i)
        {
            glVertex3f(m_grabber->getDepthMap()->cloud[i].X, m_grabber->getDepthMap()->cloud[i].Y, m_grabber->getDepthMap()->cloud[i].Z);
        }
        glEnd();
    }
}

This is how my point cloud looks like after visualization:

point cloud from Kinect V2

My problem is that as you can see (monitor is cut in half for example) if a point has a z value, which is bigger, then 1.0 then it gets clipped of. I tried to set the near and far plane, but no effect. I searched through Google and tried several things, but was unable to figure out how this works in Qt. I manged to visualize this point cloud with OpenGL and GLUT before. Any help or explanation how to do this in Qt would be much appreciated!

4

1 回答 1

2

m_projection is just a member variable in your class. It's not going to automatically "jump" into the OpenGL context. You've to explicitly load it into OpenGL. Normally you'd load a matrix like that into a uniform for use in a shader. But since you're not using shaders (booo! ;-) ) and use old, ugly and slow immediate mode (don't do that) you'll have to load it into the fixed function projection matrix.

glMatrixMode(GL_PROJECTION);
glLoadMatrixd(m_projection.constData());
于 2015-11-17T18:44:54.143 回答