void Renderer::SimpleRenderer()

in visualization/FitAdam/src/Renderer.cpp [359:552]


void Renderer::SimpleRenderer()
{
    if (use_color_fbo)
    {
        glBindFramebuffer(GL_FRAMEBUFFER, g_fbo_color);
        glViewport(0, 0, options.width, options.height);
        GLenum FBOstatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
        // GLfloat white[3] = {1., 1., 1.};
        // glClearBufferfv(GL_COLOR, 0, white);
        if (GL_FRAMEBUFFER_COMPLETE != FBOstatus)
        {
            std::cout << "FrameBuffer Fails." << std::endl;
            exit(0);
        }
        static const GLenum draw_buffers[] = {GL_COLOR_ATTACHMENT0};
        glDrawBuffers(1, draw_buffers);
    }
    else
    {
        glBindFramebuffer(GL_FRAMEBUFFER, 0);
        glViewport(0, 0, options.width, options.height);
    }

    glClearColor(1., 1., 1., 0.);
    // mesh renderer
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glPushMatrix();
    if (options.CameraMode == 0u)
    {
        gluLookAt(0, -options.view_dist * sin(0.0), -options.view_dist * cos(0.0), 0, 0, 0, 0, -1, 0);
        glRotatef(options.xrot, 1.0, 0.0, 0.0);
        glRotatef(options.yrot, 0.0, 1.0, 0.0);
    }
    else if (options.CameraMode == 2u)
    {
        glRotatef(options.xrot, 1.0, 0.0, 0.0);
        glRotatef(options.yrot, 0.0, 1.0, 0.0);
        const float centerx = 1920 * options.ortho_scale / 2;
        const float centery = 1080 * options.ortho_scale / 2;
        gluLookAt(centerx, centery, 0, centerx, centery, 1, 0, -1, 0);
    }
    else
    {
        assert(options.CameraMode == 1u);
        glTranslatef(0, 0, options.view_dist);
        glRotatef(options.xrot, 1.0, 0.0, 0.0);
        glRotatef(options.yrot, 0.0, 1.0, 0.0);
        glTranslatef(0, 0, -options.view_dist);
    }

    if (options.CameraMode == 0u)
    {
        cv::Point3d min_s(10000., 10000., 10000.);
        cv::Point3d max_s(-10000., -10000., -10000.);
        assert(pData->resultJoint);
        int start_idx, end_idx;
        if (pData->vis_type <= 2)
        {
            start_idx = 0;
            if (pData->vis_type == 0)  // for hand
                end_idx = 21;
            else if(pData->vis_type == 1)  // for body (SMC order)
                end_idx = 21;
            else if (pData->vis_type == 2) // for hand and body
                end_idx = 62;
        }
        else if(pData->vis_type == 3)
        {
            start_idx = 21;
            end_idx = 21 + 21;
        }
        else if (pData->vis_type == 4)
        {
            start_idx = 21 + 21;
            end_idx = 21 + 21 + 21;
        }
        else
        {
            assert(pData->vis_type == 5);
            start_idx = 15;
            end_idx = 19;
        }
        for (int i = start_idx; i < end_idx; i++)
        {
            if (pData->resultJoint[3*i+0] < min_s.x) min_s.x = pData->resultJoint[3*i+0];
            if (pData->resultJoint[3*i+0] > max_s.x) max_s.x = pData->resultJoint[3*i+0];
            if (pData->resultJoint[3*i+1] < min_s.y) min_s.y = pData->resultJoint[3*i+1];
            if (pData->resultJoint[3*i+1] > max_s.y) max_s.y = pData->resultJoint[3*i+1];
            if (pData->resultJoint[3*i+2] < min_s.z) min_s.z = pData->resultJoint[3*i+2];
            if (pData->resultJoint[3*i+2] > max_s.z) max_s.z = pData->resultJoint[3*i+2];
        }
        const GLfloat centerx = (min_s.x + max_s.x) / 2;
        const GLfloat centery = (min_s.y + max_s.y) / 2;
        const GLfloat centerz = (min_s.z + max_s.z) / 2;
        glTranslated(-centerx, -centery, -centerz);
    }

    if (pData->bShowBackgroundTexture)
    {
        glUseProgram(0);
        glDisable(GL_LIGHTING);
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, g_rgbfloatTexture);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1920, 1080, 0, GL_RGB, GL_UNSIGNED_BYTE, pData->backgroundImage.data);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
        glBegin(GL_QUADS);
        glColor3f(1.0, 1.0, 1.0);
        const float d = 995;

        glTexCoord2f(0, 0);
        Eigen::Map<Eigen::Matrix<double, 3, 3, Eigen::RowMajor>> K(options.K);
        Eigen::Vector3d P(0, 0, 1);
        P = K.inverse() * P;
        P = P / P(2);  // normalize so that z = 1
        glVertex3f(P(0) * d, P(1) * d, P(2) * d);  // K^{-1} [0, 0, 1]^T

        glTexCoord2f(1, 0);
        P << 1920, 0, 1;
        P = K.inverse() * P;
        P = P / P(2);  // normalize so that z = 1
        glVertex3f(P(0) * d, P(1) * d, P(2) * d);  // K^{-1} [1920, 0, 1]^T

        glTexCoord2f(1, 1);
        P << 1920, 1080, 1;
        P = K.inverse() * P;
        P = P / P(2);  // normalize so that z = 1
        glVertex3f(P(0) * d, P(1) * d, P(2) * d);

        glTexCoord2f(0, 1);
        P << 0, 1080, 1;
        P = K.inverse() * P;
        P = P / P(2);  // normalize so that z = 1
        glVertex3f(P(0) * d, P(1) * d, P(2) * d);
        glEnd();
        glDisable(GL_TEXTURE_2D);
        glEnable(GL_LIGHTING);
    }

    glUseProgram(0);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    //Draw the target joint
    if (options.show_joint && pData->targetJoint != NULL)
    {
        glColor3ub(100u, 100u, 100u);
        DrawSkeleton(pData->targetJoint, pData->vis_type, pData->connMat[pData->vis_type]);
    }
    //Draw the predicted joint
    if (options.show_joint && pData->resultJoint != NULL)
    {
        glColor3ub(50u, 50u, 50u);
        DrawSkeleton(pData->resultJoint, pData->vis_type, pData->connMat[pData->vis_type]);
    }

    if (pData->bRenderFloor)  // draw the floor
    {
        glDisable(GL_LIGHTING);
        const int grid_num = 20;
        const int width = 100;

        Eigen::Vector3d normal(pData->ground_normal[0], pData->ground_normal[1], pData->ground_normal[2]);
        normal = normal / normal.norm();
        Eigen::Vector3d tangent1(normal[0], -normal[2], normal[1]), tangent2(normal[1], -normal[0], normal[2]);
        Eigen::Vector3d origin(pData->ground_center[0], pData->ground_center[1], pData->ground_center[2]);
        origin = origin - grid_num * width * (tangent1 + tangent2);
        for (auto y = 0; y < 2 * grid_num + 1; y++)
            for (auto x = 0; x < 2 * grid_num + 1; x++)
            {
                if ((x + y) % 2 == 0)
                    glColor3f(1.0, 1.0, 1.0);
                else
                    glColor3f(0.7, 0.7, 0.7);
                Eigen::Vector3d P = origin + x * width * tangent1 + y * width * tangent2;
                glBegin(GL_QUADS);
                glVertex3f(P[0], P[1], P[2]);
                P = P + width * tangent1;
                glVertex3f(P[0], P[1], P[2]);
                P = P + width * tangent2;
                glVertex3f(P[0], P[1], P[2]);
                P = P - width * tangent1;
                glVertex3f(P[0], P[1], P[2]);
                glEnd();
            }
        glEnable(GL_LIGHTING);
    }

    glPopMatrix();
    glutSwapBuffers();
}