由于STL文件和VTK文件格式的不同,需要使用第三方库来进行文件格式的转换。本文使用的是meshio库。

安装meshio库:

!pip install meshio

读取STL文件并去除重复顶点信息:

import meshio

# 读取STL文件
mesh = meshio.read('Bunny_STL.stl')

# 去除重复顶点信息
mesh_out = meshio.Mesh(
    mesh.points, 
    [
        ('triangle', mesh.cells['triangle'])
    ], 
    cell_data={
        'Normals': [mesh.cell_data['Normals']['triangle']]
    }
)

# 保存为STL文件
meshio.write('Bunny_STL_no_dup.stl', mesh_out, file_format='stl')

转换为VTK文件:

# 转换为VTK文件
mesh_out_vtk = meshio.Mesh(
    mesh.points, 
    [
        ('triangle', mesh.cells['triangle'])
    ], 
    cell_data={
        'Normals': [mesh.cell_data['Normals']['triangle']]
    }
)

# 保存为VTK文件
meshio.write('Bunny_VTK.vtk', mesh_out_vtk, file_format='vtk')
``
用Python代码实现:读取并保存Bunny_STLstl文件关键在于去除重复顶点信息;转换输出为VTK文件

原文地址: https://www.cveoy.top/t/topic/eDJv 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录