{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Picking a Point on the Surface of a Mesh {#surface_point_picking_example}\n\nThis example demonstrates how to pick meshes using\n`enable_surface_point_picking() <pyvista.Plotter.enable_surface_point_picking>`{.interpreted-text\nrole=\"func\"}.\n\nThis allows you to pick points on the surface of a mesh.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import pyvista as pv"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Create a mesh and enable picking using the default settings.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "cube = pv.Cube()\n\npl = pv.Plotter()\npl.add_mesh(cube, show_edges=True)\npl.enable_surface_point_picking()\npl.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Enable a callback that creates a cube at the right-clicked point and add\na label at the point as well it.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "def callback(point):\n    \"\"\"Create a cube and a label at the click point.\"\"\"\n    mesh = pv.Cube(center=point, x_length=0.05, y_length=0.05, z_length=0.05)\n    pl.add_mesh(mesh, style='wireframe', color='r')\n    pl.add_point_labels(point, [f\"{point[0]:.2f}, {point[1]:.2f}, {point[2]:.2f}\"])\n\n\npl = pv.Plotter()\npl.add_mesh(cube, show_edges=True)\npl.enable_surface_point_picking(callback=callback, show_point=False)\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
}