pyvista / pymeshfix

Python Wrapper for MeshFix: easily repair holes in surface meshes
http://pymeshfix.pyvista.org
GNU General Public License v3.0
279 stars 29 forks source link

Always triangulate input PolyData meshes #12

Closed banesullivan closed 4 years ago

banesullivan commented 4 years ago

Realized when addressing https://github.com/pyvista/pyvista-support/issues/71

https://github.com/pyvista/pymeshfix/blob/d8bb4e0ad93a92e9f489b860cbcf8b6f9eb6475c/pymeshfix/meshfix.py#L30-L32

That test does not always work. You can easily have a faces array that is a multiple of 4 but not all triangules. For example, a cylinder:

import pyvista as pv
import pymeshfix

cyl = pv.Cylinder(direction=(0.0, 0.0, 1.0), radius=1.0, height=5.0)
cyl_clipped = cyl.clip('z', value=1.0, 
                       origin=(0.0, 0.0, -2.5))
cyl_clipped.plot(show_edges=True)

download

But:

print(cyl_clipped.faces.size % 4)

0

so when you try to just pass that mesh tp MesFix, it segfaults because it thinks all cells are triangles when in fact they are not

fixer = pymeshfix.MeshFix(cyl_clipped)
fixer.repair()
repaired = fixer.mesh

Solution:

Always call .triangulate() on PyVista meshes - if it is already triangles, then it won't make a difference.