sample_function#

sample_function(function: ~vtkmodules.vtkCommonDataModel.vtkImplicitFunction, bounds: ~typing.Sequence[float] = (-1.0, 1.0, -1.0, 1.0, -1.0, 1.0), dim: ~typing.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)[source]#

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
functionvtk.vtkImplicitFunction

Implicit function to evaluate. For example, the function generated from pyvista.perlin_noise().

boundslength 6 sequence

Specify the bounds in the format of:

  • (xmin, xmax, ymin, ymax, zmin, zmax)

Defaults to (-1.0, 1.0, -1.0, 1.0, -1.0, 1.0).

dimlength 3 sequence

Dimensions of the data on which to sample in the format of (xdim, ydim, zdim). Defaults to (50, 50, 50).

compute_normalsbool, optional

Enable or disable the computation of normals. Default False.

output_typenp.dtype, optional

Set the output scalar type. Defaults to np.double. 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, optional

Enable or disable capping. Default False. 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_valuefloat, optional

Capping value used with the capping parameter.

scalar_arr_namestr, optional

Set the scalar array name for this data set. Defaults to "scalars".

normal_arr_namestr, optional

Set the normal array name for this data set. Defaults to "normals".

progress_barbool, optional

Display a progress bar to indicate progress. Default False.

Returns
pyvista.UniformGrid

Uniform grid with sampled data.

Examples

Sample Perlin noise over a structured grid in 3D.

>>> import pyvista
>>> noise = pyvista.perlin_noise(0.1, (1, 1, 1), (0, 0, 0))
>>> grid = pyvista.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)
../../../_images/pyvista-core-imaging-sample_function-1_00_00.png

Sample Perlin noise in 2D and plot it.

>>> noise = pyvista.perlin_noise(0.1, (5, 5, 5), (0, 0, 0))
>>> surf = pyvista.sample_function(noise, dim=(200, 200, 1))
>>> surf.plot()
../../../_images/pyvista-core-imaging-sample_function-1_01_00.png

See Sample Function: Perlin Noise in 2D for a full example using this function.