Skip to main content

Repair triangular meshes using MeshFix

Project description

Python/Cython wrapper of Marco Attene’s wonderful, award-winning MeshFix software. This module brings the speed of C++ with the portability and ease of installation of Python.

This software takes as input a polygon mesh and produces a copy of the input where all the occurrences of a specific set of “defects” are corrected. MeshFix has been designed to correct typical flaws present in raw digitized mesh models, thus it might fail or produce coarse results if run on other sorts of input meshes (e.g. tessellated CAD models).

The input is assumed to represent a single closed solid object, thus the output will be a single watertight triangle mesh bounding a polyhedron. All the singularities, self-intersections and degenerate elements are removed from the input, while regions of the surface without defects are left unmodified.

C++ source last updated 1 Jul 2020

Installation

From PyPI

pip install pymeshfix

From source at GitHub

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

Dependencies

Requires numpy and pyvista

If you can’t or don’t want to install vtk, you can install it without pyvista with:

pip install pymeshfix --no-dependencies

You’ll miss out on some of the cool features from pyvista, but it will still function.

Examples

Test installation with the following from 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()

Easy Example

This example uses the Cython wrapper directly. No bells or whistles here:

import pymeshfix

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

This example assumes the user has vertex and faces arrays in 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)

Complete Examples with and without VTK

One of the main reasons to bring MeshFix to Python is to allow the library to communicate to other python programs without having to use the hard drive. Therefore, this example assumes that you have a mesh within memory and wish to repair it using 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')

Alternatively, the user could use the Cython wrapper of MeshFix directly if vtk is unavailable or they wish to have more control over the cleaning algorithm.

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()

Algorithm and Citation Policy

To better understand how the algorithm works, please refer to the following paper:

M. Attene. A lightweight approach to repairing digitized polygon meshes. The Visual Computer, 2010. (c) Springer. DOI: 10.1007/s00371-010-0416-3

This software is based on ideas published therein. If you use MeshFix for research purposes you should cite the above paper in your published results. MeshFix cannot be used for commercial purposes without a proper licensing contract.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymeshfix-0.17.0.tar.gz (1.5 MB view details)

Uploaded Source

Built Distributions

pymeshfix-0.17.0-cp312-cp312-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.12 Windows x86-64

pymeshfix-0.17.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

pymeshfix-0.17.0-cp312-cp312-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

pymeshfix-0.17.0-cp312-cp312-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12 macOS 10.9+ x86-64

pymeshfix-0.17.0-cp311-cp311-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.11 Windows x86-64

pymeshfix-0.17.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pymeshfix-0.17.0-cp311-cp311-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

pymeshfix-0.17.0-cp311-cp311-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pymeshfix-0.17.0-cp310-cp310-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.10 Windows x86-64

pymeshfix-0.17.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pymeshfix-0.17.0-cp310-cp310-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

pymeshfix-0.17.0-cp310-cp310-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pymeshfix-0.17.0-cp39-cp39-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.9 Windows x86-64

pymeshfix-0.17.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pymeshfix-0.17.0-cp39-cp39-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

pymeshfix-0.17.0-cp39-cp39-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

File details

Details for the file pymeshfix-0.17.0.tar.gz.

File metadata

  • Download URL: pymeshfix-0.17.0.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for pymeshfix-0.17.0.tar.gz
Algorithm Hash digest
SHA256 ce809a1741aaf670a3df98cf6aaba15881223bd7230928effc021395455397c9
MD5 b14de61faf92ba19cd3627517457795a
BLAKE2b-256 f51385fd4145af2e1e9c03194512309e0a631afc826396b11860c831171a37e0

See more details on using hashes here.

File details

Details for the file pymeshfix-0.17.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for pymeshfix-0.17.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 575bde851ab93642176a55f31c1e8c9611fc2ed43601cac4f3a028b8530f7075
MD5 f36c2b30c6c62f0a4f831cccce48b6f5
BLAKE2b-256 0440999e52f51b96ad580786e193073f1b96cf0e92bc06a444eb529022a7989c

See more details on using hashes here.

File details

Details for the file pymeshfix-0.17.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pymeshfix-0.17.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0a5215bda194e53c7b909a11313f2a2b6086c87e3e3f9ad26bfe016e9da45dab
MD5 e1852022eb5685f0fabbb77038444a89
BLAKE2b-256 a032023c0869f7056ce9f578308322722f25a2dc57a38430283bfc2b101a4bcb

See more details on using hashes here.

File details

Details for the file pymeshfix-0.17.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pymeshfix-0.17.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5bfc96dadd774591394451ad2855d3d5b2771e7dfd85a0ca9cbd47a968f8ed1f
MD5 8602df11b5626708ce5e83344503596a
BLAKE2b-256 aae898ad3f3310aa94ce334211054a4e9fe8e21877b39bca0db5942adfdbdd0a

See more details on using hashes here.

File details

Details for the file pymeshfix-0.17.0-cp312-cp312-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pymeshfix-0.17.0-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a7218bc3bb7bc87a7d7335ad0b0dcd376ce6f993980d4bd244365175d73ea8ea
MD5 fdb0113132554ce263db1c3ebc298a04
BLAKE2b-256 f098c7d6b965e776030063e5ee051ba55ed2fefa8222a2e4f89107913c08f589

