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 --recursive https://github.com/akaszynski/pymeshfix
cd pymeshfix
pip install .

Dependencies

Required: numpy, cython. Optional: vtk

Minimum requirements are numpy and cython. To enable plotting and several other features, vtk 5.0 or greater must be installed with Python bindings. VTK can be installed through a variety of methods. Please see http://www.vtk.org/

Tests

Test installation with the following from Python

from pymeshfix import Tests

# Test of pymeshfix without VTK module
Tests.Fix.Native()

# Performs same mesh repair while leveraging VTK's plotting/mesh loading
Tests.Fix.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
mfobj = meshfix.MeshFixClass()
mfobj.LoadVF(v, f) # from arrays or lists
#mfobj.LoadFile(filename) # or from file
#mfobj.LoadMesh(vtkpoly) # or from a vtk.vtkPolyData object

# Plot input (if vtk is available)
mfobj.DisplayInputSurface()

# Repair input mesh
mfobj.Repair()

# Generate vtk output mesh\
mfobj.GenFixedMesh() # creates mfobj.grid

# Or, access the resulting arrays directly from the object
mfobj.vclean # numpy np.float array
mfobj.fclean # numpy np.int32 array

# View the repaired mesh
mfobj.DisplayFixedSurface()

# Save the mesh
mfobj.SaveFixedMesh('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) # can also 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() # returns numpy arrays

Algorithim 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.10.tar.gz (1.4 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.10-cp35-cp35m-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.5mWindows x86-64

pymeshfix-0.10-cp27-cp27m-win_amd64.whl (1.4 MB view details)

Uploaded CPython 2.7mWindows x86-64

File details

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

File metadata

  • Download URL: pymeshfix-0.10.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pymeshfix-0.10.tar.gz
Algorithm Hash digest
SHA256 42d31d492f23f4d48202dcf161db3b72f04041380b5de325b9d4bb9c98338606
MD5 1ca477c4cf3ac4944824f0b71a0c4bf0
BLAKE2b-256 94dd41c4d116f0df6b45978524789161614d4c3a4dc083fc5834183f82697ab1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pymeshfix-0.10-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 3bf185a19790598815503328ed689cd5bf91df5e7c6761121d09ff5908991911
MD5 3a319d3320e18da3ad13a20df4361764
BLAKE2b-256 feb41bc643b1768ea8da4fbf63098039c2055c130704e457ac7e4bb3a7965166

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pymeshfix-0.10-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 ce5f7fb863f4a2b16262e0c13433b7fffdce8be13ab194ac9f4acfe16bdd99ed
MD5 08a3fa8373dfe68114532dd86be6ea66
BLAKE2b-256 6887c3ca6955c15532795e028d9bfb1aa4df29b6ecf1de63ae474862b43f10ea

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