gpt4 book ai didi

c++ - CGAL:从表面网格获取人脸数据

转载 作者:搜寻专家 更新时间:2023-10-31 00:08:49 27 4
gpt4 key购买 nike

我试图用从 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?
}

最佳答案

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

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 个,则将人脸拆分为三角形。

关于c++ - CGAL:从表面网格获取人脸数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46808246/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com