Search code examples
c++cgal

CGAL edge_collapse assertion failure


I'm using CGAL 5.1 with a kernel of type typedef CGAL::Simple_cartesian<float> Kernel; and a surface mesh type typedef CGAL::Surface_mesh<Kernel::Point_3> Mesh;

I load the mesh via Assimp, and everything seems fine. But when I come to run an edge_collapse I get an assertion failure CGAL_assertion(resulting_vertex_count == vertices(m_tm).size()); And sure enough, doing the math on the total number of vertices minus the removed vertex count shows that it's off by one regardless of the ratio I set.

The relevant code is:

            if(!CGAL::is_triangle_mesh(*node->mesh_info.mesh))
            {
                std::cerr << "Input geometry is not triangulated." << std::endl;
                return;
            }
            if(!is_valid_polygon_mesh(*node->mesh_info.mesh))
            {
                std::cerr << "Input geometry is not valid." << std::endl;
                return;
            }

            SMS::Count_ratio_stop_predicate<Mesh> stop(reduction);
            SMS::edge_collapse(*node->mesh_info.mesh, stop);

The two tests pass ok, so is there something obvious I'm missing? I've not tried the other algorithms yet, or set any of the optional properties. I've cleaned up the mesh using Assimp's tools for removing degenerate faces and edges, and merging coincident vertices, but I've not tried any of CGAL's tools.

I do have a "v:uv" property on each vertex, but the position property is whatever the default is.

If anyone could give me a sanity check, I'd appreciate it!


Solution

  • While trying to isolate the issue to post here, I started playing around and found that because my mesh is noisy and patchy - it's photogrammetric scan - that the standard simplification strategy was barfing on my borders. Ignoring the assert just produced a starfish.

    So I followed the example in the user manual and marked my borders as non-removable, and it is much happier now.