interpolate#
- PolyData.interpolate(target, sharpness=2, radius=1.0, strategy='null_value', null_value=0.0, n_points=None, pass_cell_arrays=True, pass_point_data=True, progress_bar=False)#
Interpolate values onto this mesh from a given dataset.
The input dataset is typically a point cloud.
This uses a Gaussian interpolation kernel. Use the
sharpness
andradius
parameters to adjust this kernel. You can also switch this kernel to use an N closest points approach.- Parameters
- target
pyvista.DataSet
The vtk data object to sample from. Point and cell arrays from this object are interpolated onto this mesh.
- sharpness
float
,optional
Set the sharpness (i.e., falloff) of the Gaussian kernel. By default
sharpness=2
. As the sharpness increases the effects of distant points are reduced.- radius
float
,optional
Specify the radius within which the basis points must lie.
- strategy
str
,optional
Specify a strategy to use when encountering a “null” point during the interpolation process. Null points occur when the local neighborhood (of nearby points to interpolate from) is empty. If the strategy is set to
'mask_points'
, then an output array is created that marks points as being valid (=1) or null (invalid =0) (and the NullValue is set as well). If the strategy is set to'null_value'
(this is the default), then the output data value(s) are set to thenull_value
(specified in the output point data). Finally, the strategy'closest_point'
is to simply use the closest point to perform the interpolation.- null_value
float
,optional
Specify the null point value. When a null point is encountered then all components of each null tuple are set to this value. By default the null value is set to zero.
- n_points
int
,optional
If given, specifies the number of the closest points used to form the interpolation basis. This will invalidate the radius argument in favor of an N closest points approach. This typically has poorer results.
- pass_cell_arraysbool,
optional
Preserve input mesh’s original cell data arrays.
- pass_point_databool,
optional
Preserve input mesh’s original point data arrays.
- progress_barbool,
optional
Display a progress bar to indicate progress.
- target
- Returns
pyvista.DataSet
Interpolated dataset. Return type matches input.
Examples
Interpolate the values of 5 points onto a sample plane.
>>> import pyvista >>> import numpy as np >>> np.random.seed(7) >>> point_cloud = np.random.random((5, 3)) >>> point_cloud[:, 2] = 0 >>> point_cloud -= point_cloud.mean(0) >>> pdata = pyvista.PolyData(point_cloud) >>> pdata['values'] = np.random.random(5) >>> plane = pyvista.Plane() >>> plane.clear_data() >>> plane = plane.interpolate(pdata, sharpness=3) >>> pl = pyvista.Plotter() >>> _ = pl.add_mesh(pdata, render_points_as_spheres=True, point_size=50) >>> _ = pl.add_mesh(plane, style='wireframe', line_width=5) >>> pl.show()
See Interpolating for more examples using this filter.