Skip to main content

Repairs triangular meshes

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.

Installation

From PyPI

pip install pymeshfix

From source at GitHub

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

Dependencies

Required: numpy, cython, vtkInterface

Minimum requirements are numpy and cython. To enable plotting and several other features, vtkInterface can be installed using:

pip install vtk

Tests

Test installation with the following from Python:

from pymeshfix import tests

# Test of pymeshfix without VTK module
tests.Native()

# Performs same mesh repair while leveraging VTK's plotting/mesh loading
tests.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.0.tar.gz (251.0 kB 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.0-cp36-cp36m-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.6mWindows x86-64

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

Uploaded CPython 3.6m

pymeshfix-0.11.0-cp35-cp35m-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.5mWindows x86-64

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

Uploaded CPython 3.5m

pymeshfix-0.11.0-cp27-cp27m-win_amd64.whl (2.5 MB view details)

Uploaded CPython 2.7mWindows x86-64

pymeshfix-0.11.0-cp27-cp27m-manylinux1_x86_64.whl (3.3 MB view details)

Uploaded CPython 2.7m

File details

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

File metadata

  • Download URL: pymeshfix-0.11.0.tar.gz
  • Upload date:
  • Size: 251.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pymeshfix-0.11.0.tar.gz
Algorithm Hash digest
SHA256 1a89d688327e4e4d2a4130d9276cd83ac8c14a64ecb075df90e5330acc18fdec
MD5 22a7fc8c18bc3d8d6d74c373faaf8945
BLAKE2b-256 98d0b9a3ad74845cc21251222fdb4297d581b2c7f06f0e67d42a1d8912aaa05e

See more details on using hashes here.

File details

Details for the file pymeshfix-0.11.0-cp36-cp36m-win_amd64.whl.

File metadata

File hashes

Hashes for pymeshfix-0.11.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 63dcfabb0532288fba346a73122203a54594dd62c7abbe5fb1a601d455b52e97
MD5 6387f003dfdec3e4c264d25f4e00d993
BLAKE2b-256 3aa1eb5e77076c7f348ea0ed8c9b16ce8555d1625cf8947f0df384bbff07560b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pymeshfix-0.11.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 01d1993eb47a37e059bd8139c820a7ac5f5fccd6c706c606e0405e03fc9832a3
MD5 6f6d86aae73720e8364f18c42d571ffe
BLAKE2b-256 6819970f7d39686a20176818b58a65a37d921d1332a0d2c4fb19e5e0134e5e3a

See more details on using hashes here.

File details

Details for the file pymeshfix-0.11.0-cp35-cp35m-win_amd64.whl.

File metadata

File hashes

Hashes for pymeshfix-0.11.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 4471ee44d928475397a9897aca452f51f8e3a19dc2f5a19572b5dbe6b9c00b66
MD5 4d36d23ac4549962388eb0bdbcfa6472
BLAKE2b-256 4e4c87d4d5b106852b41eb4e0d2c1ce80cfea13bdcaec102a1688ee6c7af29be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pymeshfix-0.11.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 8a5486fcd095dee60a45e684c51e77c0bb90a5924d5e8e893cb68dad91f85ab0
MD5 82de3c80fa987613e1442c3cfbea3cab
BLAKE2b-256 c869b8732d4f3dda815fe5894ef683fb79fba6d37719ed7aa95dafe4a358e8b1

See more details on using hashes here.

File details

Details for the file pymeshfix-0.11.0-cp27-cp27m-win_amd64.whl.

File metadata

File hashes

Hashes for pymeshfix-0.11.0-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 605604a24d524ea6e9e98eb04f41a12842c5304f8d7719d62139fbae3732b5d3
MD5 90b734c8344d6b20dc0fa35affe1d16c
BLAKE2b-256 2bd3c0bd4ed0cb2c2c2db91983f989ff7d459cff5f44ce4b7d2abd62b0a18b51

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pymeshfix-0.11.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 0f9db2c2d6ceb6f61379f7e0b1743736969a1ba404ed2c1c89d9771a1e6fe4dd
MD5 3d64d74478d4fae7e44147aed5ebd9cb
BLAKE2b-256 a88cf5a398273118c3885b43a8b4b50f9be190ee6b77eac6316de888e56d7946

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