简体   繁体   中英

Hole Filling methods takes over 20 minutes

When trying to fill holes in a mesh with a border that is highly complex, the application takes 20 minutes in the hole filling call.

It can be any of the calls shown here .

The code I'm using is this:

int main()
{
    std::ifstream input("V:/tobehealed2.off");
    Triangle_mesh mesh;
    input >> mesh;

    //////////////
    std::vector<std::vector<int>> indices(mesh.num_faces());
    std::vector<Point_3> vertices(mesh.num_vertices());

    int i = 0;
    for (auto& p : mesh.points()) {
        vertices[i++] = p;
    }

    i = 0;
    for (auto& f : mesh.faces()) {
        std::vector<int> triangle(3);
        int j = 0;
        for (auto v : mesh.vertices_around_face(mesh.halfedge(f))) {
            triangle[j++] = v;
        }

        indices[i++] = triangle;
    }

    mesh.clear();

    CGAL::Polygon_mesh_processing::repair_polygon_soup(vertices, indices);
    CGAL::Polygon_mesh_processing::orient_polygon_soup(vertices, indices);

    CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(vertices, indices, mesh);

    CGAL::Polygon_mesh_processing::keep_largest_connected_components(mesh, 1);

    bool hasHoles = true;

    std::vector<face_descriptor> face_out;
    std::vector<vertex_descriptor> vertex_out;

    while (hasHoles) {
        hasHoles = false;

        for (auto& hh : mesh.halfedges()) {
            if (mesh.is_border(hh)) {
                hasHoles = true;
                CGAL::Polygon_mesh_processing::triangulate_and_refine_hole(mesh, hh, std::back_inserter(face_out), std::back_inserter(vertex_out));
                break;
            }
        }

        face_out.clear();
        vertex_out.clear();
    }

    CGAL::Polygon_mesh_processing::keep_largest_connected_components(mesh, 1);
    CGAL::Polygon_mesh_processing::remove_isolated_vertices(mesh);

    CGAL::Polygon_mesh_processing::remove_self_intersections(mesh);

    CGAL::Surface_mesh_simplification::Count_stop_predicate<Triangle_mesh> stop(60000);
    int r = CGAL::Surface_mesh_simplification::edge_collapse(mesh, stop);
    mesh.collect_garbage();

    std::ofstream out2("V:/healed.off");
    out2 << mesh;
}

Application takes over 20 minutes in the call to triangulate_and_refine_hole .

Tested model is available for download here:

https://drive.google.com/file/d/1t2dwJBs5vNpg2jLOVprHEY-8tCHvCErK/view?usp=sharing

My goal is just to be able to check beforehand if the model has a hole so complex the closing of it will take several minutes, so I can skip the hole filling attempt. Also, if there is a way to exit the function call after some threshold time it would be nice.

The size of the model doesn't matter so much. If I use a mesh 3 times larger, it can fill a not-so-complex-hole in just a few seconds.

Also, if there is a way to exit the function call after some threshold time it would be nice.

What always works is to start the task in another thread and monitor that thread, killing it if necessary after some time.

Really wouldn't be a pretty solution though. CGAL is still a maintained library, so fairly sure you just povide it some incorrect data. Or are you sure at all that it actually hangs up? 36Mb is quite a solid size for a model and hole-fixing is a task that grows with model complexity if I recall right.

EDIT: Ah well, if you can afford to wait in general for 20 mintes before having a repaired model, threading is the way to go. It will just run in the background. if you cannot afford that it takes so long, well, then it is not so easy. Either you find some significantly better implementation (not that likely), or you will have to do some trade offs. Either simplifying the model or living with less correct hole fixes (assuming there are some heuristic algorithms for this task).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM