pyvista.UnstructuredGrid#

class UnstructuredGrid(*args, deep=False, **kwargs)[source]#

Dataset used for arbitrary combinations of all possible cell types.

Can be initialized by the following:

  • Creating an empty grid

  • From a vtk.vtkPolyData or vtk.vtkStructuredGrid object

  • From cell, offset, and node arrays

  • From a file

Parameters:
argsvarious

See below examples.

deepoptional

Whether to deep copy a vtkUnstructuredGrid object. Default is False. Keyword only.

Examples

>>> import pyvista
>>> from pyvista import examples
>>> import vtk

Create an empty grid

>>> grid = pyvista.UnstructuredGrid()

Copy a vtk.vtkUnstructuredGrid

>>> vtkgrid = vtk.vtkUnstructuredGrid()
>>> grid = pyvista.UnstructuredGrid(vtkgrid)

From a filename.

>>> grid = pyvista.UnstructuredGrid(examples.hexbeamfile)
>>> grid.plot(show_edges=True)
../../../_images/pyvista-UnstructuredGrid-1_00_00.png

From arrays (VTK >= 9). Here we create a single tetrahedron.

>>> cells = [4, 0, 1, 2, 3]
>>> celltypes = [pyvista.CellType.TETRA]
>>> points = [
...     [1.0, 1.0, 1.0],
...     [1.0, -1.0, -1.0],
...     [-1.0, 1.0, -1.0],
...     [-1.0, -1.0, 1.0],
... ]
>>> grid = pyvista.UnstructuredGrid(cells, celltypes, points)
>>> grid.plot(show_edges=True)
../../../_images/pyvista-UnstructuredGrid-1_01_00.png

See the Creating an Unstructured Grid example for more details on creating unstructured grids within PyVista.

Methods

UnstructuredGrid.add_field_array(scalars, name)

Add field data.

UnstructuredGrid.add_field_data(array, name)

Add field data.

UnstructuredGrid.cast_to_explicit_structured_grid()

Cast to an explicit structured grid.

UnstructuredGrid.cast_to_pointset([deep])

Get a new representation of this object as a pyvista.PointSet.

UnstructuredGrid.cast_to_unstructured_grid()

Get a new representation of this object as a pyvista.UnstructuredGrid.

UnstructuredGrid.cell_bounds(ind)

Return the bounding box of a cell.

UnstructuredGrid.cell_centers([vertex, ...])

Generate points at the center of the cells in this dataset.

UnstructuredGrid.cell_data_to_point_data([...])

Transform cell data into point data.

UnstructuredGrid.cell_n_points(ind)

Return the number of points in a cell.

UnstructuredGrid.cell_point_ids(ind)

Return the point ids in a cell.

UnstructuredGrid.cell_points(ind)

Return the points in a cell.

UnstructuredGrid.cell_type(ind)

Return the type of a cell.

UnstructuredGrid.center_of_mass([scalars_weight])

Return the coordinates for the center of mass of the mesh.

UnstructuredGrid.clear_arrays()

Remove all arrays from point/cell/field data.

UnstructuredGrid.clear_cell_arrays()

Remove all cell data.

UnstructuredGrid.clear_cell_data()

Remove all cell arrays.

UnstructuredGrid.clear_data()

Remove all arrays from point/cell/field data.

UnstructuredGrid.clear_field_arrays()

Remove all field data.

UnstructuredGrid.clear_field_data()

Remove all field data.

UnstructuredGrid.clear_point_arrays()

Remove all point data.

UnstructuredGrid.clear_point_data()

Remove all point arrays.

UnstructuredGrid.clear_textures()

Clear the textures from this mesh.

UnstructuredGrid.clip([normal, origin, ...])

Clip a dataset by a plane by specifying the origin and normal.

UnstructuredGrid.clip_box([bounds, invert, ...])

Clip a dataset by a bounding box defined by the bounds.

UnstructuredGrid.clip_scalar([scalars, ...])

Clip a dataset by a scalar.

UnstructuredGrid.clip_surface(surface[, ...])

Clip any mesh type using a pyvista.PolyData surface mesh.

UnstructuredGrid.compute_cell_quality([...])

Compute a function of (geometric) quality for each cell of a mesh.

UnstructuredGrid.compute_cell_sizes([...])

Compute sizes for 1D (length), 2D (area) and 3D (volume) cells.

