如何使用 OpenMesh 设置人脸的颜色?
How to set the color of a face using OpenMesh?
我正在尝试设置某张脸的颜色,但我的代码一直出错。
行 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.
我正在尝试设置某张脸的颜色,但我的代码一直出错。
行 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.