繁体   English   中英

CGAL:从网格中读取顶点和三角形

[英]CGAL: Read vertices and triangles from mesh

我只是在 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 访问),但我c2t3仅通过操作c2t3tr变量c2t3任何类似的c2t3 我期待的是这样的:

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

任何人都可以解决我的问题并指出我做错了什么吗? 此外,CGAL 的 API 非常......原始。 使用源代码挖掘也是非常核心的 - 以至于我找不到 output_surface 函数体。

好的,我在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))];
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM