使用 pymeshlab、trimesh 或 python 中的其他库填充闭合网格中的孔

问题描述 投票:0回答:1

我有一个“甜甜圈”或“环形”形状的网格,这意味着它中间有一个孔,但它是一个封闭的网格。这些孔是由网格的拓扑造成的,而不是由于错误或缺失多边形造成的。我需要填补这个洞,这样我就有一个完整的表面。我可以使用 pymeshlab、trimesh 或 python 中的其他库来实现此目的吗?我尝试过使用不同的库来填充孔方法,但由于这是一个封闭的表面,这些方法不起作用。

这是我的网格的示例。

enter image description here

enter image description here

这是我的网格在填充网格上的拓扑孔后应如何显示的示例

enter image description here

以下是我尝试过的一些功能

使用修剪网格:

stl_file = os.path.join(stl_folder, filename)
mesh = trimesh.load(stl_file)
filled_mesh = mesh_creator.fillMesh(mesh)
filled_mesh.export(stl_file)

使用VTK

fillHolesFilter = vtk.vtkFillHolesFilter() 
fillHolesFilter.SetInputConnection(reader.GetOutputPort())
fillHolesFilter.SetHoleSize(1000.0) 
fillHolesFilter.Update()

但是这些给了我完全相同的网格,但没有填充孔。

python mesh meshlab trimesh
1个回答
0
投票

正如尼尔·布彻(Neil Butcher)在你的帖子下的评论中所说,收缩包装似乎是你的首选技术。

PyMeshLab 提供了 2022 年论文“Alphawrapping with an offset”中描述的算法的实现。查看 PyMeshLab 文档 了解更多信息。

代码如下所示:

import pymeshlab

ms = pymeshlab.MeshSet()
ms.load_new_mesh("your_mesh.stl")
alpha = 1e-2 # size (fraction) of the 'ball'
offset = 1e-3 # distance (fraction) that is added to the surface
ms.generate_alpha_wrap(alpha, offset)
ms.save_current_mesh("dest_mesh.stl")

CGAL 中也实现了相同的算法。请在此处查看CGAL 文档。 CGAL 有一个 Python 包装器。如果您喜欢使用它,代码将如下所示:

from CGAL.CGAL_Polyhedron_3 import Polyhedron_3
from CGAL.CGAL_Alpha_wrap_3 import alpha_wrap_3

P = Polyhedron_3("your_mesh.stl")
Q = Polyhedron_3() # destination mesh
alpha = 1e-2 # size (abs) of the 'ball'
offset = 1e-3 # distance (abs) that is added to the surface
alpha_wrap_3(P, alpha, offset, Q)
Q.write_to_file("dest_mesh.stl")

或者,Open3D 还提供了一些您可能想要检查的表面重建算法

干杯!

© www.soinside.com 2019 - 2024. All rights reserved.