{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import subprocess\nimport sys\n\nif \"google.colab\" in sys.modules:\n subprocess.run(\"apt-get update\", shell=True, check=True)\n subprocess.run(\"apt-get install -qq xvfb libgl1-mesa-glx\", shell=True, check=True)\n subprocess.run(\"pip install pyvista[all] -qq\", shell=True, check=True)\n\n import pyvista as pv\n\n # Seems that only static plotting is supported by colab at the moment\n pv.global_theme.jupyter_backend = \"static\"\n pv.global_theme.notebook = True\n pv.start_xvfb()\nelse:\n %matplotlib inline\n from pyvista import set_plot_theme\n\n set_plot_theme(\"document\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Box Widget {#box_widget_example}\n==========\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![image](../../images/gifs/box-clip.gif)\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" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```{=html}\n
\n \n \"Open\n \n
\n```\n" ] } ], "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.10.14" } }, "nbformat": 4, "nbformat_minor": 0 }