{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Wrapping Other Objects {#wrap_trimesh}\n\nYou can wrap several other object types using pyvista including:\n\n-   [numpy]{.title-ref} arrays\n-   [trimesh.Trimesh]{.title-ref} meshes\n-   VTK objects\n\nThis allows for the \\\"best of both worlds\\\" programming special to\nPython due to its modularity. If there\\'s some limitation of pyvista (or\ntrimesh), then you can adapt your scripts to use the best features of\nmore than one module.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        ""
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Wrap a point cloud composed of random points from numpy\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\n\nimport pyvista as pv\n\npoints = np.random.default_rng().random((30, 3))\ncloud = pv.wrap(points)\npv.plot(\n    cloud,\n    scalars=points[:, 2],\n    render_points_as_spheres=True,\n    point_size=50,\n    opacity=points[:, 0],\n    cpos='xz',\n)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Wrap an instance of Trimesh\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import trimesh\n\npoints = [[0, 0, 0], [0, 0, 1], [0, 1, 0]]\nfaces = [[0, 1, 2]]\ntmesh = trimesh.Trimesh(points, faces=faces, process=False)\nmesh = pv.wrap(tmesh)\nprint(mesh)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Wrap an instance of vtk.vtkPolyData\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import vtk\n\npoints = vtk.vtkPoints()\np = [1.0, 2.0, 3.0]\nvertices = vtk.vtkCellArray()\npid = points.InsertNextPoint(p)\nvertices.InsertNextCell(1)\nvertices.InsertCellPoint(pid)\npoint = vtk.vtkPolyData()\npoint.SetPoints(points)\npoint.SetVerts(vertices)\nmesh = pv.wrap(point)\nprint(mesh)"
      ]
    }
  ],
  "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
}