{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Create a PointSet {#create_pointset_example}\n\nA `pyvista.PointSet`{.interpreted-text role=\"class\"} is a concrete class\nrepresenting a set of points that specifies the interface for datasets\nthat explicitly use \\\"point\\\" arrays to represent geometry. This class\nis useful for improving the performance of filters on point clouds.\n\nThis example shows the performance improvement when clipping using the\n`pyvista.DataSetFilters.clip`{.interpreted-text role=\"func\"} filter on a\n`pyvista.PointSet`{.interpreted-text role=\"class\"}.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import time\n\nimport pyvista as pv\nfrom pyvista import examples\n\nlidar = examples.download_lidar()\n\ntstart = time.time()\nclipped = lidar.clip(origin=(0, 0, 1.76e3), normal=(0, 0, 1))\nt_elapsed = time.time() - tstart\nprint(f\"Time to clip with a PolyData {t_elapsed:.2f} seconds.\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Plot the clipped polydata\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "clipped.plot(show_scalar_bar=False)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Show the performance improvement when using a PointSet. This is only\navailable with VTK \\>= 9.1.0.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# pset = lidar.cast_to_pointset()\n\nif pv.vtk_version_info >= (9, 1):\n    lidar_pset = lidar.cast_to_pointset()\n    tstart = time.time()\n    clipped_pset = lidar_pset.clip(origin=(0, 0, 1.76e3), normal=(0, 0, 1))\n    t_elapsed = time.time() - tstart\n    print(f\"Time to clip with a PointSet {t_elapsed:.2f} seconds.\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Plot the same dataset.\n\n::: note\n::: title\nNote\n:::\n\nPyVista must still create an intermediate PolyData to be able to plot,\nso there is no performance improvement when using a\n`pyvista.PointSet`{.interpreted-text role=\"class\"}\n:::\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "if pv.vtk_version_info >= (9, 1):\n    clipped_pset.plot(show_scalar_bar=False)"
      ]
    }
  ],
  "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
}