首页 > 解决方案 > 写入文件:行数不匹配

问题描述

neighbors_to_file应该将每个三角形面的邻居写入文件neigh.txt,用新行分隔。此网格中的面数为 352169,因此预期的线数neigh.txt为 352169 * 3 = 1056507。但实际的线数仅为 1055697。

import openmesh as om
import os

def neighbors_to_file(mesh):
    file = open("neigh.txt","w")
    for f in mesh.faces(): # iterate over the mesh's faces
        for ff in mesh.ff(f): # iterate over the face's neighbors
            file.write(str(ff.idx()))
            file.write("\n")
    file.close()

path = os.path.join("../meshes", "tr_scan_000.obj")
r_mesh = om.read_trimesh(path)
neighbors_to_file(r_mesh)

据我所知,网格是封闭的,因此那里没有孔。

标签: pythonmeshwritetofile

解决方案


推荐阅读