【问题标题】:what is the element face in ply file formatply文件格式的元素面是什么
【发布时间】:2017-01-18 17:58:58
【问题描述】:

我正在编写代码以在 opengl (c++) 中读取和绘制 ply 文件格式。 我使用glVertex3d 函数作为顶点元素。现在我不明白 ply 文件中的element face 是什么?这是为了颜色吗?有什么想法吗?

【问题讨论】:

    标签: c++ opengl


    【解决方案1】:

    面是多边形。读取顶点后开始读取面。每条面线都以多边形中的顶点数开始。然后是 0 偏移多边形顶点索引的数量。

    假设您将顶点读入具有 x、y、z 成员的结构向量(例如)。还将面部索引读入结构。

    for (int f = 0; f < num_faces; ++f)
    {
        glBegin(GL_POLYGON);
          for (int i = 0; i < face[f].num_vertices; ++i)
          {
            glVertex3f(face[f].vertex[i].x,face[f].vertex[i].y, face[f].vertex[i].z);
          }
        glEnd();
    }
    

    【讨论】:

    • 谢谢 emser。你使用glVertex3f 来绘制顶点。好的。我正在寻找像glVertex3f 这样的opengl 函数来绘制人脸。非常感谢
    • @user1972067:OpenGL 不考虑“面孔”,并且没有现成可用的功能。您必须自己遍历这些面孔。 emser 的答案有点过时,因为它使用立即模式。更好的解决方案是将 PLY 文件中的数据展开成一组顶点属性数组和匹配的索引数组。
    • @user1972067 谢谢,我知道我回来了几个版本的 rd&blue 书籍 ;-)。我有一段时间没有使用原始的 openGL 了。我使用 open Inventor,它使用保留模式 openGL。您可以使用数组构造面集和坐标集。 Coin3D 是一个很好的免费实现。
    【解决方案2】:

    元素 faces 描述了所有 ply 文件中有多少个面(多边形)。

    ply
    format ascii 1.0           { ascii/binary, format version number }
    comment made by Greg Turk  { comments keyword specified, like all lines }
    comment this file is a cube
    element vertex 8           { define "vertex" element, 8 of them in file }
    property float x           { vertex contains float "x" coordinate }
    property float y           { y coordinate is also a vertex property }
    property float z           { z coordinate, too }
    element face 6             { there are 6 "face" elements in the file }
    property list uchar int vertex_index { "vertex_indices" is a list of ints }
    end_header                 { delimits the end of the header }
    0 0 0                      { start of vertex list }
    0 0 1
    0 1 1
    0 1 0
    1 0 0
    1 0 1
    1 1 1
    1 1 0
    4 0 1 2 3                  { start of face list }
    4 7 6 5 4
    4 0 4 5 1
    4 1 5 6 2
    4 2 6 7 3
    4 3 7 4 0
    

    如果你看一下人脸列表从哪里开始数到最后,那么你应该数6。元素面也说6来确认。


    上面的 ply 文件被 http://paulbourke.net/dataformats/ply/ 偷来的可耻

    【讨论】:

    • 谢谢。我应该怎么做来绘制面部元素?我将这个glVertex3d 用于顶点元素,但对于我不知道的面元素
    • @user1972067 GL 不是我的四十岁(更多的 Direct3D),但我会查看此链接以了解如何在 OpenGL openglsamples.sourceforge.net/files/glut_ply.cpp 中干燥 ply 文件
    • 令人讨厌的是,该示例在 meshlab 中崩溃,意外 EOF,我正在努力寻找在 meshlab 中工作的示例
    • @com.prehensible:我知道已经晚了,但为了完整起见:这个例子中的描述是无效的代码。 { foo bar } 不是 PLY 格式的一部分。因此,如果这些描述被删除,文件可以在 MeshLab 中打开。
    【解决方案3】:

    元素是一个三角形索引,因为上面的例子在meshlab EOF中不起作用,这里是另一个例子:

    ply
    format ascii 1.0
    comment VCGLIB generated
    element vertex 8
    property float x
    property float y
    property float z
    property float nx
    property float ny
    property float nz
    element face 12
    property list uchar int vertex_indices
    end_header
    -1 24 4.5 -1.570796 1.570796 1.570796 
    0 21 4.5 1.570796 -1.570796 1.570796 
    0 24 4.5 1.570796 1.570796 1.570796 
    -1 21 4.5 -1.570796 -1.570796 1.570796 
    -1 21 2.5 -1.570796 -1.570796 -1.570796 
    0 24 2.5 1.570796 1.570796 -1.570796 
    0 21 2.5 1.570796 -1.570796 -1.570796 
    -1 24 2.5 -1.570796 1.570796 -1.570796 
    3 0 1 2 
    3 1 0 3 
    3 4 5 6 
    3 5 4 7 
    3 4 1 3 
    3 1 4 6 
    3 1 5 2 
    3 5 1 6 
    3 5 0 2 
    3 0 5 7 
    3 4 0 7 
    3 0 4 3 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-04
      • 2021-05-16
      • 2011-02-05
      • 2013-07-14
      • 1970-01-01
      • 2011-03-22
      • 2014-01-20
      • 2015-12-09
      相关资源
      最近更新 更多