title: CGAL::Surface_mesh_parameterization: write the vertices to off in the original order
body: <p>I am trying to modify <code>CGAL-4.13/examples/Surface_mesh_parameterization/lscm.cpp</code> so that the order of the vertices in the resulting off file is the same as in the input file.</p>
  
  <h2> Update: Example </h2>
  
  <p>Take a file <code>input.off</code> with the following simple content:</p>
  
  <pre><code>OFF
  4 2 0
  -0.9310345 0.4333333 0 
  -1 0.4333333 0 
  -0.9310345 0.5 0 
  -1 0.5 0 
  3 1 0 2
  3 2 3 1
  </code></pre>
  
  <p>When I call the standard <code>lscm</code> from CGAL with</p>
  
  <pre><code>/path/to/CGAL-4.13-build/examples/Surface_mesh_parameterization/lscm input.off
  </code></pre>
  
  <p>I obtain <code>coords.off</code> containing</p>
  
  <pre><code>OFF
  4 2 0
  -1 0.5 0
  -0.931034 0.5 0
  -0.931034 0.433333 0
  -1 0.433333 0
  3 3 2 1
  3 1 0 3
  </code></pre>
  
  <p>and <code>uvmap.off</code> with</p>
  
  <pre><code>OFF
  4 2 0
  -0.0166567 0.982769 0
  1 1 0
  1.01666 0.0172311 0
  0 0 0
  3 3 2 1
  3 1 0 3
  </code></pre>
  
  <p>The files <code>coords.off</code> and <code>uvmap.off</code> contain the vertices and their parameter pairs in the same order (which is <em>different</em> from that in <code>input.off</code>). Instead, I would like the parameters in <code>uvmap.off</code> to be in the order corresponding to <code>input.off</code>. In particular, I want <code>uvmap.off</code> to look like this:</p>
  
  <pre><code>OFF
  4 2 0
  1.01666 0.0172311 0
  0 0 0
  1 1 0
  -0.0166567 0.982769 0
  3 1 0 2
  3 2 3 1
  </code></pre>
  
  <p>Basically, this renders <code>coords.off</code> redundant, as I can use <code>input.off</code> in its role.</p>
  
  <h2> Effort at a solution </h2>
  
  <p>From what I understand, this might be possible to achieve by calling <code>output_uvmap_to_off(...)</code> with 6 parameters instead of 4 (both versions can be found in <code>CGAL-4.13/include/CGAL/Surface_mesh_parameterization/IO/File_off.h</code>). As one of these parameters is a <code>VertexIndexMap</code>, I should probably also use </p>
  
  <pre><code>CGAL::Surface_mesh_parameterization::LSCM_parameterizer_3&lt; TriangleMesh_, BorderParameterizer_, SolverTraits_ &gt;::parameterize(...)
  </code></pre>
  
  <p>instead of</p>
  
  <pre><code>CGAL::Surface_mesh_parameterization::parameterize(...)
  </code></pre>
  
  <p>used in the example.</p>
  
  <p>Here is a minimal (not really working) example. It is derived from <code>lscm.cpp</code> but I threw away a lot of things to remain concise.</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;CGAL/Simple_cartesian.h&gt;
  #include &lt;CGAL/Surface_mesh.h&gt;
  #include &lt;CGAL/boost/graph/Seam_mesh.h&gt;
  #include &lt;CGAL/Surface_mesh_parameterization/IO/File_off.h&gt;
  #include &lt;CGAL/Surface_mesh_parameterization/parameterize.h&gt;
  #include &lt;CGAL/Surface_mesh_parameterization/Two_vertices_parameterizer_3.h&gt;
  #include &lt;CGAL/Surface_mesh_parameterization/LSCM_parameterizer_3.h&gt;
  #include &lt;CGAL/Polygon_mesh_processing/measure.h&gt;
  #include &lt;boost/foreach.hpp&gt;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;sstream&gt;
  #include &lt;string&gt;
  
  typedef CGAL::Simple_cartesian&lt;double&gt;      Kernel;
  typedef Kernel::Point_2                     Point_2;
  typedef Kernel::Point_3                     Point_3;
  typedef CGAL::Surface_mesh&lt;Kernel::Point_3&gt; SurfaceMesh;
  typedef boost::graph_traits&lt;SurfaceMesh&gt;::edge_descriptor SM_edge_descriptor;
  typedef boost::graph_traits&lt;SurfaceMesh&gt;::halfedge_descriptor SM_halfedge_descriptor;
  typedef boost::graph_traits&lt;SurfaceMesh&gt;::vertex_descriptor SM_vertex_descriptor;
  typedef SurfaceMesh::Property_map&lt;SM_halfedge_descriptor, Point_2&gt; UV_pmap;
  typedef SurfaceMesh::Property_map&lt;SM_edge_descriptor, bool&gt; Seam_edge_pmap;
  typedef SurfaceMesh::Property_map&lt;SM_vertex_descriptor, bool&gt; Seam_vertex_pmap;
  typedef CGAL::Seam_mesh&lt;SurfaceMesh, Seam_edge_pmap, Seam_vertex_pmap&gt; Mesh;
  typedef boost::graph_traits&lt;Mesh&gt;::vertex_descriptor vertex_descriptor;
  typedef boost::graph_traits&lt;Mesh&gt;::halfedge_descriptor halfedge_descriptor;
  typedef boost::graph_traits&lt;Mesh&gt;::face_descriptor face_descriptor;
  
  namespace SMP = CGAL::Surface_mesh_parameterization;
  
  int main(int argc, char** argv)
  {
    std::ifstream in_mesh((argc&gt;1) ? argv[1] : "data/lion.off");
    if(!in_mesh){
      std::cerr &lt;&lt; "Error: problem loading the input data" &lt;&lt; std::endl;
      return EXIT_FAILURE;
    }
  
    SurfaceMesh sm;
    in_mesh &gt;&gt; sm;
  
    Seam_edge_pmap seam_edge_pm = sm.add_property_map&lt;SM_edge_descriptor, bool&gt;("e:on_seam", false).first;
    Seam_vertex_pmap seam_vertex_pm = sm.add_property_map&lt;SM_vertex_descriptor, bool&gt;("v:on_seam", false).first;
  
    Mesh mesh(sm, seam_edge_pm, seam_vertex_pm);
    UV_pmap uv_pm = sm.add_property_map&lt;SM_halfedge_descriptor, Point_2&gt;("h:uv").first;
  
    halfedge_descriptor bhd = CGAL::Polygon_mesh_processing::longest_border(mesh, CGAL::Polygon_mesh_processing::parameters::all_default()).first;
  
    typedef SMP::Two_vertices_parameterizer_3&lt;Mesh&gt;                Border_parameterizer;
    typedef SMP::LSCM_parameterizer_3&lt;Mesh, Border_parameterizer&gt;  Parameterizer;
  
    // Here's where the big changes start.
    SurfaceMesh::Property_map&lt;SM_halfedge_descriptor, int&gt; vimap = sm.add_property_map&lt;SM_halfedge_descriptor, int&gt;("h:vi").first;
    SurfaceMesh::Property_map&lt;SM_halfedge_descriptor, bool&gt; vpmap = sm.add_property_map&lt;SM_halfedge_descriptor, bool&gt;("h:vp").first;
    Parameterizer parameterizer;
    parameterizer.parameterize(mesh, bhd, uv_pm, vimap, vpmap);
  
    const char* uvmap_file = "uvmap.off";
    std::ofstream uvmap_out(uvmap_file);
    SMP::IO::output_uvmap_to_off(mesh,sm.vertices(),sm.faces(),uv_pm,vimap,uvmap_out);
  
    return EXIT_SUCCESS;
  }
  </code></pre>
  
  <p>This does not compile, complaining about a required conversion on line 131 in File_off.h.</p>
  
  <h2> Actual questions </h2>
  
  <ul>
  <li>Is <code>vimap</code> initialized correctly?</li>
  <li>Is this the reasonable direction towards my goal of writing the vertices in the same order?</li>
  <li>If yes, how do I pass the correct arguments to <code>output_uvmap_to_off(...)</code>? For instance, it asks for a <code>VertexContainer</code> and I provide a <code>Vertex_range</code> (hence the compilation error, I suppose). Shall I just collect the vertices as suggested <a href="https://stackoverflow.com/questions/48809669/how-to-get-the-vertices-and-the-faces-of-a-polygon-mesh-with-cgal">here</a> or <a href="https://stackoverflow.com/questions/39521720/cgal-read-vertices-and-triangles-from-mesh">here</a> or is there a more elegant way?</li>
  <li>If no, what is the right course of action?</li>
  </ul>