title: Failing to extract volumes of difference between triangulated Nef polyhedrons derived from STEP files
body: <p>Suppose to have a polyhedron representing an object <em>A</em>, and to want to get its concavities.</p>
  
  <p>An option for doing that consists in computing the convex hull <em>CH</em> of the object <em>A</em> and splitting the difference <em>CH - A</em> into connected components. </p>
  
  <p>For doing that I tried to use the <a href="https://doc.cgal.org/latest/Nef_3/index.html" rel="nofollow noreferrer">Nef Polyhedrons module in CGAL</a>. This allows to convert <em>A</em> and <em>CH</em> into Nef Polyhedrons, for easily applying boolean operations like the set difference.</p>
  
  <p>Once the difference is obtained as a Nef Polyhedron, its volumes labeled with a 1 in the <code>mark</code> field should represent the finite connected components of the difference, and can be converted back into Polyhedrons with the function <code>convert_inner_shell_to_polyhedron</code>.</p>
  
  <p>In theory this approach should work fine, but in practice there is a problem that arises when the Polyhedrons used are the result of a conversion from a STEP file into a triangular mesh that defines the Polyhedron. In fact, consider for example a quadrilateral face in the STEP file. During the conversion, it must be converted in at least two triangles. The problem is that when saving the generated triangles into the file representing the converted mesh (for example an OFF file, or a STL, or OBJ), they risk to lose their coplanarity because of vertices coordinate approximation.</p>
  
  <p>This causes, when the Nef Polyhedrons difference is computed, the following undesired behaviors:</p>
  
  <ul>
  <li>some very thin volumes are generated, because one of the diagonals of the quadrilateral (supposing the quadrilateral has been split in <em>two</em> triangles) has "moved" towards the internal of the polyhedron;</li>
  <li>the function <code>convert_inner_shell_to_polyhedron</code> prints an error message like 
  
  <blockquote>
    <p>lookup_halfedge(): input error: facet 11 shares a halfedge from vertex
    2 to vertex 1 with facet 0.</p>
  </blockquote></li>
  </ul>
  
  <p>The first behavior is not a big problem: every volume converted to a Polyhedron can be checked for its thickness and eventually discarded. The second one, however, returns an empty Polyhedron, and there is no way, as far as I know, to get the desired volume.</p>
  
  <p>So I ask you for methods for solving this problem. Here I report some observations I did about that:</p>
  
  <ul>
  <li>CGAL Polyhedrons allow to use polygonal faces instead of triangular ones, so a solution could be to convert the STEP file into a polygonal mesh: this should allow to maintain the coplanarity of points of the same faces. However, I was not able to find software that performs the conversion without passing through a triangular mesh;</li>
  <li>convert directly the STEP file into a CGAL Polyhedron instance. I think this approach is far from being affordable in a reasonable amount of time;</li>
  <li>implementing some method for correcting coplanarity of points of neighboring faces. This may be a practicable method, but there may be some other problem arising when changing manually the position of the vertices of a polyhedron.</li>
  </ul>