Meshlab 中生成的折线的边缘数据

Edge data from generated polyline in Meshlab

我正在通过 'Compute Planar Section' 过滤器在 Meshlab 中生成多段线,代码如 .

for z_value in np.arange(0, 5, 1):
    ms.set_current_mesh(0)
    planeoffset = float(z_value)
    ms.compute_planar_section(planeaxis = 'Z Axis', planeoffset = planeoffset)
    m = ms.current_mesh()
    m.compact()
    print(m.vertex_number(), "vertices in Planar Section Z =", planeoffset)

我希望能够做的是获取用于将一个点连接到另一个点的数据。 Meshlab 保存此数据,因为当我将多段线导出为 DXF 时,边缘存在,正确连接在一起。

我想象一个列表,其中每条边都有一个起点和终点(可能是顶点 ID),如在 DXF 中看到的那样将是最有帮助的。

任何帮助获取此信息的指导将不胜感激。

更新: Pymeshlab 开发人员have already included 在当前版本的pymeshlab 中m.edge_matrix() 公开边缘数据的方法。从那时起,如果您有现代版本的 pymeshlab,这是解决问题的推荐方法。

我必须带来坏消息。在当天(2021 年 10 月),您请求的边缘信息存储在 VCG 网格内部,但未公开给 python API,因此您无法使用 pymeshlab 读取它。您只能使用 m.edge_number() 方法读取边数。

如果您需要继续您的项目,您的选择是:

  1. https://github.com/cnr-isti-vclab/PyMeshLab/issues/写一期,恳请开发者将边缘信息暴露给pymeshlab api。
  2. 如果您的表面是凸面,您可以重建边缘数据计算顶点的凸包,或者通过围绕顶点质心按角度对顶点进行排序。
  3. 如果您的曲面很复杂,您仍然可以将网格存储到 dxf 文件中,然后解析 dxf 以读回信息

选项 3 似乎是最容易实现的。 meshlab写的DXF文件有很多段

LINE
8
0
10
40.243473   -> this is coordinate X of point 1
20
-40.981182  -> this is coordinate Y of point 1
30
0.000000    -> this is coordinate Z of point 1
11
40.887867    -> this is coordinate X of point 2
21
-42.090389   -> this is coordinate Y of point 2
31
0.000000    -> this is coordinate Z of point 2
0

所以你可以用这段python代码解析dxf文件

edges=[]
with open("contour.dxf") as f:
    line = f.readline().strip()
    while line:
        if line == "LINE" :
            f.readline()
            f.readline()
            f.readline()
            x1 = float(f.readline())
            f.readline()
            y1 = float(f.readline())
            f.readline()
            z1 = float(f.readline())
            f.readline()
            x2 = float(f.readline())
            f.readline()
            y2 = float(f.readline())
            f.readline()
            z2 = float(f.readline())
            print("edge from", (x1,y1,z1), "to", (x2,y2,z2))
            edges.append( ( (x1,y1,z1), (x2,y2,z2) ) )
        line = f.readline().strip()