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
|
Find min/max for bounds across blocks. |
|
Return the center of the bounding box. |
|
Return the length of the diagonal of the bounding box. |
|
Return the total number of blocks set. |
|
Return the total volume of all meshes in this dataset. |
Methods
|
Add a data set to the next block index. |
|
Remove any null blocks in place. |
|
Return a copy of the object. |
|
Copy pyvista meta data onto this object from another object. |
|
Get a block by its index or name. |
|
Return the string name of the block at the given index. |
|
Get the min/max of an array given its name across all blocks. |
|
Find the index number by block name. |
|
Get all the block names in the dataset. |
|
Get the next block from the iterator. |
|
Plot a vtk or numpy object. |
|
Pop off a block at the specified index. |
|
Set a block’s string name at the specified index. |
|
Ensure that 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.You can think of
MultiBlock
like lists or dictionaries as we can iterate over this data structure by index and we can also access blocks by their string name.Examples
>>> import pyvista as pv
>>> # Create empty composite dataset >>> blocks = pv.MultiBlock() >>> # Add a dataset to the collection >>> sphere = pv.Sphere() >>> blocks.append(sphere) >>> # Or add a named block >>> blocks["cube"] = pv.Cube()
>>> # instantiate from a list of objects >>> data = [pv.Sphere(), pv.Cube(), pv.Cone()] >>> blocks = pv.MultiBlock(data)
>>> # instantiate from a dictionary >>> data = {"cube": pv.Cube(), "sphere": pv.Sphere()} >>> blocks = pv.MultiBlock(data)
>>> # now iterate over the collection >>> for name in blocks.keys(): ... block = blocks[name] # do something!
>>> for block in blocks: ... surf = block.extract_surface() # Do something with each dataset
-
append
(data)¶ Add a data set to the next block index.
-
property
bounds
¶ Find min/max for bounds across blocks.
- Returns
length 6 tuple of floats containing min/max along each axis
- Return type
tuple(float)
-
property
center
¶ Return the center of the bounding box.
-
clean
(empty=True)¶ Remove any null blocks in place.
- Parameters
empty (bool) – Remove any meshes that are empty as well (have zero points).
-
copy
(deep=True)¶ Return 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)¶ Copy 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 occurrence.
-
get_block_name
(index)¶ Return the string name of the block at the given index.
-
get_data_range
(name)¶ Get the min/max of an array 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
¶ Return the length of the diagonal of the bounding box.
-
property
n_blocks
¶ Return 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, volume=False, parallel_projection=False, use_ipyvtk=None, **kwargs)¶ Plot 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.use_ipyvtk (bool, optional) – Use the
ipyvtk-simple
ViewInteractiveWidget
to visualize the plot within a juyterlab notebook.**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)¶ Pop off a block at the specified index.
-
set_block_name
(index, name)¶ Set a block’s string name at the specified index.
-
property
volume
¶ Return the total volume of all meshes in this dataset.
- Returns
volume – Total volume of the mesh.
- Return type
float
-
wrap_nested
()¶ Ensure that all nested data structures are wrapped as PyVista datasets.
This is performed in place.
-