pyvista.DataSetFilters.bounding_box

pyvista.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,
)[ソース]#

このデータセットの境界ボックスを返します.

By default, the box is an axis-aligned bounding box (AABB) returned as a MultiBlock with six PolyData comprising 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.

パラメータ:
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). Use frame_width to 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. See oriented_bounding_box() for more details.

frame_widthfloat, optional

Set the width of the frame. Only has an effect if box_style is 'frame'. Values must be between 0.0 (minimal frame) and 1.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.MultiBlock with six blocks: one for each face. Set this False to merge the output and return PolyData with six cells instead. The faces in both outputs are separate, i.e. there are duplicate points at the corners.

戻り値:
pyvista.MultiBlock or pyvista.PolyData

MultiBlock with six named cube faces when as_composite=True and PolyData otherwise.

numpy.ndarray

The box's corner point corresponding to the origin of its axes if return_meta=True.

numpy.ndarray

The box's orthonormal axes vectors if return_meta=True.

参考

outline

Lightweight version of this filter with fewer options.

oriented_bounding_box

Similar filter with oriented=True by default and more options.

pyvista.Plotter.add_bounding_box

Add a bounding box to a scene.

pyvista.CubeFacesSource

Generate the faces of a cube. Used internally by this filter.

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()
../../../_images/pyvista-DataSetFilters-bounding_box-1_00_00.png

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()
../../../_images/pyvista-DataSetFilters-bounding_box-1_01_00.png

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()
../../../_images/pyvista-DataSetFilters-bounding_box-1_02_00.png

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()
../../../_images/pyvista-DataSetFilters-bounding_box-1_03_00.png