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_repair_vtk():
meshin = pv.PolyData(bunny_scan)
meshfix = pymeshfix.MeshFix(meshin)
meshfix.repair()
# check arrays and output mesh
assert np.any(meshfix.v)
assert np.any(meshfix.f)
meshout = meshfix.mesh
assert meshfix.mesh.n_points
# test for any holes
pdata = meshout.extract_edges(non_manifold_edges=False, feature_edges=False,
manifold_edges=False)
assert pdata.n_points == 0
def with_vtk(plot=True):
""" Tests VTK interface and mesh repair of Stanford Bunny Mesh """
mesh = pv.PolyData(bunny_scan)
meshfix = pymeshfix.MeshFix(mesh)
if plot:
print('Plotting input mesh')
meshfix.plot()
meshfix.repair()
if plot:
print('Plotting repaired mesh')
meshfix.plot()
return meshfix.mesh
################################################################################
cow = examples.download_cow()
# Add holes and cast to triangulated PolyData
cow['random'] = np.random.rand(cow.n_cells)
holy_cow = cow.threshold(0.9, invert=True).extract_geometry().tri_filter()
print(holy_cow)
################################################################################
# A nice camera location of the cow
cpos= [(6.56, 8.73, 22.03),
(0.77, -0.44, 0.0),
(-0.13, 0.93, -0.35)]
meshfix = mf.MeshFix(holy_cow)
holes = meshfix.extract_holes()
# Render the mesh and outline the holes
p = pv.Plotter()
p.add_mesh(holy_cow, color=True)
p.add_mesh(holes, color='r', line_width=8)
p.camera_position = cpos
p.enable_eye_dome_lighting() # helps depth perception
p.show()
################################################################################
# Repair the holey cow
meshfix.repair(verbose=True)
################################################################################
cow = examples.download_cow()
# Add holes and cast to triangulated PolyData
cow['random'] = np.random.rand(cow.n_cells)
holy_cow = cow.threshold(0.9, invert=True).extract_geometry().tri_filter()
print(holy_cow)
################################################################################
# A nice camera location of the cow
cpos= [(6.56, 8.73, 22.03),
(0.77, -0.44, 0.0),
(-0.13, 0.93, -0.35)]
meshfix = mf.MeshFix(holy_cow)
holes = meshfix.extract_holes()
# Render the mesh and outline the holes
p = pv.Plotter()
p.add_mesh(holy_cow, color=True)
p.add_mesh(holes, color='r', line_width=8)
p.camera_position = cpos
p.enable_eye_dome_lighting() # helps depth perception
p.show()
################################################################################
# Repair the holey cow
meshfix.repair(verbose=True)
""" Functional Test: vtk and native """
t_start = time.time()
out_file = 'repaired.ply'
native()
outmesh = pv.PolyData(out_file)
os.remove(out_file)
assert outmesh.n_points
# test for any holes
pdata = outmesh.extract_edges(non_manifold_edges=False, feature_edges=False,
manifold_edges=False)
assert pdata.n_points == 0
# test vtk
meshin = pv.PolyData(bunny_scan)
meshfix = pymeshfix.MeshFix(meshin)
meshfix.repair()
# check arrays and output mesh
assert np.any(meshfix.v)
assert np.any(meshfix.f)
meshout = meshfix.mesh
assert meshfix.mesh.n_points
# test for any holes
pdata = meshout.extract_edges(non_manifold_edges=False, feature_edges=False,
manifold_edges=False)
print('PASS in %f seconds' % (time.time() - t_start))