{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Clip Volume Widget {#clip_volume_widget_example}\n\nIf you have a structured dataset like a\n`pyvista.ImageData`{.interpreted-text role=\"class\"} or\n`pyvista.RectilinearGrid`{.interpreted-text role=\"class\"}, you can clip\nit using the `pyvista.Plotter.add_volume_clip_plane`{.interpreted-text\nrole=\"func\"} widget to better see the internal structure of the dataset.\n\n![image](../../images/gifs/volume-clip-plane-widget.gif)\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        ""
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Create the Dataset\n\nCreate a dense `pyvista.ImageData`{.interpreted-text role=\"class\"} with\ndimensions `(200, 200, 200)` and set the active scalars to distance from\nthe `center\n<pyvista.DataSet.center>`{.interpreted-text role=\"attr\"} of the grid.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\n\nimport pyvista as pv\n\ngrid = pv.ImageData(dimensions=(200, 200, 200))\ngrid['scalars'] = np.linalg.norm(grid.center - grid.points, axis=1)\ngrid"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Generate the Opacity Array\n\nCreate a banded opacity array such that our dataset shows \\\"rings\\\" at\ncertain values. Have this increase such that higher values (values\nfarther away from the center) are more opaque.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "opacity = np.zeros(100)\nopacity[::10] = np.geomspace(0.01, 0.75, 10)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Plot a Single Clip Plane Dataset\n\nPlot the volume with a single clip plane.\n\nReverse the opacity array such that portions closer to the center are\nmore opaque.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "pl = pv.Plotter()\npl.add_volume_clip_plane(grid, normal='-x', opacity=opacity[::-1], cmap='magma')\npl.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Plot Multiple Clip Planes\n\nPlot the dataset using the\n`pyvista.Plotter.add_volume_clip_plane`{.interpreted-text role=\"func\"}\nwith the output from `pyvista.Plotter.add_volume`{.interpreted-text\nrole=\"func\"} Enable constant interaction by setting the\n`interaction_event` to `'always'`.\n\nDisable the arrows to make the plot a bit clearer and flip the opacity\narray.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "pl = pv.Plotter()\nvol = pl.add_volume(grid, opacity=opacity)\nvol.prop.interpolation_type = 'linear'\npl.add_volume_clip_plane(\n    vol,\n    normal='-x',\n    interaction_event='always',\n    normal_rotation=False,\n)\npl.add_volume_clip_plane(\n    vol,\n    normal='-y',\n    interaction_event='always',\n    normal_rotation=False,\n)\npl.show()"
      ]
    }
  ],
  "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
}