{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Box Widget {#box_widget_example}\n\nThe box widget can be enabled and disabled by the\n`pyvista.Plotter.add_box_widget`{.interpreted-text role=\"func\"} and\n`pyvista.Plotter.clear_box_widgets`{.interpreted-text role=\"func\"}\nmethods respectively. When enabling the box widget, you must provide a\ncustom callback function otherwise the box would appear and do nothing -\nthe callback functions are what allow us to leverage the widget to\nperform a task like clipping/cropping.\n\nConsidering that using a box to clip/crop a mesh is one of the most\ncommon use cases, we have included a helper method that will allow you\nto add a mesh to a scene with a box widget that controls its extent, the\n`pyvista.Plotter.add_mesh_clip_box`{.interpreted-text role=\"func\"}\nmethod.\n\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import pyvista as pv\nfrom pyvista import examples\n\nmesh = examples.download_nefertiti()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "p = pv.Plotter()\np.add_mesh_clip_box(mesh, color='white')\np.show(cpos=[-1, -1, 0.2])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After interacting with the scene, the clipped mesh is available as:\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "p.box_clipped_meshes" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.2" } }, "nbformat": 4, "nbformat_minor": 0 }