See more details on using hashes here.

File details

Details for the file pymeshfix-0.17.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for pymeshfix-0.17.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8bfa35b1105b3af6fee3e75e64da08bb82d9a92021277c02d3678639eeefe6ee
MD5 3d441e554d6fd2943c3ac5e9a357631a
BLAKE2b-256 0a767c3bd6eb9fa1e8f0580ae18bcc0e5279fd58440a76d6a879cd22630957ae

See more details on using hashes here.

File details

Details for the file pymeshfix-0.17.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pymeshfix-0.17.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e15ebfd8396f9504674391b81b0ec06f55640c04f212cb3a940463165e06910b
MD5 bccc0e76cceffc4409480757a100c2b3
BLAKE2b-256 3822a7548529770112a4b3980e2c06ec5c4618da537b6d236c01d0cc0f07c5c5

See more details on using hashes here.

File details

Details for the file pymeshfix-0.17.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pymeshfix-0.17.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fef1de0b0d250221b41b9f2df5cc381558ffae105c7de7a3a0c66559c43088e0
MD5 4aece3fb4ceb148b75f1582f85a5169a
BLAKE2b-256 56b08095d7e08a77c4d4e2b8eaf847bf539004ff8736ef0ed013ec20dc055b2e

See more details on using hashes here.

File details

Details for the file pymeshfix-0.17.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pymeshfix-0.17.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 dabe6b589dd71cf7314856ac6e7a861756c7d3b8dbc9d07cae3f74722e6ff00a
MD5 a24dab5a7667b918609a5aa951d98f67
BLAKE2b-256 1aeadaa383e947c7cbe69a76884b8c2ede4dc9910a7f3047dc70680c8df609f7

See more details on using hashes here.

File details

Details for the file pymeshfix-0.17.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for pymeshfix-0.17.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 df88f2bbdd43b72a067a557b080da8820e51adc9833e2eae8aa1373f204316f9
MD5 5b63c4a2ae16657fb24cd3829380f51b
BLAKE2b-256 259a7c233c7740d57ea99101cbfc63dddcff99bf96044eac3b6fea049ac5b4e0

See more details on using hashes here.

File details

Details for the file pymeshfix-0.17.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pymeshfix-0.17.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e66b870ba9143f1edd71ec945c4de7b0d4e8f54d184260d8fbf71b1eaa3a1065
MD5 392280ae9a2b3c73a33938d9b7007b8f
BLAKE2b-256 7be95932527c8d42bd9b7f6fa8ee2fa533cb6c8581caded5f01118191efea670

See more details on using hashes here.

File details

Details for the file pymeshfix-0.17.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pymeshfix-0.17.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0abd1e40836b8199fcdf2ced61e6f3cb4ce2e56406832238827d330dc9e580d4
MD5 2f4c7198bd143ff80190d83d3e736ebe
BLAKE2b-256 c6b0ffdef66d6873ac9dae2ec869d02cdafb03a3e447e68ac2274d096e35eba8

See more details on using hashes here.

File details

Details for the file pymeshfix-0.17.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pymeshfix-0.17.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 135d84ce6a1e98028fef672a199bf4d5eb38aa54959ab032de6bc107ff447207
MD5 a2696a3f28bf63b458e78916b9a2b28a
BLAKE2b-256 340bfe2df9514cb0b3f55729525c119c64bf8766b31e7f997c08d410ee962b9e

See more details on using hashes here.

File details

Details for the file pymeshfix-0.17.0-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for pymeshfix-0.17.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 dc9c41417a303e461cddc40d0bf5ff1359a891c4f0050a286223f60fc32435be
MD5 c90a98b7467976a3bde843963db0492c
BLAKE2b-256 b7ae4dca7c3bc6744605fbd70337860608660f2c6a840f4336e7a61d3fb14d90

See more details on using hashes here.

File details

Details for the file pymeshfix-0.17.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pymeshfix-0.17.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ab82020dfa9dfeb1894e3ed416bb7ea493bf0d78ba28f31d9d0ccf0c27e2384e
MD5 7254a9330fcf084136caabc4ab00b178
BLAKE2b-256 7ffc1560f2b1d674c7b2a3847fd64ae27dd4768c1cda0ddb5ac5012778aa337c

See more details on using hashes here.

File details

Details for the file pymeshfix-0.17.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pymeshfix-0.17.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d6549f5c856709888ed3c445b785c6ecb0372b0f649b879c222a62622ab3172b
MD5 db844164155ba2330b683635071f34ab
BLAKE2b-256 10f0dccdf11c3cec6e73fef444ecd9d7504ccd098944d3be2113b9da7a1ab993

See more details on using hashes here.

File details

Details for the file pymeshfix-0.17.0-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pymeshfix-0.17.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 370db90b316d304dac11974167e7da111f232b8bb7aae2a85affe723584bb7c1
MD5 e05382984ba1bdb4fc15c3ffd977c10d
BLAKE2b-256 66dc4240cbc68f19e42f8fdd7a07d78327108f0cbb029ed6a020765cfbc74b95

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page