如何使用 openmesh 从网格中删除面?

发布于 01-12 02:01 字数 1074 浏览 4 评论 0原文

几乎与标题一样,我试图使用开放网格删除网格的几个面,如下所示:


    MyMesh mesh;

    char fname[1024];
    sprintf(fname, "box_%i.obj", 0);
    if (!OpenMesh::IO::read_mesh(mesh, std::string(fname)))
    {
        std::cerr << "read error\n";
        exit(1);
    }

    MyMesh::FaceIter v_it, v_end(mesh.faces_end());
    uint count = 0;
    for (v_it=mesh.faces_begin(); v_it!=v_end; ++v_it)
    {
        mesh.delete_face(*v_it, true);
    }

这是第一次调用delete_face时出现的段错误。

然而,编写这个网格(不尝试删除面):

    if (!OpenMesh::IO::write_mesh(mesh, std::string("open_mesh.obj")))
    {
        std::cerr << "write error\n";
        exit(1);
    }

工作得很好,搅拌机可以打开 obj。所以问题似乎在于我如何尝试删除这些面孔。

这些文档似乎没有提供任何解释为什么这无效: https://www.graphics.rwth-aachen.de/media/openmesh_static/Documentations/OpenMesh-Doc-Latest/a02618.html#ae20c4e746b52c34ace6a7b805fbd61ac

Pretty much the title I am trying to delete a few faces of a mesh using open mesh, like this:


    MyMesh mesh;

    char fname[1024];
    sprintf(fname, "box_%i.obj", 0);
    if (!OpenMesh::IO::read_mesh(mesh, std::string(fname)))
    {
        std::cerr << "read error\n";
        exit(1);
    }

    MyMesh::FaceIter v_it, v_end(mesh.faces_end());
    uint count = 0;
    for (v_it=mesh.faces_begin(); v_it!=v_end; ++v_it)
    {
        mesh.delete_face(*v_it, true);
    }

This is segfaulting on the first call to delete_face.

However, writing this mesh (without trying to delete faces):

    if (!OpenMesh::IO::write_mesh(mesh, std::string("open_mesh.obj")))
    {
        std::cerr << "write error\n";
        exit(1);
    }

Works perfectly fine and blender can open the obj. So the issue very much seems to be with how I am trying to delete the faces.

The docs don;t seem to provide any explanation as to why this is not valid:
https://www.graphics.rwth-aachen.de/media/openmesh_static/Documentations/OpenMesh-Doc-Latest/a02618.html#ae20c4e746b52c34ace6a7b805fbd61ac

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黒涩兲箜2025-01-19 02:01:35

我认为迭代器在删除其中的元素后无效。

for (v_it=mesh.faces_begin(); v_it!=v_end; ++v_it)
{
    mesh.delete_face(*v_it, true);
    v_it = mesh.faces_begin(); //<- add this to test
}

I think iterator being invalid after removing an element in it.

for (v_it=mesh.faces_begin(); v_it!=v_end; ++v_it)
{
    mesh.delete_face(*v_it, true);
    v_it = mesh.faces_begin(); //<- add this to test
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文