pyransame.random_vertex_dataset#

pyransame.random_vertex_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 vertices with sampled data.

Note

This function is provided for completeness of API, but it is likely faster and more flexible to use a custom method.

Supported cell types:

  • Vertex

  • PolyVertex

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

Create a mesh with 1 vertex cell (1 point) and 1 polyvertex cell (5 points). Add data for y position.

>>> import pyransame
>>> import pyvista as pv
>>> p = [
...       [0., 0., 0.],
...       [1., 0., 0.],
...       [1., 1., 0.],
...       [1., 2., 0.],
...       [1., 3., 0.],
...       [1., 4., 0.],
... ]
>>> mesh = pv.PolyData(p, verts=[1, 0, 5, 1, 2, 3, 4, 5])
>>> mesh["y"] = mesh.points[:, 1]
>>> dataset = pyransame.random_vertex_dataset(mesh, n=3)

Now plot result.

>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(mesh, render_points_as_spheres=True, point_size=8.0, color='black')
>>> _ = pl.add_points(dataset, render_points_as_spheres=True, point_size=20.0, scalars="y")
>>> pl.view_xy()
>>> pl.show()
../_images/pyransame-random_vertex_dataset-1_00_00.png