Composite Datasets

Container to mimic vtkMultiBlockDataSet objects. These classes hold many VTK datasets in one object that can be passed to VTK algorithms and PyVista filtering/plotting routines.

MultiBlock Datasets

Attributes

bounds

Finds min/max for bounds across blocks

center

Center of the bounding box

length

the length of the diagonal of the bounding box

n_blocks

The total number of blocks set

volume

Total volume of all meshes in this dataast

Methods

append(data)

Add a data set to the next block index

clean([empty])

This will remove any null blocks in place :param empty: Remove any meshes that are empty as well (have zero points) :type empty: bool

copy([deep])

Returns a copy of the object

copy_meta_from(ido)

Copies pyvista meta data onto this object from another object

get(index)

Get a block by its index or name (if the name is non-unique then returns the first occurence)

get_block_name(index)

Returns the string name of the block at the given index

get_data_range(name)

Gets the min/max of a scalar given its name across all blocks

get_index_by_name(name)

Find the index number by block name

keys()

Get all the block names in the dataset

next()

Get the next block from the iterator

plot([off_screen, full_screen, screenshot, …])

Convenience plotting function for a vtk or numpy object.

pop(index)

Pops off a block at the specified index

save(filename[, binary])

Writes a MultiBlock dataset to disk.

set_block_name(index, name)

Set a block’s string name at the specified index

wrap_nested()

A helper to ensure all nested data structures are wrapped as PyVista datasets.

class pyvista.MultiBlock(*args, **kwargs)

Bases: vtkCommonDataModelPython.vtkMultiBlockDataSet, pyvista.core.filters.CompositeFilters, pyvista.core.common.DataObject

A composite class to hold many data sets which can be iterated over. This wraps/extends the vtkMultiBlockDataSet class in VTK so that we can easily plot these data sets and use the composite in a Pythonic manner.

append(data)

Add a data set to the next block index

property bounds

Finds min/max for bounds across blocks

Returns

length 6 tuple of floats containing min/max along each axis

Return type

tuple(float)

property center

Center of the bounding box

clean(empty=True)

This will remove any null blocks in place :param empty: Remove any meshes that are empty as well (have zero points) :type empty: bool

copy(deep=True)

Returns a copy of the object

Parameters

deep (bool, optional) – When True makes a full copy of the object.

Returns

newobject – Deep or shallow copy of the input.

Return type

same as input

copy_meta_from(ido)

Copies pyvista meta data onto this object from another object

get(index)

Get a block by its index or name (if the name is non-unique then returns the first occurence)

get_block_name(index)

Returns the string name of the block at the given index

get_data_range(name)

Gets the min/max of a scalar given its name across all blocks

get_index_by_name(name)

Find the index number by block name

keys()

Get all the block names in the dataset

property length

the length of the diagonal of the bounding box

property n_blocks

The total number of blocks set

next()

Get the next block from the iterator

plot(off_screen=None, full_screen=False, screenshot=None, interactive=True, cpos=None, window_size=None, show_bounds=False, show_axes=True, notebook=None, background=None, text='', return_img=False, eye_dome_lighting=False, use_panel=None, volume=False, parallel_projection=False, **kwargs)

Convenience plotting function for a vtk or numpy object.

Parameters
  • item (vtk or numpy object) – VTK object or numpy array to be plotted.

  • off_screen (bool) – Plots off screen when True. Helpful for saving screenshots without a window popping up.

  • full_screen (bool, optional) – Opens window in full screen. When enabled, ignores window_size. Default False.

  • screenshot (str or bool, optional) –

    Saves screenshot to file when enabled. See: help(pyvistanterface.Plotter.screenshot). Default disabled.

    When True, takes screenshot and returns numpy array of image.

  • window_size (list, optional) – Window size in pixels. Defaults to [1024, 768]

  • show_bounds (bool, optional) – Shows mesh bounds when True. Default False. Alias show_grid also accepted.

  • notebook (bool, optional) – When True, the resulting plot is placed inline a jupyter notebook. Assumes a jupyter console is active.

  • show_axes (bool, optional) – Shows a vtk axes widget. Enabled by default.

  • text (str, optional) – Adds text at the bottom of the plot.

  • volume (bool, optional) – Use the add_volume method for volume rendering.

  • **kwargs (optional keyword arguments) – See help(Plotter.add_mesh) for additional options.

Returns

  • cpos (list) – List of camera position, focal point, and view up.

  • img (numpy.ndarray) – Array containing pixel RGB and alpha. Sized: [Window height x Window width x 3] for transparent_background=False [Window height x Window width x 4] for transparent_background=True Returned only when screenshot enabled

pop(index)

Pops off a block at the specified index

save(filename, binary=True)

Writes a MultiBlock dataset to disk.

Written file may be an ASCII or binary vtm file.

Parameters
  • filename (str) – Filename of mesh to be written. File type is inferred from the extension of the filename unless overridden with ftype. Can be one of the following types (.vtm or .vtmb)

  • binary (bool, optional) – Writes the file as binary when True and ASCII when False.

Notes

Binary files write much faster than ASCII and have a smaller file size.

set_block_name(index, name)

Set a block’s string name at the specified index

property volume

Total volume of all meshes in this dataast

Returns

volume – Total volume of the mesh.

Return type

float

wrap_nested()

A helper to ensure all nested data structures are wrapped as PyVista datasets. This is perfrom inplace