Package: pymeshfix
Python/Cython wrapper of Marco Attene’s wonderful, award-winningMeshFixsoftware.
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 2020InstallationFromPyPIpipinstallpymeshfixFrom source atGitHubgitclonehttps://github.com/pyvista/pymeshfixcdpymeshfixpipinstall.DependenciesRequiresnumpyandpyvistaIf you can’t or don’t want to install vtk, you can install it withoutpyvistawith:pipinstallpymeshfix--no-dependenciesYou’ll miss out on some of the cool features frompyvista, but it will still function.ExamplesTest installation with the following from Python:frompymeshfiximportexamples# Test of pymeshfix without VTK moduleexamples.native()# Performs same mesh repair while leveraging VTK's plotting/mesh loadingexamples.with_vtk()Easy ExampleThis example uses the Cython wrapper directly. No bells or whistles here:importpymeshfix# Read mesh from infile and output cleaned mesh to outfilepymeshfix.clean_from_file(infile,outfile)This example assumes the user has vertex and faces arrays in Python.importpymeshfix# Generate vertex and face arrays of cleaned mesh# where v and f are numpy arraysvclean,fclean=pymeshfix.clean_from_arrays(v,f)Complete Examples with and without VTKOne 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.importpymeshfix# Create object from vertex and face arraysmeshfix=pymeshfix.MeshFix(v,f)# Plot inputmeshfix.plot()# Repair input meshmeshfix.repair()# Access the repaired mesh with vtkmesh=meshfix.mesh# Or, access the resulting arrays directly from the objectmeshfix.v# numpy np.float64 arraymeshfix.f# numpy np.int32 array# View the repaired mesh (requires vtkInterface)meshfix.plot()# Save the meshmeshfix.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.importpymeshfix# Create TMesh objecttin=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 holestin.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 againprint('There are{:d}boundaries'.format(tin.boundaries()))# Clean again if necessary...# Output meshtin.save_file(outfile)# or return numpy arraysvclean,fclean=tin.return_arrays()Algorithm and Citation PolicyTo 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-3This 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.CopyrightMeshFix is Copyright(C) 2010: IMATI-GE / CNRAll rights reserved.This program is dual-licensed as follows:(1) You may use MeshFix as free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option) any
later version.In this case the program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
(http://www.gnu.org/licenses/gpl.txt) for more details.(2) You may use MeshFix as part of a commercial software. In this case a proper
agreement must be reached with the Authors and with IMATI-GE/CNR based on a
proper licensing contract.