• Stars
    star
    262
  • Rank 155,248 (Top 4 %)
  • Language
    C++
  • License
    GNU General Publi...
  • Created almost 8 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python Wrapper for MeshFix: easily repair holes in surface meshes

PyMeshFix

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.

C++ source last updated 1 Jul 2020

Installation

From PyPI

pip install pymeshfix

From source at GitHub

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

Dependencies

Requires numpy and pyvista

If you can't or don't want to install vtk, you can install it without pyvista with:

pip install pymeshfix --no-dependencies

You'll miss out on some of the cool features from pyvista, but it will still function.

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:

import pymeshfix

# Read mesh from infile and output cleaned mesh to outfile
pymeshfix.clean_from_file(infile, outfile)

This example assumes the user has vertex and faces arrays in Python.

import pymeshfix

# Generate vertex and face arrays of cleaned mesh
# where v and f are numpy arrays
vclean, fclean = pymeshfix.clean_from_arrays(v, f)

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

import pymeshfix

# Create object from vertex and face arrays
meshfix = pymeshfix.MeshFix(v, f)

# Plot input
meshfix.plot()

# Repair input mesh
meshfix.repair()

# Access the repaired mesh with vtk
mesh = meshfix.mesh

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

import pymeshfix

# Create TMesh object
tin = 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 holes
tin.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 again
print('There are {:d} boundaries'.format(tin.boundaries()))

# Clean again if necessary...

# Output mesh
tin.save_file(outfile)

 # or return numpy arrays
vclean, fclean = tin.return_arrays()

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

Copyright

MeshFix is Copyright(C) 2010: IMATI-GE / CNR

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

More Repositories

1

pyvista

3D plotting and mesh analysis through a streamlined interface for the Visualization Toolkit (VTK)
Python
2,543
star
2

tetgen

A Python interface to the C++ TetGen library to generate tetrahedral meshes of any 3D polyhedral domains
C++
212
star
3

pyacvd

Python implementation of surface mesh resampling algorithm ACVD
Cython
164
star
4

pyvistaqt

Qt support for PyVista
Python
98
star
5

pyvista-xarray

xarray DataArray accessors for PyVista
Python
97
star
6

fast-simplification

Fast Quadratic Mesh Simplification
C++
79
star
7

pyvista-support

[moved] Please head over to the Discussions tab of the PyVista repository
59
star
8

pyvista-tutorial

PyVista SciPy 2022-2024 Tutorial
Python
41
star
9

vtk-data

PyVista example data - These are used for examples in both PyVista and PVGeo
G-code
34
star
10

pyiges

Python IGES Reader
Python
34
star
11

scikit-gmsh

Scikit for Gmsh to generate 3D finite element mesh
Python
21
star
12

pyvista-reality

OpenVR and OpenXR variants of PyVista
Python
16
star
13

setup-headless-display-action

GitHub Action to setup a headless display on Linux and Windows (not needed on MacOS)
PowerShell
14
star
14

pytest-pyvista

Plugin to test PyVista plot outputs
Python
13
star
15

pyvista-gui

A Graphical User Interface built atop PyVista
Python
12
star
16

pyvistaqt-exe

Create a Windows installable exe from a PyVistaQt application
Python
10
star
17

pyvista-wheels

VTK wheels for PyVista
Python
8
star
18

pyvista-examples

A place where we host the Jupyter notebooks found in the PyVista docs for use on MyBinder - this repo is automatically deployed by our CI robot friends - NO PRs HERE PLEASE
Dockerfile
8
star
19

vtkjs-viewer

This repo is strictly for the purpose of hosting the vtk.js standalone web viewer
JavaScript
7
star
20

streamlit-pyvista

Python
6
star
21

gl-ci-helpers

Continuous integration helper scripts for your 3D visualization needs
PowerShell
6
star
22

pyvista-fastapi-webapp

Demo FastAPI and Three.js application using PyVista
TypeScript
6
star
23

pyvista-doc-translations

translated docs for pyvista official document
Jupyter Notebook
4
star
24

pyvista-docs-dev

A place where we host the most up to date development documentation for PyVista
HTML
3
star
25

show-room

[WIP] A set of domain specific examples to showcase how PyVista can be used
Jupyter Notebook
3
star
26

cookiecutter-pyvista-binder

This is a Cookiecutter for using PyVista on the notebook hosting service MyBinder.
Jupyter Notebook
3
star
27

pyvista-docs-dynamic

3
star
28

pyminiply

Wrapper over the excellent and fast miniply to read PLY files
Python
3
star
29

pytetwild

Python wrapper for fTetWild
C++
3
star
30

pyvista-tutorial-translations

translated docs for pyvista official tutorial
Jupyter Notebook
2
star
31

pyvista-tutorial-ja

A place where we host the most up to date tutorial for PyVista
2
star
32

stl-reader

Fast STL file reader
C
2
star
33

npt-promote

Mypy plugin to add type promotions between NumPy and builtin data types.
Python
2
star
34

pyvista-optimized

Cython optimizations and overrides to PyVista
2
star
35

pyvista-media

PostScript
1
star
36

multiversion-docs-testing

1
star
37

awesome-pyvista

A curated list of awesome stuff related to PyVista 😎
1
star
38

pyvista-osmnx

1
star
39

pyvista-doc-example

Example Documentation build using PyVista
1
star
40

pyvista-docs-dev-ja

1
star
41

pyvista-docs-archive

A place where we automatically deploy the PyVista documentation
HTML
1
star
42

pyvista-bot

Python
1
star
43

pyvista-docs

Main Netlify site for our documentation deployment
HTML
1
star
44

examples

`pyvista-examples` contains a variety of built-in demos and downloadable example datasets.
Python
1
star
45

streamlit-stlviewer

Python
1
star