MultiBlock#

class MultiBlock(*args, **kwargs)[source]#

A composite class to hold many data sets which can be iterated over.

This wraps/extends the vtkMultiBlockDataSet class so that we can easily plot these data sets and use the composite in a Pythonic manner.

You can think of MultiBlock like a list as we can iterate over this data structure by index. It has some dictionary features as we can also access blocks by their string name.

Changed in version 0.36.0: MultiBlock adheres more closely to being list like, and inherits from collections.abc.MutableSequence. Multiple nonconforming behaviors were removed or modified.

Parameters:
*argsdict, optional

Data object dictionary.

validatebool | MeshValidationFields | sequence[MeshValidationFields], default: False

Validate the mesh using validate_mesh() after initialization. Set this to True to validate all fields, or specify any combination of fields allowed by validate_mesh.

Added in version 0.47.

**kwargsdict, optional

See pyvista.read() for additional options.

Examples#

Download Python source code | Download Jupyter notebook

>>> import pyvista as pv

Create an empty composite dataset.

Add a dataset to the collection.

Add a named block.

>>> blocks['cube'] = pv.Cube()

Instantiate from a list of objects.

>>> data = [
...     pv.Sphere(center=(2, 0, 0)),
...     pv.Cube(center=(0, 2, 0)),
...     pv.Cone(),
... ]
>>> blocks = pv.MultiBlock(data)
>>> blocks.plot()
../../../_images/pyvista-MultiBlock-5007dab4f570ef99_00_00.png

Instantiate from a dictionary.

>>> data = {
...     'cube': pv.Cube(),
...     'sphere': pv.Sphere(center=(2, 2, 0)),
... }
>>> blocks = pv.MultiBlock(data)
>>> blocks.plot()
../../../_images/pyvista-MultiBlock-5007dab4f570ef99_01_00.png

Iterate over the collection.

>>> for name in blocks.keys():
...     block = blocks[name]
>>> for block in blocks:
...     # Do something with each dataset
...     surf = block.extract_surface(algorithm=None)

Inheritance#

Inherited members are documented on _BoundsSizeMixin, CompositeFilters, DataObjectFilters, DataObject.

See them all under Inherited Attributes, Inherited Methods and Filters.

Wraps vtkMultiBlockDataSet.

Attributes#

MultiBlock.block_types

Return a set of all block types.

MultiBlock.bounds

Find min/max for bounds across blocks.

MultiBlock.center

Set or return the center of the bounding box.

MultiBlock.is_all_polydata

Return True when all the blocks are PolyData.

MultiBlock.is_empty

Return True if there are no blocks.

MultiBlock.is_heterogeneous

Return True any two nested blocks have different type.

MultiBlock.is_homogeneous

Return True if all nested blocks have the same type.

MultiBlock.is_nested

Return True if any blocks are a MultiBlock.

MultiBlock.length

Return the length of the diagonal of the bounding box.

MultiBlock.n_blocks

Return the total number of blocks set.

MultiBlock.nested_block_types

Return a set of all nested block types.

MultiBlock.volume

Return the total volume of all meshes in this dataset.

Inherited Attributes#

DataObject.actual_memory_size

Return the actual size of the dataset object.

_BoundsSizeMixin.bounds_size

Return the size of each axis of the object’s bounding box.

DataObject.field_data

Return FieldData as DataSetAttributes.

DataObject.memory_address

Get address of the underlying VTK C++ object.

DataObject.user_dict

Set or return a user-specified data dictionary.

Methods#

MultiBlock.append(dataset[, name])

Add a data set to the next block index.

MultiBlock.as_polydata_blocks([copy])

Convert all the datasets within this MultiBlock to PolyData.

MultiBlock.as_unstructured_grid_blocks([copy])

Convert all the datasets within this MultiBlock to UnstructuredGrid.

MultiBlock.clean([empty])

Remove any null blocks in place.

MultiBlock.clear_all_cell_data()

Clear all cell data from all blocks.

MultiBlock.clear_all_data()

Clear all data from all blocks.

MultiBlock.clear_all_point_data()

Clear all point data from all blocks.

MultiBlock.copy([deep])

Return a copy of the multiblock.

MultiBlock.copy_meta_from(ido, deep)

Copy pyvista meta data onto this object from another object.

MultiBlock.deep_copy(to_copy)

Overwrite this MultiBlock with another MultiBlock as a deep copy.

MultiBlock.extend(datasets)

Extend MultiBlock with an Iterable.

MultiBlock.flatten(*[, order, name_mode, ...])

Flatten this MultiBlock.

MultiBlock.get(index[, default])

