【问题标题】:Edge data from generated polyline in MeshlabMeshlab中生成的折线的边缘数据
【发布时间】:2021-12-08 05:21:49
【问题描述】:

我正在通过“计算平面截面”过滤器在 Meshlab 中生成折线,代码如 here 所示。

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 中所见,这将是最有帮助的。

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

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: polyline vertex meshlab pymeshlab


【解决方案1】:

更新: Pymeshlab 开发者have already included 方法m.edge_matrix() 在当前版本的pymeshlab 中公开边缘数据。从那时起,如果您有现代版本的 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()

【讨论】:

  • 非常感谢您的帮助和联系开发人员!对此,我真的非常感激。希望这有助于解决我的问题。非常感谢!
  • 更新: Pymeshlab 开发者have already included 方法m.edge_matrix() 在当前版本的pymeshlab 中暴露边缘数据。如果您有现代版本的 pymeshlab,这是解决问题的推荐方法。
  • 这是立即可用还是在下一个版本中可用?谢谢!
  • 它将在下一个版本中。不知道什么时候发布。
  • 恭喜。新版pymeshlabhas just been released
猜你喜欢
  • 2012-04-27
  • 2020-04-11
  • 2015-09-19
  • 1970-01-01
  • 2021-12-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-16
相关资源
最近更新 更多