pyvista.wrap#
- wrap( ) pyvista.DataSet | pyvista.pyvista_ndarray | None [source]#
Wrap any given VTK data object to its appropriate PyVista data object.
Other formats that are supported include:
2D
numpy.ndarray
of XYZ vertices3D
numpy.ndarray
representing a volume. Values will be scalars.3D
trimesh.Trimesh
mesh.3D
meshio.Mesh
mesh.
Changed in version 0.38.0: If the passed object is already a wrapped PyVista object, then this is no-op and will return that object directly. In previous versions of PyVista, this would perform a shallow copy.
- Parameters:
- dataset
numpy.ndarray
|trimesh.Trimesh
|vtk.DataSet
Dataset to wrap.
- dataset
- Returns:
pyvista.DataSet
The PyVista wrapped dataset.
Examples
Wrap a numpy array representing a random point cloud.
>>> import numpy as np >>> import pyvista as pv >>> points = np.random.default_rng().random((10, 3)) >>> cloud = pv.wrap(points) >>> cloud PolyData (...) N Cells: 10 N Points: 10 N Strips: 0 X Bounds: ... Y Bounds: ... Z Bounds: ... N Arrays: 0
Wrap a VTK object.
>>> import pyvista as pv >>> import vtk >>> points = vtk.vtkPoints() >>> p = [1.0, 2.0, 3.0] >>> vertices = vtk.vtkCellArray() >>> pid = points.InsertNextPoint(p) >>> _ = vertices.InsertNextCell(1) >>> _ = vertices.InsertCellPoint(pid) >>> point = vtk.vtkPolyData() >>> _ = point.SetPoints(points) >>> _ = point.SetVerts(vertices) >>> mesh = pv.wrap(point) >>> mesh PolyData (...) N Cells: 1 N Points: 1 N Strips: 0 X Bounds: 1.000e+00, 1.000e+00 Y Bounds: 2.000e+00, 2.000e+00 Z Bounds: 3.000e+00, 3.000e+00 N Arrays: 0
Wrap a Trimesh object.
>>> import trimesh >>> import pyvista as pv >>> points = [[0, 0, 0], [0, 0, 1], [0, 1, 0]] >>> faces = [[0, 1, 2]] >>> tmesh = trimesh.Trimesh(points, faces=faces, process=False) >>> mesh = pv.wrap(tmesh) >>> mesh PolyData (0x7fc55ff27ad0) N Cells: 1 N Points: 3 X Bounds: 0.000e+00, 0.000e+00 Y Bounds: 0.000e+00, 1.000e+00 Z Bounds: 0.000e+00, 1.000e+00 N Arrays: 0