【问题标题】:CGAL: Read vertices and triangles from meshCGAL:从网格中读取顶点和三角形
【发布时间】:2016-09-15 23:20:11
【问题描述】:

我只花了几个小时在 Visual Studio C++ 中使用 CGAL,试图了解网格的工作原理。我想要的是访问顶点和三角形列表(双[3]形式的顶点,int [3]形式的三角形)。这是我正在编写的脚本:

http://doc.cgal.org/latest/Surface_mesher/Surface_mesher_2mesh_a_3d_gray_image_8cpp-example.html

关键是 - 函数 CGAL::output_surface_facets_to_off (out, c2t3); 以 .off 格式向我输出了一个不错的文件(可由 MeshLab 访问),但我无法仅通过操作 c2t3tr 变量来做任何类似的事情。我所期待的是这样的:

c2t3.vertices(从 0 到 N)和 c2t3.triangles(从 0 到 M),其值为整数的三倍。我得到的是顶点列表、构面列表、单元列表、边列表......除了在未排序的顶点列表中查找每个顶点编号之外,没有其他方法可以从构面获取顶点编号。

谁能解决我的问题并指出我做错了什么?此外,CGAL 的 API 非常……原始。用源码挖掘也很硬核——以至于找不到 output_surface 函数体。

【问题讨论】:

    标签: c++ mesh cgal


    【解决方案1】:

    好的,我在Complex_2_in_triangulation_3_file_writer.h 文件中找到了答案。显然 CGAL 库正在创建整个顶点地图并在该地图中寻找小平面顶点。代码部分:

    using CGAL::Surface_mesher::number_of_facets_on_surface;
    
    typedef typename C2t3::Triangulation Tr;
    typedef typename Tr::Finite_facets_iterator Finite_facets_iterator;
    typedef typename Tr::Finite_vertices_iterator Finite_vertices_iterator;
    typedef typename Tr::Facet Facet;
    typedef typename Tr::Edge Edge;
    typedef typename Tr::Vertex_handle Vertex_handle;
    
    std::map<Vertex_handle, int> V;
    int inum = 0;
    for(Finite_vertices_iterator vit = tr.finite_vertices_begin();
    vit != tr.finite_vertices_end();
    ++vit)
    {
        V[vit] = inum++;
    }
    
    for( Finite_facets_iterator fit = tr.finite_facets_begin();
    fit != tr.finite_facets_end(); ++fit)
    {
    const typename Tr::Cell_handle cell = fit->first;
    const int& index = fit->second;
        if (cell->is_facet_on_surface(index)==true)
        {
        const int index1 = V[cell->vertex(tr.vertex_triple_index(index, 0))];
        const int index2 = V[cell->vertex(tr.vertex_triple_index(index, 1))];
        const int index3 = V[cell->vertex(tr.vertex_triple_index(index, 2))];
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-15
      相关资源
      最近更新 更多