更新: Pymeshlab 开发者have already included 方法m.edge_matrix() 在当前版本的pymeshlab 中公开边缘数据。从那时起,如果您有现代版本的 pymeshlab,推荐使用这种方法来解决您的问题。
我必须带来坏消息。在当天(2021 年 10 月),您请求的边缘信息存储在 VCG 网格内部,但未暴露给 python API,因此您无法使用 pymeshlab 读取它。您只能使用 m.edge_number() 方法读取边数。
如果您需要继续您的项目,您的选择是:
- 在https://github.com/cnr-isti-vclab/PyMeshLab/issues/ 写一期,请开发人员将边缘信息公开给 pymeshlab api。
- 如果您的曲面是凸面,您可以重建边缘数据来计算顶点的凸包,或者通过围绕顶点质心按角度对顶点进行排序。
- 如果您的表面很复杂,您仍然可以将网格存储到 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()