Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_select_intersecting_triangles():
meshfix = _meshfix.PyTMesh(quiet=0)
meshfix.load_file(examples.bunny_scan)
faces = meshfix.select_intersecting_triangles()
assert faces.any()
def test_remove_components():
meshfix = _meshfix.PyTMesh()
meshfix.load_file(examples.bunny_scan)
assert meshfix.remove_smallest_components()
def test_load_array():
meshfix = _meshfix.PyTMesh()
v = bunny.points
with pytest.raises(Exception):
meshfix.load_array(v, bunny.faces)
f = bunny.faces.reshape(-1, 4)[:, 1:]
meshfix.load_array(v, f)
v, f = meshfix.return_arrays()
assert f.shape[0] == bunny.n_faces
with pytest.raises(Exception):
meshfix.load_array(v, f)
def test_fill_small_boundaries():
meshfix = _meshfix.PyTMesh()
meshfix.load_file(examples.bunny_scan)
ninit_boundaries = meshfix.boundaries()
meshfix.fill_small_boundaries(refine=False)
assert meshfix.boundaries() < ninit_boundaries
from vtkplotter import Plotter, boundaries
try:
# Credits:
# https://github.com/MarcoAttene/MeshFix-V2.1
# https://github.com/akaszynski/pymeshfix
from pymeshfix._meshfix import PyTMesh, Repair
from pymeshfix.examples import bunny_scan
except:
print('Install pymeshfix with: pip install pymeshfix')
exit()
########################################### PyTMesh repair
inputmesh = bunny_scan # 'pymeshfix/examples/StanfordBunny.ply'
ouputmesh = 'meshfix_repaired.ply' # try e.g. vtkconvert -to vtk repaired.ply
tm = PyTMesh()
tm.LoadFile(inputmesh)
Repair(tm, verbose=True, joincomp=True, removeSmallestComponents=True)
tm.SaveFile(ouputmesh)
########################################### vtkplotter
vp = Plotter(shape=(2,1))
act_original = vp.load(inputmesh)
bo = boundaries(act_original)
act_repaired = vp.load(ouputmesh)
br = boundaries(act_repaired)
vp.show([act_original, bo], at=0)
vp.show([act_repaired, br], at=1, interactive=1)