{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Table of Glyphs {#glyph_table_example}\n\n`vtk` supports tables of glyphs from which glyphs are looked up. This\nexample demonstrates this functionality.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\n\nimport pyvista as pv" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can allow tables of glyphs in a backward-compatible way by allowing a\nsequence of geometries as well as single (scalar) geometries to be\npassed as the `geom` kwarg of\n`pyvista.DataSetFilters.glyph`{.interpreted-text role=\"func\"}. An\n`indices` optional keyword specifies the index of each glyph geometry in\nthe table, and it has to be the same length as `geom` if specified. If\nit is absent a default value of `range(len(geom))` is assumed.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# get dataset for the glyphs: supertoroids in xy plane\n# use N random kinds of toroids over a mesh with 27 points\nN = 5\nvalues = np.arange(N) # values for scalars to look up glyphs by\n\n\n# taken from:\n# rng = np.random.default_rng()\n# params = rng.uniform(0.5, 2, size=(N, 2)) # (n1, n2) parameters for the toroids\nparams = np.array(\n [\n [1.56821334, 0.99649769],\n [1.08247844, 1.83758874],\n [1.49598881, 0.83495047],\n [1.52442129, 0.89600688],\n [1.92212387, 0.78096621],\n ],\n)\n\ngeoms = [pv.ParametricSuperToroid(n1=n1, n2=n2) for n1, n2 in params]\n\n# get dataset where to put glyphs\nx, y, z = np.mgrid[:3.0, :3.0, :3.0]\nmesh = pv.StructuredGrid(x, y, z)\n\n# add random scalars\n# rng_int = rng.integers(0, N, size=x.size)\nrng_int = np.array(\n [4, 1, 2, 0, 4, 0, 1, 4, 3, 1, 1, 3, 3, 4, 3, 4, 4, 3, 3, 2, 2, 1, 1, 1, 2, 0, 3],\n)\nmesh.point_data['scalars'] = rng_int\n\n# construct the glyphs on top of the mesh; don't scale by scalars now\nglyphs = mesh.glyph(geom=geoms, indices=values, scale=False, factor=0.3, rng=(0, N - 1))\n\n# create plotter and add our glyphs with some nontrivial lighting\nplotter = pv.Plotter()\nplotter.add_mesh(glyphs, specular=1, specular_power=15, smooth_shading=True, show_scalar_bar=False)\nplotter.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 }