DataSetFilters.bounding_box#
- DataSetFilters.bounding_box(
- box_style: Literal['frame', 'outline', 'face'] = 'face',
- *,
- oriented: bool = False,
- frame_width: float = 0.1,
- return_meta: bool = False,
- as_composite: bool = True,
Return a bounding box for this dataset.
By default, the box is an axis-aligned bounding box (AABB) returned as a
MultiBlockwith sixPolyDatacomprising the faces of the box. The blocks are named and ordered as('+X','-X','+Y','-Y','+Z','-Z').The box can optionally be styled as an outline or frame. It may also be oriented to generate an oriented bounding box (OBB).
Added in version 0.45.
- Parameters:
- box_style‘frame’ | ‘outline’ | ‘face’, default: ‘face’
Choose the style of the box. If
'face'(default), each face of the box is a single quad cell. If'outline', the edges of each face are returned as line cells. If'frame', the center portion of each face is removed to create a picture-frame style border with each face having four quads (one for each side of the frame). Useframe_widthto control the size of the frame.- orientedbool, default:
False Orient the box using this dataset’s
principal_axes(). This will generate a box that best fits this dataset’s points. Seeoriented_bounding_box()for more details.- frame_width
float, optional Set the width of the frame. Only has an effect if
box_styleis'frame'. Values must be between0.0(minimal frame) and1.0(large frame). The frame is scaled to ensure it has a constant width.- return_metabool, default:
False If
True, also returns the corner point and the three axes vectors defining the orientation of the box.- as_compositebool, default:
True Return the box as a
pyvista.MultiBlockwith six blocks: one for each face. Set thisFalseto merge the output and returnPolyDatawith six cells instead. The faces in both outputs are separate, that is, there are duplicate points at the corners.
- Returns:
- output
pyvista.MultiBlock|pyvista.PolyData MultiBlock with six named cube faces when
as_composite=Trueand PolyData otherwise.numpy.ndarrayThe box’s corner point corresponding to the origin of its axes if
return_meta=True.numpy.ndarrayThe box’s orthonormal axes vectors if
return_meta=True.
- output
Examples#
Download Python source code | Download Jupyter notebook
Create a bounding box for a dataset.
>>> import pyvista as pv
>>> from pyvista import examples
>>> mesh = examples.download_oblique_cone()
>>> box = mesh.bounding_box()
Plot the mesh and its bounding box.
>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(mesh, color='red')
>>> _ = pl.add_mesh(box, opacity=0.5)
>>> pl.show()
Create a frame instead.
>>> frame = mesh.bounding_box('frame')
>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(mesh, color='red')
>>> _ = pl.add_mesh(frame, show_edges=True)
>>> pl.show()
Create an oriented bounding box (OBB) and compare it to the non-oriented one. Use the outline style for both.
>>> box = mesh.bounding_box('outline')
>>> obb = mesh.bounding_box('outline', oriented=True)
>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(mesh)
>>> _ = pl.add_mesh(box, color='red', line_width=5)
>>> _ = pl.add_mesh(obb, color='blue', line_width=5)
>>> pl.show()
Return the metadata for the box.
>>> box, point, axes = mesh.bounding_box('outline', return_meta=True)
Use the metadata to plot the box’s axes using AxesAssembly.
Create the assembly and position it at the box’s corner. Scale it to a fraction
of the box’s length.
>>> scale = box.length / 4
>>> axes_assembly = pv.AxesAssembly(position=point, scale=scale)
Plot the box and the axes.
>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(mesh)
>>> _ = pl.add_mesh(box, color='black', line_width=5)
>>> _ = pl.add_actor(axes_assembly)
>>> _ = pl.view_yz()
>>> pl.show()
See Also#
outlineLightweight version of this filter with fewer options.
oriented_bounding_boxSimilar filter with
oriented=Trueby default and more options.pyvista.Plotter.add_bounding_boxAdd a bounding box to a scene.
pyvista.CubeFacesSourceGenerate the faces of a cube. Used internally by this filter.
Used In#
Gallery Examples