Пример #1
0
void MeshViewer :: addMesh(const ntk::Mesh& mesh, const Pose3D& pose, MeshViewerMode mode, bool influence_on_center)
{  
    unsigned long start = ntk::Time::getMillisecondCounter();
	
	if (mesh.vertices.size() < 1)
		return;

    makeCurrent();

    // Compute new mesh center.
    if (influence_on_center)
    {
        m_mesh_center = Point3f(0,0,0);
        int n_sample = 0;
        for (int i = 0; i < mesh.vertices.size(); i += mesh.vertices.size()/100 + 1)
        {
            cv::Point3f p = pose.cameraTransform(mesh.vertices[i]);
            m_mesh_center += p;
            ++n_sample;
        }
        if (mesh.vertices.size()>0)
            m_mesh_center *= 1.0/n_sample;
    }

    // Setup texture
    GLuint texture;
    if (mesh.texture.data)
    {
        if ((mesh.texture.cols % 2 != 0) || (mesh.texture.rows % 2 != 0))
            glEnable(GL_TEXTURE_RECTANGLE_NV);

        glGenTextures( 1, &texture );
        m_upcoming_textures.push_back(texture);
        glBindTexture( GL_TEXTURE_2D, texture );
        glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
        //glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_BASE_LEVEL,0);
        //glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LEVEL,0);
        //glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
        //glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
        glTexImage2D(GL_TEXTURE_2D, 0,
                     GL_RGB8, mesh.texture.cols, mesh.texture.rows,
                     0, GL_BGR, GL_UNSIGNED_BYTE,mesh.texture.data);
    }

    if (m_use_vertex_buffer_object)
    {
        addMeshToVertexBufferObject(mesh, pose, mode);
    }
    else
    {
        addMeshToDisplayList(mesh, pose, mode);
    }

    unsigned long end = ntk::Time::getMillisecondCounter();
    //ntk_dbg_print((end-start) / 1000., 1);
    updateDisplayCenter();
}
Пример #2
0
void Mesh::applyTransform(const Pose3D& pose)
{
    foreach_idx(i, vertices)
            vertices[i] = pose.cameraTransform(vertices[i]);

    ntk::Pose3D normal_pose;
    normal_pose.applyTransformBefore(cv::Vec3f(0.f,0.f,0.f), pose.cvEulerRotation());

    foreach_idx(i, normals)
            normals[i] = normal_pose.cameraTransform(normals[i]);
}
Пример #3
0
void MeshRenderer :: estimateOptimalPlanes(const Pose3D& pose, float* near_plane, float* far_plane)
{
    float min_z = std::numeric_limits<float>::max();
    float max_z = 0.01f;

    for (int i = 0; i < m_mesh->faces.size(); ++i)
    {
        const Point3f& v1 = m_mesh->vertices[m_mesh->faces[i].indices[0]];
        const Point3f& v2 = m_mesh->vertices[m_mesh->faces[i].indices[1]];
        const Point3f& v3 = m_mesh->vertices[m_mesh->faces[i].indices[2]];

        Point3f pv1 = pose.cameraTransform(v1);
        Point3f pv2 = pose.cameraTransform(v2);
        Point3f pv3 = pose.cameraTransform(v3);

        min_z = ntk::math::min(min_z,-pv1.z);
        min_z = ntk::math::min(min_z,-pv2.z);
        min_z = ntk::math::min(min_z,-pv3.z);

        max_z = ntk::math::max(max_z,-pv1.z);
        max_z = ntk::math::max(max_z,-pv2.z);
        max_z = ntk::math::max(max_z,-pv3.z);
    }

    ntk_dbg_print(min_z, 2);
    ntk_dbg_print(max_z, 2);

    if (min_z < 0)
        min_z = 0.01f;

    if (max_z < min_z)
        max_z = (min_z*2);

    *near_plane = min_z*0.9f;
    *far_plane = max_z*1.1f;
}