Get a block by its index or name.

MultiBlock.get_block(index)

Get a block by its index or name.

MultiBlock.get_block_name(index)

Return the string name of the block at the given index.

MultiBlock.get_data_range(name[, ...])

Get the min/max of an array given its name across all blocks.

MultiBlock.get_index_by_name(name)

Find the index number by block name.

MultiBlock.insert(index, dataset[, name])

Insert data before index.

MultiBlock.keys()

Get all the block names in the dataset.

MultiBlock.move_nested_field_data_to_root(*)

Move or copy field data from all nested MultiBlock blocks.

MultiBlock.plot([off_screen, full_screen, ...])

Plot a PyVista, NumPy, or VTK object.

MultiBlock.pop([index])

Pop off a block at the specified index.

MultiBlock.recursive_iterator(...)

Iterate over all nested blocks recursively.

MultiBlock.replace(index, dataset)

Replace dataset at index while preserving key name.

MultiBlock.reverse()

Reverse MultiBlock in-place.

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

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

MultiBlock.set_block_name(index, name)

Set a block's string name at the specified index.

MultiBlock.shallow_copy(to_copy[, recursive])

Shallow copy the given multiblock to this multiblock.

MultiBlock.wrap_nested()

Ensure that all nested data structures are wrapped as PyVista datasets.

Inherited Methods#

DataObject.add_field_data

Add field data.

DataObject.cast_to_multiblock

Convert this DataObject to a MultiBlock.

DataObject.clear_field_data

Remove all field data.

DataObject.copy_attributes

Copy the data attributes of the input dataset object.

DataObject.copy_structure

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

DataObject.head

Return the header stats of this dataset.

DataObject.save

Save this vtk object to file.

Filters#

DataObjectFilters.cell_centers

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

DataObjectFilters.cell_data_to_point_data

Transform cell data into point data.

DataObjectFilters.cell_quality

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

DataObjectFilters.cell_validator

Check the validity of each cell in this dataset.

DataObjectFilters.clip

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

DataObjectFilters.clip_box

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

DataObjectFilters.clip_slab

Clip a dataset by a slab of finite thickness around a plane.

CompositeFilters.combine

Combine all blocks into a single unstructured grid.

DataObjectFilters.compute_cell_sizes

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

DataObjectFilters.convex_hull

Compute the convex hull from this mesh’s points.

DataObjectFilters.ctp

Transform cell data into point data.

DataObjectFilters.elevation

Generate scalar values on a dataset.

DataObjectFilters.extract_all_edges

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

CompositeFilters.extract_geometry

Extract the surface the geometry of all blocks.

DataObjectFilters.extract_surface

Extract surface geometry of the mesh as PolyData.

DataObjectFilters.flip_normal

Flip mesh about the normal.

DataObjectFilters.flip_x

Flip mesh about the x-axis.

DataObjectFilters.flip_y

Flip mesh about the y-axis.

DataObjectFilters.flip_z

Flip mesh about the z-axis.

CompositeFilters.generic_filter

Apply any filter to all nested blocks recursively.

CompositeFilters.outline

Produce an outline of the full extent for the all blocks in this composite dataset.

CompositeFilters.outline_corners

Produce an outline of the corners for the all blocks in this composite dataset.

DataObjectFilters.point_data_to_cell_data

Transform point data into cell data.

DataObjectFilters.ptc

Transform point data into cell data.

DataObjectFilters.reflect

Reflect a dataset across a plane.

DataObjectFilters.resize

Resize the dataset’s bounds.

DataObjectFilters.rotate

Rotate mesh about a point with a rotation matrix or Rotation object.

DataObjectFilters.rotate_vector

Rotate mesh about a vector.

DataObjectFilters.rotate_x

Rotate mesh about the x-axis.

DataObjectFilters.rotate_y

Rotate mesh about the y-axis.

DataObjectFilters.rotate_z

Rotate mesh about the z-axis.

DataObjectFilters.sample

Resample array data from a passed mesh onto this mesh.

DataObjectFilters.scale

Scale the mesh.

DataObjectFilters.slice

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

DataObjectFilters.slice_along_axis

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

DataObjectFilters.slice_along_line

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

DataObjectFilters.slice_implicit

Slice a dataset by a VTK implicit function.

DataObjectFilters.slice_orthogonal

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

DataObjectFilters.transform

Transform this mesh with a 4x4 transform.

DataObjectFilters.translate

Translate the mesh.

DataObjectFilters.triangulate

Return an all triangle mesh.

DataObjectFilters.validate_mesh

Validate this mesh’s array data, points, and cells.