{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Line Widget {#line_widget_example}\n\nThe line widget can be enabled and disabled by the\n`pyvista.Plotter.add_line_widget`{.interpreted-text role=\"func\"} and\n`pyvista.Plotter.clear_line_widgets`{.interpreted-text role=\"func\"}\nmethods respectively. Unfortunately, PyVista does not have any helper\nmethods to utilize this widget, so it is necessary to pass a custom\ncallback method.\n\nOne particularly fun example is to use the line widget to create a\nsource for the `pyvista.DataSetFilters.streamlines`{.interpreted-text\nrole=\"func\"} filter. Again note the use of the `name` argument in\n`add_mesh`.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nimport pyvista as pv\nfrom pyvista import examples\n\npv.set_plot_theme(\"document\")\n\nmesh = examples.download_kitchen()\nfurniture = examples.download_kitchen(split=True)\n\narr = np.linalg.norm(mesh[\"velocity\"], axis=1)\nclim = [arr.min(), arr.max()]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "pl = pv.Plotter()\npl.add_mesh(furniture, name=\"furniture\", color=True)\npl.add_mesh(mesh.outline(), color=\"black\")\npl.add_axes()\n\n\ndef simulate(pointa, pointb) -> None:\n    streamlines = mesh.streamlines(\n        n_points=10, max_steps=100, pointa=pointa, pointb=pointb, integration_direction=\"forward\"\n    )\n    pl.add_mesh(\n        streamlines, name=\"streamlines\", line_width=5, render_lines_as_tubes=True, clim=clim\n    )\n\n\npl.add_line_widget(callback=simulate, use_vertices=True)\npl.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "And here is a screen capture of a user interacting with this\n\n![image](../../images/gifs/line-widget-streamlines.gif)\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "```{=html}\n<center>\n  <a target=\"_blank\" href=\"https://colab.research.google.com/github/pyvista/pyvista-tutorial/blob/gh-pages/notebooks/tutorial/08_widgets/c_line-widget.ipynb\">\n    <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/ width=\"150px\">\n  </a>\n</center>\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.12.11"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}