{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%gui qt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Isosurface Visual\n\nThis example demonstrates the use of the Isosurface visual.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import sys\nimport numpy as np\n\nfrom vispy import app, scene\n\n# Create a canvas with a 3D viewport\ncanvas = scene.SceneCanvas(keys='interactive')\nview = canvas.central_widget.add_view()\n\n\n# Define a scalar field from which we will generate an isosurface\ndef psi(i, j, k, offset=(25, 25, 50)):\n x = i-offset[0]\n y = j-offset[1]\n z = k-offset[2]\n th = np.arctan2(z, (x**2+y**2)**0.5)\n r = (x**2 + y**2 + z**2)**0.5\n a0 = 1\n ps = ((1./81.) * 1./(6.*np.pi)**0.5 * (1./a0)**(3/2) * (r/a0)**2 *\n np.exp(-r/(3*a0)) * (3 * np.cos(th)**2 - 1))\n return ps\n\nprint(\"Generating scalar field..\")\ndata = np.abs(np.fromfunction(psi, (50, 50, 100)))\n\n# Create isosurface visual\nsurface = scene.visuals.Isosurface(data, level=data.max()/4.,\n color=(0.5, 0.6, 1, 1), shading='smooth',\n parent=view.scene)\nsurface.transform = scene.transforms.STTransform(translate=(-25, -25, -50))\n\n# Add a 3D axis to keep us oriented\naxis = scene.visuals.XYZAxis(parent=view.scene)\n\n# Use a 3D camera\n# Manual bounds; Mesh visual does not provide bounds yet\n# Note how you can set bounds before assigning the camera to the viewbox\ncam = scene.TurntableCamera(elevation=30, azimuth=30)\ncam.set_range((-10, 10), (-10, 10), (-10, 10))\nview.camera = cam\n\n\nif __name__ == '__main__':\n canvas.show()\n if sys.flags.interactive == 0:\n app.run()" ] } ], "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.9.19" } }, "nbformat": 4, "nbformat_minor": 0 }