pyvista / pyvista-support

[moved] Please head over to the Discussions tab of the PyVista repository
https://github.com/pyvista/pyvista/discussions
60 stars 4 forks source link

Unexcepted empty values in sampe result. #329

Closed 109021017 closed 3 years ago

109021017 commented 3 years ago
When I use the sample filter to sample the mesh, I found there are many holes in the sampling result. I extract a small part of a my model to reproduce this issue. As the image below shows, there's an area in the middle of a triangle cell where the sample result is empty. img
Left: original mesh. Right: the sampling result

The content of test.obj

v 16 17 2
v 16 0 2
v 0 16 2
v 0 10 2
v 0 17 2
v 0 10 2
v 0 9 2
v 0 8 2
v 15 4 2
v 16 4 2
v 15 5 2
v 16 5 2
v 16 6 2
v 15 7 2
v 16 7 2

f 5 1 3
f 3 2 4

Code:

plotter = pv.Plotter(shape=(1, 2))
mesh = pv.read('test.obj')
mesh.point_arrays['z'] = mesh.points[:, 2]

points = pv.PolyData(mesh.points)
points.point_arrays['point_id'] = np.arange(0, points.n_points)

plotter.add_mesh(mesh, scalars='z')
plotter.add_mesh(points, render_points_as_spheres=True)
plotter.show_axes()

resolution = 0.01
bounds = np.array(mesh.bounds).reshape([3, 2])
x = np.arange(bounds[0, 0], bounds[0, 1], resolution)
y = np.arange(bounds[1, 0], bounds[1, 1], resolution)
z = np.array([bounds[2, 0]])
x, y, z = np.meshgrid(x, y, z)
sample = pv.StructuredGrid(x, y, z).sample(mesh)
plotter.subplot(0, 1)
plotter.add_mesh(sample)
plotter.link_views()
img = plotter.show(cpos='xy', screenshot=True)[1]
109021017 commented 3 years ago

I change the smaple grid from pv.StructuredGrid to pv.UniformGrid, and the empty values are gone.