UnstructuredGrid.compute_derivative([...])

Compute derivative-based quantities of point/cell scalar field.

UnstructuredGrid.compute_implicit_distance(surface)

Compute the implicit distance from the points to a surface.

UnstructuredGrid.connectivity([largest, ...])

Find and label connected bodies/volumes.

UnstructuredGrid.contour([isosurfaces, ...])

Contour an input self by an array.

UnstructuredGrid.copy([deep])

Return a copy of the object.

UnstructuredGrid.copy_attributes(dataset)

Copy the data attributes of the input dataset object.

UnstructuredGrid.copy_from(mesh)

Overwrite this dataset inplace with the new dataset's geometries and data.

UnstructuredGrid.copy_meta_from(ido[, deep])

Copy pyvista meta data onto this object from another object.

UnstructuredGrid.copy_structure(dataset)

Copy the structure (geometry and topology) of the input dataset object.

UnstructuredGrid.ctp([pass_cell_data, ...])

Transform cell data into point data.

UnstructuredGrid.decimate_boundary([...])

Return a decimated version of a triangulation of the boundary.

UnstructuredGrid.deep_copy(to_copy)

Overwrite this data object with another data object as a deep copy.

UnstructuredGrid.delaunay_2d([tol, alpha, ...])

Apply a 2D Delaunay filter along the best fitting plane.

UnstructuredGrid.delaunay_3d([alpha, tol, ...])

Construct a 3D Delaunay triangulation of the mesh.

UnstructuredGrid.elevation([low_point, ...])

Generate scalar values on a dataset.

UnstructuredGrid.explode([factor])

Push each individual cell away from the center of the dataset.

UnstructuredGrid.extract_all_edges([...])

Extract all the internal/external edges of the dataset as PolyData.

UnstructuredGrid.extract_cells(ind[, ...])

Return a subset of the grid.

UnstructuredGrid.extract_feature_edges([...])

Extract edges from the surface of the mesh.

UnstructuredGrid.extract_geometry([extent, ...])

Extract the outer surface of a volume or structured grid dataset.

UnstructuredGrid.extract_largest([inplace, ...])

Extract largest connected set in mesh.

UnstructuredGrid.extract_points(ind[, ...])

Return a subset of the grid (with cells) that contains any of the given point indices.

UnstructuredGrid.extract_surface([...])

Extract surface mesh of the grid.

UnstructuredGrid.find_cells_along_line(...)

Find the index of cells in this mesh along a line.

UnstructuredGrid.find_cells_within_bounds(bounds)

Find the index of cells in this mesh within bounds.

UnstructuredGrid.find_closest_cell(point[, ...])

Find index of closest cell in this mesh to the given point.

UnstructuredGrid.find_closest_point(point[, n])

Find index of closest point in this mesh to the given point.

UnstructuredGrid.find_containing_cell(point)

Find index of a cell that contains the given point.

UnstructuredGrid.flip_normal(normal[, ...])

Flip mesh about the normal.

UnstructuredGrid.flip_x([point, ...])

Flip mesh about the x-axis.

UnstructuredGrid.flip_y([point, ...])

Flip mesh about the y-axis.

UnstructuredGrid.flip_z([point, ...])

Flip mesh about the z-axis.

UnstructuredGrid.get_array(name[, preference])

Search both point, cell and field data for an array.

UnstructuredGrid.get_array_association(name)

Get the association of an array.

UnstructuredGrid.get_data_range([arr_var, ...])

Get the non-NaN min and max of a named array.

UnstructuredGrid.glyph([orient, scale, ...])

Copy a geometric representation (called a glyph) to the input dataset.

UnstructuredGrid.head([display, html])

Return the header stats of this dataset.

UnstructuredGrid.integrate_data([progress_bar])

Integrate point and cell data.

UnstructuredGrid.interpolate(target[, ...])

Interpolate values onto this mesh from a given dataset.

UnstructuredGrid.linear_copy([deep])

Return a copy of the unstructured grid containing only linear cells.

UnstructuredGrid.merge([grid, merge_points, ...])

Join one or many other grids to this grid.

UnstructuredGrid.outline([generate_faces, ...])

Produce an outline of the full extent for the input dataset.

UnstructuredGrid.outline_corners([factor, ...])

Produce an outline of the corners for the input dataset.

UnstructuredGrid.overwrite(mesh)

Overwrite this dataset inplace with the new dataset's geometries and data.

