pyvista.sample_function#
- sample_function(
- function: ~vtkmodules.vtkCommonDataModel.vtkImplicitFunction,
- bounds: ~collections.abc.Sequence[float] = (-1.0,
- 1.0,
- -1.0,
- 1.0,
- -1.0,
- 1.0),
- dim: ~collections.abc.Sequence[int] = (50,
- 50,
- 50),
- compute_normals: bool = False,
- output_type: ~numpy.dtype = <class 'numpy.float64'>,
- capping: bool = False,
- cap_value: float = 1.7976931348623157e+308,
- scalar_arr_name: str = 'scalars',
- normal_arr_name: str = 'normals',
- progress_bar: bool = False,
Sample an implicit function over a structured point set.
Uses
vtk.vtkSampleFunction
This method evaluates an implicit function and normals at each point in a
vtk.vtkStructuredPoints
. The user can specify the sample dimensions and location in space to perform the sampling.To create closed surfaces (in conjunction with the vtkContourFilter), capping can be turned on to set a particular value on the boundaries of the sample space.
- Parameters:
- function
vtk.vtkImplicitFunction
Implicit function to evaluate. For example, the function generated from
perlin_noise()
.- boundssequence[
float
], default: (-1.0, 1.0, -1.0, 1.0, -1.0, 1.0) Specify the bounds in the format of:
(x_min, x_max, y_min, y_max, z_min, z_max)
.
- dimsequence[
float
], default: (50, 50, 50) Dimensions of the data on which to sample in the format of
(xdim, ydim, zdim)
.- compute_normalsbool, default:
False
Enable or disable the computation of normals.
- output_type
numpy.dtype
, default:numpy.double
Set the output scalar type. One of the following:
np.float64
np.float32
np.int64
np.uint64
np.int32
np.uint32
np.int16
np.uint16
np.int8
np.uint8
- cappingbool, default:
False
Enable or disable capping. If capping is enabled, then the outer boundaries of the structured point set are set to cap value. This can be used to ensure surfaces are closed.
- cap_value
float
, default:sys.float_info.max
Capping value used with the
capping
parameter.- scalar_arr_name
str
, default: “scalars” Set the scalar array name for this data set.
- normal_arr_name
str
, default: “normals” Set the normal array name for this data set.
- progress_barbool, default:
False
Display a progress bar to indicate progress.
- function
- Returns:
pyvista.ImageData
Uniform grid with sampled data.
Examples
Sample Perlin noise over a structured grid in 3D.
>>> import pyvista as pv >>> noise = pv.perlin_noise(0.1, (1, 1, 1), (0, 0, 0)) >>> grid = pv.sample_function( ... noise, [0, 3.0, -0, 1.0, 0, 1.0], dim=(60, 20, 20) ... ) >>> grid.plot( ... cmap='gist_earth_r', show_scalar_bar=False, show_edges=True ... )
Sample Perlin noise in 2D and plot it.
>>> noise = pv.perlin_noise(0.1, (5, 5, 5), (0, 0, 0)) >>> surf = pv.sample_function(noise, dim=(200, 200, 1)) >>> surf.plot()
See Sample Function: Perlin Noise in 2D for a full example using this function.