Open banesullivan opened 5 years ago
There isn't really a shortcut for this, but maybe we could make one for both StructuredGrid
s and UniformGrid
s. Here is an example of subsampling a sturctured grid in a few different ways. The trick is simply reshaping the points
to the dimesnions
and properly iterating over them:
import pyvista as pv
import numpy as np
x = np.arange(-10, 10, 0.25)
y = np.arange(-10, 10, 0.25)
x, y = np.meshgrid(x, y)
r = np.sqrt(x ** 2 + y ** 2)
z = np.sin(r)
grid = pv.StructuredGrid(x, y, z)
grid.plot(show_edges=True)
# Structure the points into their grid
structured_points = grid.points.reshape((*grid.dimensions, 3))
# Get every step point in the grid
step = 3
subset_points = structured_points[::step, ::step, ::step, :]
xx = subset_points[:, :, :, 0]
yy = subset_points[:, :, :, 1]
zz = subset_points[:, :, :, 2]
subset = pv.StructuredGrid(xx, yy, zz)
subset.plot(show_edges=True)
# Or extract a VOI
subset_points = structured_points[:, 0:50, :, :]
xx = subset_points[:, :, :, 0]
yy = subset_points[:, :, :, 1]
zz = subset_points[:, :, :, 2]
subset = pv.StructuredGrid(xx, yy, zz)
subset.plot(show_edges=True)
@jsfraser1