跳转到主要内容

使用MeshFix修复三角形网格

项目描述

Python/Cython包装了Marco Attene的优秀、获奖软件MeshFix。此模块结合了C++的速度、Python的便携性和易于安装的特点。

该软件将多边形网格作为输入,并生成一个副本,其中所有特定集合的“缺陷”都已被纠正。MeshFix旨在纠正原始数字网格模型中存在的典型缺陷,因此如果将其应用于其他类型的输入网格(例如,镶嵌的CAD模型),可能会失败或产生粗糙的结果。

假设输入表示单个封闭实体对象,因此输出将是一个单一生成的多面体封闭三角形网格。从输入中移除了所有奇点、自相交和退化元素,而表面上的无缺陷区域则保持不变。

C++源代码最后更新时间:2020年7月1日

安装

PyPI安装

pip install pymeshfix

GitHub的源代码安装

git clone https://github.com/pyvista/pymeshfix
cd pymeshfix
pip install .

依赖关系

需要numpypyvista

如果您无法或不想安装vtk,您可以使用以下方法在不安装pyvista的情况下安装它

pip install pymeshfix --no-dependencies

您将错过一些来自 pyvista 的酷功能,但它仍然可以正常工作。

示例

使用以下Python代码测试安装

from pymeshfix import examples

# Test of pymeshfix without VTK module
examples.native()

# Performs same mesh repair while leveraging VTK's plotting/mesh loading
examples.with_vtk()

简单示例

此示例直接使用Cython包装器。这里没有铃铛或哨子

import pymeshfix

# Read mesh from infile and output cleaned mesh to outfile
pymeshfix.clean_from_file(infile, outfile)

此示例假设用户在Python中有顶点和面数组。

import pymeshfix

# Generate vertex and face arrays of cleaned mesh
# where v and f are numpy arrays
vclean, fclean = pymeshfix.clean_from_arrays(v, f)

包含和不包含VTK的完整示例

将MeshFix引入Python的主要原因是允许库与其他Python程序通信,而无需使用硬盘。因此,此示例假设您内存中有网格,并希望使用MeshFix修复它。

import pymeshfix

# Create object from vertex and face arrays
meshfix = pymeshfix.MeshFix(v, f)

# Plot input
meshfix.plot()

# Repair input mesh
meshfix.repair()

# Access the repaired mesh with vtk
mesh = meshfix.mesh

# Or, access the resulting arrays directly from the object
meshfix.v # numpy np.float64 array
meshfix.f # numpy np.int32 array

# View the repaired mesh (requires vtkInterface)
meshfix.plot()

# Save the mesh
meshfix.write('out.ply')

或者,如果VTK不可用或用户希望对清理算法有更多控制,可以直接使用MeshFix的Cython包装器。

import pymeshfix

# Create TMesh object
tin = pymeshfix.PyTMesh()

tin.LoadFile(infile)
# tin.load_array(v, f) # or read arrays from memory

# Attempt to join nearby components
# tin.join_closest_components()

# Fill holes
tin.fill_small_boundaries()
print('There are {:d} boundaries'.format(tin.boundaries()))

# Clean (removes self intersections)
tin.clean(max_iters=10, inner_loops=3)

# Check mesh for holes again
print('There are {:d} boundaries'.format(tin.boundaries()))

# Clean again if necessary...

# Output mesh
tin.save_file(outfile)

 # or return numpy arrays
vclean, fclean = tin.return_arrays()

算法和引用政策

为了更好地理解算法的工作原理,请参阅以下论文

M. Attene. 一种修复数字化多边形网格的轻量级方法。视觉计算机,2010。(c)斯普林格。DOI:10.1007/s00371-010-0416-3

本软件基于其中发表的想法。如果您将MeshFix用于研究目的,应在您的发表成果中引用上述论文。在没有适当的许可合同的情况下,MeshFix不能用于商业目的。

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分布

pymeshfix-0.17.0.tar.gz (1.5 MB 查看哈希值)

上传时间

构建分布

pymeshfix-0.17.0-cp312-cp312-win_amd64.whl (1.4 MB 查看哈希值)

上传时间 CPython 3.12 Windows x86-64

pymeshfix-0.17.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB 查看哈希值)

上传时间 CPython 3.12 manylinux: glibc 2.17+ x86-64

pymeshfix-0.17.0-cp312-cp312-macosx_11_0_arm64.whl (1.4 MB 查看哈希值)

上传时间 CPython 3.12 macOS 11.0+ ARM64

pymeshfix-0.17.0-cp312-cp312-macosx_10_9_x86_64.whl (1.5 MB 查看哈希值)

上传时间 CPython 3.12 macOS 10.9+ x86-64

pymeshfix-0.17.0-cp311-cp311-win_amd64.whl (1.4 MB 查看哈希值)

上传时间 CPython 3.11 Windows x86-64

pymeshfix-0.17.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB 查看哈希值)

上传时间 CPython 3.11 manylinux: glibc 2.17+ x86-64

pymeshfix-0.17.0-cp311-cp311-macosx_11_0_arm64.whl (1.4 MB 查看哈希值)

上传时间 CPython 3.11 macOS 11.0+ ARM64

pymeshfix-0.17.0-cp311-cp311-macosx_10_9_x86_64.whl (1.5 MB 查看哈希值)

上传时间 CPython 3.11 macOS 10.9+ x86-64

pymeshfix-0.17.0-cp310-cp310-win_amd64.whl (1.4 MB 查看哈希值)

上传时间 CPython 3.10 Windows x86-64

pymeshfix-0.17.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB 查看哈希值)

上传时间 CPython 3.10 manylinux: glibc 2.17+ x86-64

pymeshfix-0.17.0-cp310-cp310-macosx_11_0_arm64.whl (1.4 MB 查看哈希值)

上传时间 CPython 3.10 macOS 11.0+ ARM64

pymeshfix-0.17.0-cp310-cp310-macosx_10_9_x86_64.whl (1.5 MB 查看哈希值)

上传时间 CPython 3.10 macOS 10.9+ x86-64

pymeshfix-0.17.0-cp39-cp39-win_amd64.whl (1.4 MB 查看哈希值)

上传于 CPython 3.9 Windows x86-64

pymeshfix-0.17.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB 查看哈希值)

上传于 CPython 3.9 manylinux: glibc 2.17+ x86-64

pymeshfix-0.17.0-cp39-cp39-macosx_11_0_arm64.whl (1.4 MB 查看哈希值)

上传于 CPython 3.9 macOS 11.0+ ARM64

pymeshfix-0.17.0-cp39-cp39-macosx_10_9_x86_64.whl (1.5 MB 查看哈希值)

上传于 CPython 3.9 macOS 10.9+ x86-64

由以下组织支持