{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Depth Peeling {#depth_peeling_example}\n\nDepth peeling is a technique to correctly render translucent geometry.\nThis is not enabled by default in `pyvista.global_theme\n<pyvista.plotting.themes.Theme>`{.interpreted-text role=\"attr\"} as some\noperating systems and versions of VTK have issues with this routine.\n\nFor this example, we will showcase the difference that depth peeling\nprovides.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import pyvista as pv\nfrom pyvista import examples"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "centers = [(0, 0, 0), (1, 0, 0), (-1, 0, 0), (0, 1, 0), (0, -1, 0)]\nradii = [1, 0.5, 0.5, 0.5, 0.5]\n\nspheres = pv.MultiBlock()\nfor i, c in enumerate(centers):\n    spheres.append(pv.Sphere(center=c, radius=radii[i]))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "dargs = dict(opacity=0.5, color=\"red\", smooth_shading=True)\n\np = pv.Plotter(shape=(1, 2))\n\np.add_mesh(spheres, **dargs)\np.enable_depth_peeling(10)\np.add_text(\"Depth Peeling\")\n\np.subplot(0, 1)\np.add_text(\"Standard\")\np.add_mesh(spheres.copy(), **dargs)\n\np.link_views()\np.camera_position = [(11.7, 4.7, -4.33), (0.0, 0.0, 0.0), (0.3, 0.07, 0.9)]\np.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "The following room surfaces example mesh, provided courtesy of [Sam\nPotter](https://github.com/sampotter) has coincident topology and depth\nrendering helps correctly render those geometries when a global opacity\nvalue is used.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "room = examples.download_room_surface_mesh()\n\np = pv.Plotter(shape=(1, 2))\n\np.enable_depth_peeling(number_of_peels=4, occlusion_ratio=0)\np.add_mesh(room, opacity=0.5, color='lightblue')\np.add_text(\"Depth Peeling\")\n\np.subplot(0, 1)\np.add_text(\"Standard\")\np.add_mesh(room.copy(), opacity=0.5, color='lightblue')\n\np.link_views()\np.camera_position = [(43.6, 49.5, 19.8), (0.0, 2.25, 0.0), (-0.57, 0.70, -0.42)]\n\np.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "And here is another example wheen rendering many translucent contour\nsurfaces.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "mesh = examples.download_brain().contour(5)\ncmap = \"viridis_r\"\n\np = pv.Plotter(shape=(1, 2))\n\np.add_mesh(mesh, opacity=0.5, cmap=cmap)\np.enable_depth_peeling(10)\np.add_text(\"Depth Peeling\")\n\np.subplot(0, 1)\np.add_text(\"Standard\")\np.add_mesh(mesh.copy(), opacity=0.5, cmap=cmap)\n\np.link_views()\np.camera_position = [(418.3, 659.0, 53.8), (90.2, 111.5, 90.0), (0.03, 0.05, 1.0)]\np.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
}