CGAL:从网格读取顶点和三角形 [英] CGAL: Read vertices and triangles from mesh

查看:483
本文介绍了CGAL:从网格读取顶点和三角形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在Visual Studio C ++中花了几个小时在CGAL上,试图了解网格的工作方式.我想获得的是对顶点和三角形列表的访问(顶点以double [3]的形式,三角形以int [3]的形式).这是我正在处理的脚本:

http://doc.cgal.org/latest/Surface_mesher/Surface_mesher_2mesh_a_image_3d 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函数体.

解决方案

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

I just spend few hours with CGAL in Visual Studio C++ trying to understand how meshes work. What I want to get is an access to list of vertices and triangles (vertices in form of double[3], triangles in form of int[3]). Here is the script I am working on:

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

The point is - function CGAL::output_surface_facets_to_off (out, c2t3); outputs me a nice file in .off format (accessible by MeshLab), but I CAN'T DO ANY SIMILAR just by manipulating a c2t3 or tr variable. What I was expecting was something like:

c2t3.vertices (from 0 to N), and c2t3.triangles (from 0 to M) with values of triple of integers. What I've got was list of vertices, list of facets, list of cells, list of edges... and no way to get vertices numbers from facets any other way than finding for every vertice number in nonsorted list of vertices.

Can anybody solve my problem and point what I am doing wrong? Also, API of CGAL is very... raw. Digging with source was also very hardcore - so much I couldn't find output_surface function body.

解决方案

Okay, I found the answer in Complex_2_in_triangulation_3_file_writer.h file. Apparently CGAL library is creating whole map of vertices and looking for facet vertices in this map. The code part:

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))];
    }
}

这篇关于CGAL:从网格读取顶点和三角形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