Skip to main content

Repairs triangular meshes

Project description

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 vtkInterface

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

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.

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.11.1.tar.gz (1.3 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pymeshfix-0.11.1-cp36-cp36m-manylinux1_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.6m

pymeshfix-0.11.1-cp35-cp35m-manylinux1_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.5m

pymeshfix-0.11.1-cp27-cp27mu-manylinux1_x86_64.whl (2.1 MB view details)

Uploaded CPython 2.7mu

pymeshfix-0.11.1-cp27-cp27m-manylinux1_x86_64.whl (2.1 MB view details)

Uploaded CPython 2.7m

File details

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

File metadata

  • Download URL: pymeshfix-0.11.1.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/38.2.4 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.3

File hashes

Hashes for pymeshfix-0.11.1.tar.gz
Algorithm Hash digest
SHA256 9a2e36e7cf7cfa8c59fadaa9098a8b54f0b223903a924606b1b61dfb2f9bc757
MD5 0f3b89ac3b730537692c8097f2637a20
BLAKE2b-256 372b6ea317d5386ab2532a232aa0f39b41641c228b858bf5ebe1fb782ba4bc63

See more details on using hashes here.

File details

Details for the file pymeshfix-0.11.1-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pymeshfix-0.11.1-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/38.2.4 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.3

File hashes

Hashes for pymeshfix-0.11.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 bafb6039d37a73446bbee2ccfd9925d25ec9c67ae0cfd9ca3ff989599c43d6cd
MD5 3d39ffa05f1cef09d6c8101582b063f3
BLAKE2b-256 327571ff97cdfae6054084c54c06887e2f76877903a128d5c9eb3240a709137b

See more details on using hashes here.

File details

Details for the file pymeshfix-0.11.1-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pymeshfix-0.11.1-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/38.2.4 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.3

File hashes

Hashes for pymeshfix-0.11.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 cf2d7f7620b303e2cfaca024aac0aaaaeeb580222984572cf9225a28f590d856
MD5 34d9832a903d1fde3c37005e5eaaadbe
BLAKE2b-256 eea0a915ec7dbef0d48252d5650304cf89023f72859257f1d54faa80402f8c8b

See more details on using hashes here.

File details

Details for the file pymeshfix-0.11.1-cp27-cp27mu-manylinux1_x86_64.whl.

File metadata

  • Download URL: pymeshfix-0.11.1-cp27-cp27mu-manylinux1_x86_64.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: CPython 2.7mu
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/38.2.4 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.3

File hashes

Hashes for pymeshfix-0.11.1-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 87a77178afee56a6ba735a16152129df7a57d108018df1dc33b8ec6ecb61eef6
MD5 79c7b2795fc7fe888f2bead6aef4f053
BLAKE2b-256 2abe7f4ba9591f330b532ef3b03bef56ebe8fba813862d26ec40be6611f76590

See more details on using hashes here.

File details

Details for the file pymeshfix-0.11.1-cp27-cp27m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pymeshfix-0.11.1-cp27-cp27m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: CPython 2.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/38.2.4 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.3

File hashes

Hashes for pymeshfix-0.11.1-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 5db5df14896a8f4c0581f1445bb7cd0adfc6a664d58b898d9e21f86895d415aa
MD5 b95ae59283203acc6042b0a675d6e5c9
BLAKE2b-256 e536353da50a938d2e1e7b929d8cffa7e9240bf1ddff75f6f93c41e507130d8c

See more details on using hashes here.

Supported by

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