gpt4 book ai didi

c++ - 如何使用 OpenMesh 设置人脸的颜色?

转载 作者:行者123 更新时间:2023-11-28 04:10:11 41 4
gpt4 key购买 nike

我试图只设置特定面孔的颜色,但我的代码一直抛出错误。

mesh.set_color(*f_it, clr); 行抛出错误(关于属性错误)。我尝试将其更改为 mesh.set_color(f_it.handle(), clr); 但这会引发取消引用错误。

我要正确设置颜色吗?

typedef OpenMesh::TriMesh_ArrayKernelT<> myMesh;
myMesh * Mesh;
myMesh mesh;

void computeFaceNormals(myMesh mesh) {
OpenMesh::Vec3f pointA, pointB, pointC;
myMesh::VertexIter vlt, vBegin, vEnd;
myMesh::ConstFaceVertexIter cfvlt;
myMesh::Color clr;

for (myMesh::FaceIter f_it = mesh.faces_begin(); f_it != mesh.faces_end(); f_it++) {
cfvlt = mesh.cfv_iter(*f_it);
pointA = mesh.point(*cfvlt);
pointB = mesh.point((*cfvlt++));
pointC = mesh.point((*cfvlt++));

clr[0] = 0;
clr[1] = 1;
clr[2] = 0;

mesh.set_color(*f_it, clr);
}

}

最佳答案

openmesh 网格 (OpenMesh::TriMesh_ArrayKernelT) 可以使用不同的属性:顶点颜色、面颜色、顶点法线等。但是您需要明确指定您希望网格具有的属性。

在你的情况下,你缺少的是
mesh.request_face_colors();

如果您收到网格作为参数,您可以检查它是否已经具有颜色属性:
mesh.has_face_colors()

您还可以使用以下方法删除属性:
mesh.release_face_colors();

Read the tutorial for more details.您应该考虑的重要说明(来自教程)阐明了 request/has/release 的用法:

But, what happens if for example the vertex status property has been requested twice? Then the first release does nothing, but the second one will remove it. The standard properties have a reference counter, which is incremented by one for each request and decremented by one for each release. If the counter reaches 0 the property will be removed from memory.

关于c++ - 如何使用 OpenMesh 设置人脸的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57976347/

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