{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%gui qt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Share Camera Views\n\nDemonstrating two scenes that share the same camera view by linking the\ncameras.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\n\nfrom vispy import app, scene, io\n\ncanvas = scene.SceneCanvas(keys='interactive')\ncanvas.size = 800, 600\ncanvas.show()\n\n# Create two ViewBoxes, place side-by-side\nvb1 = scene.widgets.ViewBox(border_color='yellow', parent=canvas.scene)\nvb2 = scene.widgets.ViewBox(border_color='blue', parent=canvas.scene)\n#\ngrid = canvas.central_widget.add_grid()\ngrid.padding = 6\ngrid.add_widget(vb1, 0, 0)\ngrid.add_widget(vb2, 0, 1)\n\n# Create the image\nim1 = io.load_crate().astype('float32') / 255\n# Make gray, smooth, and take derivatives: edge enhancement\nim2 = im1[:, :, 1]\nim2 = (im2[1:-1, 1:-1] + im2[0:-2, 1:-1] + im2[2:, 1:-1] + \n im2[1:-1, 0:-2] + im2[1:-1, 2:]) / 5\nim2 = 0.5 + (np.abs(im2[0:-2, 1:-1] - im2[1:-1, 1:-1]) + \n np.abs(im2[1:-1, 0:-2] - im2[1:-1, 1:-1]))\n\nimage1 = scene.visuals.Image(im1, parent=vb1.scene)\nimage2 = scene.visuals.Image(im2, parent=vb2.scene)\n\n# Set 2D camera (PanZoomCamera, TurnTableCamera)\nvb1.camera, vb2.camera = scene.PanZoomCamera(), scene.PanZoomCamera()\nvb1.camera.aspect = vb2.camera.aspect = 1 # no auto-scale\nvb1.camera.link(vb2.camera)\n\n# Set the view bounds to show the entire image with some padding\nvb1.camera.set_range()\n\n\nif __name__ == '__main__':\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 }