问题描述
我有一个 stl 文件,里面有大量的 traingles。我想使用顶点阈值分割 stl 文件。
1.我使用 numpy-stl 将 stl 文件拆分为两个单独的实体。分割完成。
-
我还附上了原始网格和分裂网格的图像。
加载原始 stl 网格
mesh = mesh.Mesh.from_file('mesh.stl')
facet_normals = pd.DataFrame(mesh.units)
vertex1 = pd.DataFrame(mesh.v0)
vertex2 = pd.DataFrame(mesh.v1)
vertex3 = pd.DataFrame(mesh.v2)
网格分裂从这里开始
coord_matrix = np.zeros((len(facet_normals),12))
coord_matrix = pd.DataFrame(coord_matrix)
所有的顶点法线和面法线都排列在矩阵中
coord_matrix[coord_matrix.columns[0:3]] = vertex1[vertex1.columns[0:3]] coord_matrix[coord_matrix.columns[3:6]] = vertex2[vertex2.columns[0:3]] coord_matrix[coord_matrix.columns[6:9]] = vertex3[vertex3.columns[0:3]] coord_matrix[coord_matrix.columns[9:12]] = facet_normals[facet_normals.columns[0:3]]
根据顶点阈值分成两部分
c = coord_matrix[(coord_matrix2 2 >=0.1) & (coord_matrix[5] >=0.1) & (coord_matrix[8] >=0.1)]
将其分配给名为“chestwall”的新分割网格
chestwall = mesh.Mesh(np.zeros(c.shape[0],dtype=mesh.Mesh.dtype)) chestwall_facet_normals = np.array(c[c.columns[9:12]])
chestwall.units = chestwall_facet_normals
chestwall.v0 = np.array(c[c.columns[0:3]])
chestwall.v1 = np.array(c[c.columns[3:6]])
chestwall.v2 = np.array(c[c.columns[6:9]])
将其分配给名为“gland”的新分割网格
gland = mesh.Mesh(np.zeros(g.shape[0],dtype=mesh.Mesh.dtype))
gland_facet_normals = np.array(g[g.columns[9:12]])
gland.units = 腺体_facet_normals
gland.v0 = np.array(g[g.columns[0:3]])
gland.v1 = np.array(g[g.columns[3:6]])
gland.v2 = np.array(g[g.columns[6:9]])
保存新的分割网格
chestwall.save('chestwall.stl')
gland.save('gland.stl')`
图像:
正如在分裂网格中所见,两个网格的连接之间存在孔洞。如何获得闭合网格?任何线索将不胜感激。
问候, Sunag R A.
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)