UnstructuredGrid.partition(n_partitions[, ...])

Break down input dataset into a requested number of partitions.

UnstructuredGrid.plot([off_screen, ...])

Plot a PyVista, numpy, or vtk object.

UnstructuredGrid.plot_curvature([curv_type])

Plot the curvature of the external surface of the grid.

UnstructuredGrid.plot_over_circular_arc(...)

Sample a dataset along a circular arc and plot it.

UnstructuredGrid.plot_over_circular_arc_normal(center)

Sample a dataset along a resolution circular arc defined by a normal and polar vector and plot it.

UnstructuredGrid.plot_over_line(pointa, pointb)

Sample a dataset along a high resolution line and plot.

UnstructuredGrid.point_data_to_cell_data([...])

Transform point data into cell data.

UnstructuredGrid.point_is_inside_cell(ind, point)

Return whether one or more points are inside a cell.

UnstructuredGrid.points_to_double()

Convert the points datatype to double precision.

UnstructuredGrid.probe(points[, tolerance, ...])

Sample data values at specified point locations.

UnstructuredGrid.ptc([pass_point_data, ...])

Transform point data into cell data.

UnstructuredGrid.reconstruct_surface([...])

Reconstruct a surface from the points in this dataset.

UnstructuredGrid.reflect(normal[, point, ...])

Reflect a dataset across a plane.

UnstructuredGrid.remove_cells(ind[, inplace])

Remove cells.

UnstructuredGrid.rename_array(old_name, new_name)

Change array name by searching for the array then renaming it.

UnstructuredGrid.rotate_vector(vector, angle)

Rotate mesh about a vector.

UnstructuredGrid.rotate_x(angle[, point, ...])

Rotate mesh about the x-axis.

UnstructuredGrid.rotate_y(angle[, point, ...])

Rotate mesh about the y-axis.

UnstructuredGrid.rotate_z(angle[, point, ...])

Rotate mesh about the z-axis.

UnstructuredGrid.sample(target[, tolerance, ...])

Resample array data from a passed mesh onto this mesh.

UnstructuredGrid.sample_over_circular_arc(...)

Sample a dataset over a circular arc.

UnstructuredGrid.sample_over_circular_arc_normal(center)

Sample a dataset over a circular arc defined by a normal and polar vector and plot it.

UnstructuredGrid.sample_over_line(pointa, pointb)

Sample a dataset onto a line.

UnstructuredGrid.sample_over_multiple_lines(points)

Sample a dataset onto a multiple lines.

UnstructuredGrid.save(filename[, binary, ...])

Save this vtk object to file.

UnstructuredGrid.scale(xyz[, ...])

Scale the mesh.

UnstructuredGrid.select_enclosed_points(surface)

Mark points as to whether they are inside a closed surface.

UnstructuredGrid.separate_cells()

Return a copy of the dataset with separated cells with no shared points.

UnstructuredGrid.set_active_scalars(name[, ...])

Find the scalars by name and appropriately sets it as active.

UnstructuredGrid.set_active_tensors(name[, ...])

Find the tensors by name and appropriately sets it as active.

UnstructuredGrid.set_active_vectors(name[, ...])

Find the vectors by name and appropriately sets it as active.

UnstructuredGrid.shallow_copy(to_copy)

Create a shallow copy from a different dataset into this one.

UnstructuredGrid.shrink([shrink_factor, ...])

Shrink the individual faces of a mesh.

UnstructuredGrid.slice([normal, origin, ...])

Slice a dataset by a plane at the specified origin and normal vector orientation.

UnstructuredGrid.slice_along_axis([n, axis, ...])

Create many slices of the input dataset along a specified axis.

UnstructuredGrid.slice_along_line(line[, ...])

Slice a dataset using a polyline/spline as the path.

UnstructuredGrid.slice_implicit(...[, ...])

Slice a dataset by a VTK implicit function.

UnstructuredGrid.slice_orthogonal([x, y, z, ...])

Create three orthogonal slices through the dataset on the three cartesian planes.

UnstructuredGrid.split_bodies([label, ...])

Find, label, and split connected bodies/volumes.

UnstructuredGrid.streamlines([vectors, ...])

Integrate a vector field to generate streamlines.

UnstructuredGrid.streamlines_evenly_spaced_2D([...])

Generate evenly spaced streamlines on a 2D dataset.

