Skip to main content
https://travis-ci.org/akaszynski/pymeshfix.svg?branch=master

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.

Installation

From PyPI

pip install pymeshfix

From source at GitHub

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

Dependencies

Requires numpy and vtki

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:

from pymeshfix import _meshfix

# Read mesh from infile and output cleaned mesh to outfile
_meshfix.CleanFromFile(infile, outfile)

This example assumes the user has vertex and faces arrays in Python. Again, no bells or whistles.

from pymeshfix import _meshfix

# Generate vertex and face arrays of cleaned mesh
vclean, fclean = CleanFromVF(v, f) # v and f are numpy arrays or python lists

Fuller 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.

#Load module
from pymeshfix import meshfix

# Create object from arrays or lists
meshfix = meshfix.MeshFixClass(v, f)
meshfix.LoadVF(v, f) #

# Plot input (if vtk is available)
meshfix.Plot()

# Repair input mesh
meshfix.Repair()

# Access the repaired mesh with vtk
meshfix.mesh

# Or, access the resulting arrays directly from the object
meshfix.v # numpy np.float 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 algorthim.

from pymeshfix import _meshfix

# Create TMesh object
tin = _meshfix.PyTMesh()

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

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

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

# Clean (removes self intersections)
tin.MeshClean(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.SaveFile(outfile)
# vclean, fclean = tin.ReturnArrays() # or return numpy arrays

Algorithim and Citation Policy

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

  1. 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.

Release files for pymeshfix 0.12.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pymeshfix 0.12.1
File Size Uploaded
pymeshfix-0.12.1.tar.gz 1.3 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for pymeshfix 0.12.1
File
pymeshfix-0.12.1-cp37-cp37m-manylinux1_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64 Details
pymeshfix-0.12.1-cp36-cp36m-manylinux1_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64 Details
pymeshfix-0.12.1-cp35-cp35m-manylinux1_x86_64.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64 Details
pymeshfix-0.12.1-cp27-cp27mu-manylinux1_x86_64.whl CPython 2.7 CPython 2.7 pymalloc wide-unicode Linux glibc 2.5+ x86-64 Details
pymeshfix-0.12.1-cp27-cp27m-manylinux1_x86_64.whl CPython 2.7 CPython 2.7 pymalloc Linux glibc 2.5+ x86-64 Details

Total release size: 11.7 MB

Release files / pymeshfix-0.12.1.tar.gz

Download URL pymeshfix-0.12.1.tar.gz
Size 1.3 MB
Tags Source
SHA-256 checksum
How to use checksums
d13d8813b0058b363cab7d21c2d84fabeb0d88f2b207e844a2ca69dd40906411
BLAKE2b-256 checksum
How to use checksums
71b1532afd89975f9285cfb1834c29c0f21f78556c20c8b96090aca81c7b397b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/38.2.4 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.3

Release files / pymeshfix-0.12.1-cp37-cp37m-manylinux1_x86_64.whl

Download URL pymeshfix-0.12.1-cp37-cp37m-manylinux1_x86_64.whl
Size 2.1 MB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
a579fdef6c17ed826f73aa95e3b5a77ee8af9c4ae549e1277e33c59e40ea965d
BLAKE2b-256 checksum
How to use checksums
878228bda6580f513f34433eff9cd0e9fec402ddb1a158c8ee030661e5f068b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/38.2.4 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.3

Release files / pymeshfix-0.12.1-cp36-cp36m-manylinux1_x86_64.whl

Download URL pymeshfix-0.12.1-cp36-cp36m-manylinux1_x86_64.whl
Size 2.1 MB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
3a3fe37d431f1245932112ce031e5df2aecb43c28161201defc56cfcfa05271d
BLAKE2b-256 checksum
How to use checksums
19b014e697a7047c0b38cb4c4151a574e6fe645bf1988709b71f41f6e165880f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/38.2.4 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.3

Release files / pymeshfix-0.12.1-cp35-cp35m-manylinux1_x86_64.whl

Download URL pymeshfix-0.12.1-cp35-cp35m-manylinux1_x86_64.whl
Size 2.1 MB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
e204c3742727a58bde52fdce0a5e9bd81685957153edc1fb11fd2530586197f5
BLAKE2b-256 checksum
How to use checksums
638e0c3caa2b4c97513dcf6681277d2da3e3f5dc28cb7585c6218812885e7c10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/38.2.4 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.3

Release files / pymeshfix-0.12.1-cp27-cp27mu-manylinux1_x86_64.whl

Download URL pymeshfix-0.12.1-cp27-cp27mu-manylinux1_x86_64.whl
Size 2.1 MB
Tags CPython 2.7 CPython 2.7 pymalloc wide-unicode Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
8350ca00cd2631d483ff41c7a42e46f0631ba4520a2ce4718f10a6f7c3cd42f6
BLAKE2b-256 checksum
How to use checksums
36978269d1c3da70e368a58206f6f6edc8f0a2c41dd990cb9b3baa2cfeca4f7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/38.2.4 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.3

Release files / pymeshfix-0.12.1-cp27-cp27m-manylinux1_x86_64.whl

Download URL pymeshfix-0.12.1-cp27-cp27m-manylinux1_x86_64.whl
Size 2.1 MB
Tags CPython 2.7 CPython 2.7 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
a23fcddc2566f1d17aa2663b9726daf0f37e66dde0b0f665aa5ae64675b3164c
BLAKE2b-256 checksum
How to use checksums
1f111ea2ff498ac0423143d759f1f65562d9e2a60abe4d2dcfbc8334d0a0bc6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/38.2.4 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.3
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page