【问题标题】:CGAL: Get face data from surface meshCGAL:从表面网格中获取人脸数据
【发布时间】:2017-10-18 10:38:53
【问题描述】:

我正在尝试用从 CGAL::Surface_mesh 检索到的数据填充我自己的结构。

您可以通过...将面添加到表面网格中。

CGAL::SM_Face_index face = SM_Surface_Mesh.add_face(SM_Vertex_Index, SM_Vertex_Index, SM_Vertex_Index);

.. 但是如何在给定 SM_Face_Index 的情况下检索那张脸呢?我已尝试筛选文档,但无济于事。

InteropMesh * outputMesh = new InteropMesh();
uint32_t num = mesh1.number_of_vertices();

outputMesh->vertexCount = num;

outputMesh->vertices = new InteropVector3[num];

for (Mesh::Vertex_index vd : mesh1.vertices()) 
{
    uint32_t index = vd; //via size_t

    Point data = mesh1.point(vd);
    outputMesh->vertices[index].x = (float)data.x();
    outputMesh->vertices[index].y = (float)data.y();
    outputMesh->vertices[index].z = (float)data.z();
}

outputMesh->indices = new uint32_t[mesh1.number_of_faces() * 3];

for (CGAL::SM_Face_index fd : mesh1.faces())
{
    //? How do I get the three vertex indices?
}

【问题讨论】:

    标签: c++ cgal


    【解决方案1】:

    Surface_mesh 数据结构不仅可以表示三角形网格。这意味着每个面可能有超过 3 个顶点。 获得面后,您可以在其边界边缘上导航并获取源顶点和目标顶点。

    例如你可以这样做:

    Surface_mesh::Halfedge_index hf = sm.halfedge(fi);
    for(Surface_mesh::Halfedge_index hi : halfedges_around_face(hf, sm))
    {
      Surface_mesh::Vertex_index vi = target(hi, sm);
    }
    

    您也可以手动操作:

    Surface_mesh::Halfedge_index hstart = sm.halfedge(fi), hi=hstart;
    do{
      Surface_mesh::Vertex_index vi = target(hi, sm);
      hi=sm.next(hi);
    }
    while(hi!=hstart)
    

    【讨论】:

      【解决方案2】:

      获取顶点和面索引的简单方法可以这样完成;

      typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
      typedef CGAL::Surface_mesh<K::Point_3> Mesh;
      
      Mesh sm;
      
      // sm created here or as a result of some CGAL function
      
      std::vector<float> verts;
      std::vector<uint32_t> indices;
      
      //Get vertices ...
      for (Mesh::Vertex_index vi : sm.vertices()) {
          K::Point_3 pt = sm.point(vi);
          verts.push_back((float)pt.x());
          verts.push_back((float)pt.y());
          verts.push_back((float)pt.z());
      }
      
      //Get face indices ...
      for (Mesh::Face_index face_index : sm.faces()) {
          CGAL::Vertex_around_face_circulator<Mesh> vcirc(sm.halfedge(face_index), sm), done(vcirc);
          do indices.push_back(*vcirc++); while (vcirc != done);
      }
      

      此示例假设输出三角形(即每 3 个索引描述一个三角形),尽管正如 Andry 指出的那样,面部可能有更多索引。

      应该添加另一个函数来检查人脸索引计数,如果索引超过 3 个,则将人脸分割成三角形。

      【讨论】:

      • 老实说,我不知道这有什么用,但欢迎来到 StackOverflow!
      • 谢谢 Auspex!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-17
      • 2013-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-05
      相关资源
      最近更新 更多