CGAL::Surface_mesh_parameterization:将顶点按原来的顺序写到off

CGAL::Surface_mesh_parameterization: write the vertices to off in the original order

我正在尝试修改 CGAL-4.13/examples/Surface_mesh_parameterization/lscm.cpp 以便生成的关闭文件中的顶点顺序与输入文件中的顶点顺序相同。

更新:示例

获取文件input.off,内容如下:

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

当我使用

从 CGAL 调用标准 lscm
/path/to/CGAL-4.13-build/examples/Surface_mesh_parameterization/lscm input.off

我得到coords.off包含

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

uvmap.off

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

文件coords.offuvmap.off包含相同顺序的顶点及其参数对(与[=20=不同 ]).相反,我希望 uvmap.off 中的参数顺序与 input.off 相对应。特别是,我希望 uvmap.off 看起来像这样:

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

基本上,这使 coords.off 变得多余,因为我可以在其角色中使用 input.off

努力解决

据我所知,这可以通过使用 6 个参数而不是 4 个参数调用 output_uvmap_to_off(...) 来实现(两个版本都可以在 CGAL-4.13/include/CGAL/Surface_mesh_parameterization/IO/File_off.h 中找到)。由于这些参数之一是 VertexIndexMap,我可能还应该使用

CGAL::Surface_mesh_parameterization::LSCM_parameterizer_3< TriangleMesh_, BorderParameterizer_, SolverTraits_ >::parameterize(...)

而不是

CGAL::Surface_mesh_parameterization::parameterize(...)

在示例中使用。

这是一个最小的(不是真正有效的)例子。它源自 lscm.cpp 但我舍弃了很多东西以保持简洁。

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/boost/graph/Seam_mesh.h>
#include <CGAL/Surface_mesh_parameterization/IO/File_off.h>
#include <CGAL/Surface_mesh_parameterization/parameterize.h>
#include <CGAL/Surface_mesh_parameterization/Two_vertices_parameterizer_3.h>
#include <CGAL/Surface_mesh_parameterization/LSCM_parameterizer_3.h>
#include <CGAL/Polygon_mesh_processing/measure.h>
#include <boost/foreach.hpp>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>

typedef CGAL::Simple_cartesian<double>      Kernel;
typedef Kernel::Point_2                     Point_2;
typedef Kernel::Point_3                     Point_3;
typedef CGAL::Surface_mesh<Kernel::Point_3> SurfaceMesh;
typedef boost::graph_traits<SurfaceMesh>::edge_descriptor SM_edge_descriptor;
typedef boost::graph_traits<SurfaceMesh>::halfedge_descriptor SM_halfedge_descriptor;
typedef boost::graph_traits<SurfaceMesh>::vertex_descriptor SM_vertex_descriptor;
typedef SurfaceMesh::Property_map<SM_halfedge_descriptor, Point_2> UV_pmap;
typedef SurfaceMesh::Property_map<SM_edge_descriptor, bool> Seam_edge_pmap;
typedef SurfaceMesh::Property_map<SM_vertex_descriptor, bool> Seam_vertex_pmap;
typedef CGAL::Seam_mesh<SurfaceMesh, Seam_edge_pmap, Seam_vertex_pmap> Mesh;
typedef boost::graph_traits<Mesh>::vertex_descriptor vertex_descriptor;
typedef boost::graph_traits<Mesh>::halfedge_descriptor halfedge_descriptor;
typedef boost::graph_traits<Mesh>::face_descriptor face_descriptor;

namespace SMP = CGAL::Surface_mesh_parameterization;

int main(int argc, char** argv)
{
  std::ifstream in_mesh((argc>1) ? argv[1] : "data/lion.off");
  if(!in_mesh){
    std::cerr << "Error: problem loading the input data" << std::endl;
    return EXIT_FAILURE;
  }

  SurfaceMesh sm;
  in_mesh >> sm;

  Seam_edge_pmap seam_edge_pm = sm.add_property_map<SM_edge_descriptor, bool>("e:on_seam", false).first;
  Seam_vertex_pmap seam_vertex_pm = sm.add_property_map<SM_vertex_descriptor, bool>("v:on_seam", false).first;

  Mesh mesh(sm, seam_edge_pm, seam_vertex_pm);
  UV_pmap uv_pm = sm.add_property_map<SM_halfedge_descriptor, Point_2>("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<Mesh>                Border_parameterizer;
  typedef SMP::LSCM_parameterizer_3<Mesh, Border_parameterizer>  Parameterizer;

  // Here's where the big changes start.
  SurfaceMesh::Property_map<SM_halfedge_descriptor, int> vimap = sm.add_property_map<SM_halfedge_descriptor, int>("h:vi").first;
  SurfaceMesh::Property_map<SM_halfedge_descriptor, bool> vpmap = sm.add_property_map<SM_halfedge_descriptor, bool>("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;
}

这无法编译,抱怨 File_off.h 中第 131 行需要转换。

真题

以下issue回答了这个问题。