pyransame.random_surface_dataset#

pyransame.random_surface_dataset(mesh: DataSet, n: int = 1, weights: str | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None = None) PolyData#

Generate random points on surface with sampled data.

Supported cell types:

  • Triangle

  • Triangle Strip

  • Pixel

  • Polygon

  • Quad

All cells must be convex.

Parameters:
meshpyvista.DataSet

The mesh for which to generate random points. Must have cells.

nint, default: 1

Number of random points to generate.

weightsstr, or array_like, optional

Weights to use for probability of choosing points inside each cell.

If a str is supplied, it will use the existing cell data on mesh.

Returns:
pointspv.PolyData

(n, 3) points that exist inside cells on mesh and with sampled data.

Examples

>>> import pyransame
>>> import pyvista as pv
>>> from pyvista import examples
>>> mesh = examples.download_bunny()
>>> mesh['y'] = mesh.points[:, 1]
>>> points = pyransame.random_surface_dataset(mesh, n=500)

Now plot result.

>>> cpos = [
...     (-0.07, 0.2, 0.5),
...     (-0.02, 0.1, -0.0),
...     (0.04, 1.0, -0.2),
... ]
>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(mesh, color='tan')
>>> _ = pl.add_points(points, scalars='y', render_points_as_spheres=True, point_size=10.0)
>>> pl.show(cpos=cpos)
../_images/pyransame-random_surface_dataset-1_00_00.png