pyvista.UniformGrid#

class UniformGrid(uinput=None, *args, dimensions=None, spacing=(1.0, 1.0, 1.0), origin=(0.0, 0.0, 0.0), deep=False, **kwargs)[source]#

Models datasets with uniform spacing in the three coordinate directions.

Can be initialized in one of several ways:

  • Create empty grid

  • Initialize from a vtk.vtkImageData object

  • Initialize based on dimensions, cell spacing, and origin.

Changed in version 0.33.0: First argument must now be either a path or vtk.vtkImageData. Use keyword arguments to specify the dimensions, spacing, and origin of the uniform grid.

Changed in version 0.37.0: The dims parameter has been renamed to dimensions.

Parameters:
uinputstr, vtk.vtkImageData, pyvista.UniformGrid, optional

Filename or dataset to initialize the uniform grid from. If set, remainder of arguments are ignored.

dimensionsiterable, optional

Dimensions of the uniform grid.

spacingiterable, optional

Spacing of the uniform in each dimension. Defaults to (1.0, 1.0, 1.0). Must be positive.

originiterable, optional

Origin of the uniform grid. Defaults to (0.0, 0.0, 0.0).

deepbool, optional

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

Examples

Create an empty UniformGrid.

>>> import pyvista
>>> grid = pyvista.UniformGrid()

Initialize from a vtk.vtkImageData object.

>>> import vtk
>>> vtkgrid = vtk.vtkImageData()
>>> grid = pyvista.UniformGrid(vtkgrid)

Initialize using using just the grid dimensions and default spacing and origin. These must be keyword arguments.

>>> grid = pyvista.UniformGrid(dimensions=(10, 10, 10))

Initialize using dimensions and spacing.

>>> grid = pyvista.UniformGrid(
...     dimensions=(10, 10, 10),
...     spacing=(2, 1, 5),
... )

Initialize using dimensions, spacing, and an origin.

>>> grid = pyvista.UniformGrid(
...     dimensions=(10, 10, 10),
...     spacing=(2, 1, 5),
...     origin=(10, 35, 50),
... )

Initialize from another UniformGrid.

>>> grid = pyvista.UniformGrid(
...     dimensions=(10, 10, 10),
...     spacing=(2, 1, 5),
...     origin=(10, 35, 50),
... )
>>> grid_from_grid = pyvista.UniformGrid(grid)
>>> grid_from_grid == grid
True

Methods

UniformGrid.cast_to_rectilinear_grid()

Cast this uniform grid to a rectilinear grid.

UniformGrid.cast_to_structured_grid()

Cast this uniform grid to a structured grid.

UniformGrid.to_tetrahedra([tetra_per_cell, ...])

Create a tetrahedral mesh structured grid.

Attributes

UniformGrid.extent

Return or set the extent of the UniformGrid.

UniformGrid.origin

Return the origin of the grid (bottom southwest corner).

UniformGrid.points

Build a copy of the implicitly defined points as a numpy array.

UniformGrid.spacing

Return or set the spacing for each axial direction.

UniformGrid.x

Return all the X points.

UniformGrid.y

Return all the Y points.

UniformGrid.z

Return all the Z points.