title: How do I remove self-intersecting triangles from a 3D surface mesh?
body: <p>I have a CGAL surface_mesh of triangles with some self-intersecting triangles which I'm trying to remove to create a continuous 2-manifold shell, ultimately for printing.</p>
  <p>I've attempted to use <a href="https://github.com/CGAL/cgal/blob/master/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/repair.h#L1877" rel="nofollow noreferrer">remove_self_intersection()</a> and <a href="https://github.com/CGAL/cgal/blob/master/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/corefinement.h#L771" rel="nofollow noreferrer">autorefine_and_remove_self_intersections()</a> from <a href="https://stackoverflow.com/questions/50840742/remove-self-intersections-in-meshlab-or-vcglib">this answer</a>. The first only removes a few self-intersections while the second completely removes my mesh.</p>
  <p>So, I'm trying my own approach - I'm finding the <a href="https://doc.cgal.org/latest/Polygon_mesh_processing/group__PMP__intersection__grp.html#ga0afb9e365a2f16f0591255b8df468885%20self-intersections" rel="nofollow noreferrer">self-intersections</a> and then attempting to delete them. I've tried using the low level <a href="https://doc.cgal.org/latest/Surface_mesh/classCGAL_1_1Surface__mesh.html#af2311658bf6d730b276b23b5c304f90e" rel="nofollow noreferrer">remove_face</a> but the borders are not detectable afterwards so I'm unable to fill the resulting holes. <a href="https://stackoverflow.com/questions/45875622/cgal-surface-mesh-removing-face">This answer</a> refers to using the higher level Euler remove_face but this method, and make_hole seem to discard my mesh entirely.</p>
  <p>Here is an extract (I'm using break to see if I can get at least one triangle removed, and I'm just trying with the first of the pair):</p>
  <pre><code>    vector&lt;pair&lt;face_descriptor, face_descriptor&gt; &gt; intersected_tris;
  PMP::self_intersections(mesh, back_inserter(intersected_tris));
  for (pair&lt;face_descriptor, face_descriptor&gt; &amp;p : intersected_tris) {
      CGAL::Euler::remove_face(mesh.halfedge(get&lt;0&gt;(p)), mesh);
      break;
  }
  </code></pre>