DataObjectFilters.resize

DataObjectFilters.resize#

DataObjectFilters.resize(
*,
bounds: VectorLikeFloat | None = None,
bounds_size: float | VectorLikeFloat | None = None,
length: float | None = None,
center: VectorLikeFloat | None = None,
preserve_aspect_ratio: bool | None = None,
transform_all_input_vectors: bool = False,
inplace: bool = False,
) → _MeshType_co[source]#

Resize the dataset’s bounds.

This filter rescales and translates the mesh to fit specified bounds. This is useful for normalizing datasets, changing units, or fitting datasets into specific coordinate ranges.

It has three independent use cases:

  1. Use bounds to set the mesh’s bounds directly.

  2. Use bounds_size to set the mesh’s bounds_size directly.

  3. Use length to set the mesh’s diagonal length directly.

By default, the bounds_size and length options resize the mesh so that its center is unchanged. Optionally, center may be set explicitly for these cases.

Added in version 0.46.

Parameters:
boundsVectorLikeFloat, optional

Target bounds for the resized dataset in the format [xmin, xmax, ymin, ymax, zmin, zmax]. If provided, the dataset is scaled and translated to fit exactly within these bounds. Cannot be used together with bounds_size, length, or center.

bounds_sizefloat | VectorLikeFloat, optional

Target size of the bounds for the resized dataset. Use a single float to specify the size of all three axes, or a 3-element vector to set the size of each axis independently. Cannot be used together with bounds or length.

lengthfloat, optional

Target length of the bounds for the resized dataset. Cannot be used together with bounds or bounds_size.

Added in version 0.47.

centerVectorLikeFloat, optional

Center of the resized dataset in [x, y, z]. By default, the mesh’s center is used. Only used when bounds_size or length is specified.

preserve_aspect_ratiobool, optional

Whether to preserve the dataset’s aspect ratio during resizing.

  • If True, a uniform scale factor is applied. For bounds and bounds_size, the specified values are treated as maximum extents rather than exact targets.

  • If False, each axis is scaled independently to exactly match the requested bounds or bounds_size.

By default, bounds and bounds_size use independent axis scaling, while length preserves the aspect ratio. This parameter can be used to enable aspect ratio preservation for bounds and bounds_size.

Added in version 0.49.

transform_all_input_vectorsbool, default: False

When True, all input vectors are transformed as part of the resize. Otherwise, only the points, normals, and active vectors are transformed.

inplacebool, default: False

If True, the dataset is modified in place. If False, a new dataset is returned.

Returns:
outputDataSet | MultiBlock

Resized dataset. Return type matches input.

Examples#

Download Python source code | Download Jupyter notebook

Load a mesh with asymmetric bounds and show them.

>>> import pyvista as pv
>>> mesh = pv.Cube(
...     x_length=1.0, y_length=2.0, z_length=3.0, center=(1.0, 2.0, 3.0)
... )
>>> mesh.bounds
BoundsTuple(x_min = 0.5,
            x_max = 1.5,
            y_min = 1.0,
            y_max = 3.0,
            z_min = 1.5,
            z_max = 4.5)

Resize it to fit specific bounds.

>>> resized = mesh.resize(bounds=[-1, 2, -3, 4, -5, 6])
>>> resized.bounds
BoundsTuple(x_min = -1.0,
            x_max =  2.0,
            y_min = -3.0,
            y_max =  4.0,
            z_min = -5.0,
            z_max =  6.0)

Resize the mesh so its diagonal length is 4.0. The mesh’s center is unchanged.

>>> resized = mesh.resize(length=4.0)
>>> resized.length
4.0
>>> resized.center
(1.0, 2.0, 3.0)

Resize the mesh so its size is 4.0. The mesh’s center is again unchanged.

>>> resized = mesh.resize(bounds_size=4.0)
>>> resized.bounds_size
(4.0, 4.0, 4.0)
>>> resized.center
(1.0, 2.0, 3.0)
>>> resized.bounds
BoundsTuple(x_min = -1.0,
            x_max =  3.0,
            y_min =  0.0,
            y_max =  4.0,
            z_min =  1.0,
            z_max =  5.0)

Specify a different size for each axis and set the desired center.

>>> resized = mesh.resize(bounds_size=(2.0, 1.0, 0.5), center=(1.0, 0.5, 0.25))
>>> resized.bounds_size
(2.0, 1.0, 0.5)
>>> resized.center
(1.0, 0.5, 0.25)

Center the mesh at the origin and normalize its bounds to 1.0.

>>> resized = mesh.resize(bounds_size=1.0, center=(0.0, 0.0, 0.0))
>>> resized.bounds
BoundsTuple(x_min = -0.5,
            x_max =  0.5,
            y_min = -0.5,
            y_max =  0.5,
            z_min = -0.5,
            z_max =  0.5)

Normalize it again, but preserve the aspect ratio. Its 1:2:3 x-y-z bounds ratio is preserved.

>>> resized = mesh.resize(
...     bounds_size=1.0, center=(0.0, 0.0, 0.0), preserve_aspect_ratio=True
... )
>>> resized.bounds
BoundsTuple(x_min = -0.1666,
            x_max =  0.1666,
            y_min = -0.3333,
            y_max =  0.3333,
            z_min = -0.5,
            z_max =  0.5)
>>> resized.bounds_size
(0.3333, 0.6666, 1.0)

See Also#

scale(), translate()

Scale and/or translate a mesh. Used internally by resize().