UnstructuredGrid.streamlines_from_source(source)

Generate streamlines of vectors from the points of a source mesh.

UnstructuredGrid.subdivide_tetra()

Subdivide each tetrahedron into twelve tetrahedrons.

UnstructuredGrid.surface_indices([progress_bar])

Return the surface indices of a grid.

UnstructuredGrid.tessellate([...])

Tessellate a mesh.

UnstructuredGrid.texture_map_to_plane([...])

Texture map this dataset to a user defined plane.

UnstructuredGrid.texture_map_to_sphere([...])

Texture map this dataset to a user defined sphere.

UnstructuredGrid.threshold([value, scalars, ...])

Apply a vtkThreshold filter to the input dataset.

UnstructuredGrid.threshold_percent([...])

Threshold the dataset by a percentage of its range on the active scalars array.

UnstructuredGrid.transform(trans[, ...])

Transform this mesh with a 4x4 transform.

UnstructuredGrid.translate(xyz[, ...])

Translate the mesh.

UnstructuredGrid.triangulate([inplace, ...])

Return an all triangle mesh.

UnstructuredGrid.warp_by_scalar([scalars, ...])

Warp the dataset's points by a point data scalars array's values.

UnstructuredGrid.warp_by_vector([vectors, ...])

Warp the dataset's points by a point data vectors array's values.

Attributes

UnstructuredGrid.active_normals

Return the active normals as an array.

UnstructuredGrid.active_scalars

Return the active scalars as an array.

UnstructuredGrid.active_scalars_info

Return the active scalar's association and name.

UnstructuredGrid.active_scalars_name

Return the name of the active scalars.

UnstructuredGrid.active_t_coords

Return or set the active texture coordinates on the points.

UnstructuredGrid.active_tensors

Return the active tensors array.

UnstructuredGrid.active_tensors_info

Return the active tensor's field and name: [field, name].

UnstructuredGrid.active_tensors_name

Return the name of the active tensor array.

UnstructuredGrid.active_vectors

Return the active vectors array.

UnstructuredGrid.active_vectors_info

Return the active vector's association and name.

UnstructuredGrid.active_vectors_name

Return the name of the active vectors array.

UnstructuredGrid.actual_memory_size

Return the actual size of the dataset object.

UnstructuredGrid.area

Return the mesh area if 2D.

UnstructuredGrid.array_names

Return a list of array names for the dataset.

UnstructuredGrid.arrows

Return a glyph representation of the active vector data as arrows.

UnstructuredGrid.bounds

Return the bounding box of this dataset.

UnstructuredGrid.cell_arrays

Return vtkCellData as DataSetAttributes.

UnstructuredGrid.cell_connectivity

Return a the vtk cell connectivity as a numpy array.

UnstructuredGrid.cell_data

Return vtkCellData as DataSetAttributes.

UnstructuredGrid.cells

Return a pointer to the cells as a numpy object.

UnstructuredGrid.cells_dict

Return a dictionary that contains all cells mapped from cell types.

UnstructuredGrid.celltypes

Return the cell types array.

UnstructuredGrid.center

Return the center of the bounding box.

UnstructuredGrid.field_arrays

Return vtkFieldData as DataSetAttributes.

UnstructuredGrid.field_data

Return FieldData as DataSetAttributes.

UnstructuredGrid.length

Return the length of the diagonal of the bounding box.

UnstructuredGrid.memory_address

Get address of the underlying VTK C++ object.

UnstructuredGrid.n_arrays

Return the number of arrays present in the dataset.

UnstructuredGrid.n_cells

Return the number of cells in the entire dataset.

UnstructuredGrid.n_points

Return the number of points in the entire dataset.

UnstructuredGrid.number_of_cells

Return the number of cells.

UnstructuredGrid.number_of_points

Return the number of points.

UnstructuredGrid.offset

Return the cell locations array.

UnstructuredGrid.point_arrays

Return vtkPointData as DataSetAttributes.

UnstructuredGrid.point_data

Return vtkPointData as DataSetAttributes.

UnstructuredGrid.points

Return a reference to the points as a numpy object.

UnstructuredGrid.t_coords

Return the active texture coordinates on the points.

UnstructuredGrid.textures

Return a dictionary to hold compatible vtk.vtkTexture objects.

UnstructuredGrid.vectors

Return active vectors.

UnstructuredGrid.volume

Return the mesh volume.