{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%gui qt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Nested Viewboxes\n\nSimple test of nested viewboxes, demonstrating the three methods that\ncan be used by a viewbox to provide clipping.\n\nIn the root scene are two viewboxes: the left viewbox uses the 'viewport'\nclipping method and a PanZoomCamera, whereas the right viewbox uses the 'fbo'\nclipping method and a base Camera (null transform).\n\nEach of these viewboxes contains again two viewboxes, with the same\ndifferences. In this way we test embedding each type of viewbox inside each\ntype.\n\nThis is what it should look like:\n\nThe plot line has a \"marker\" region on the left side that points in the +y\ndirection. In pixel coordinates, this is normally expected to point downward\n(because the pixel y-axis points down). However, the default behavior for\nPanZoomCamera is to reverse its internal y-axis relative to its parent.\n\n +-----------------+-----------------+\n | | vb1 uses | | vb2 uses |\n | | PanZoomCamera | | base Camera |\n | | (+y upward) | | (+y downward) |\n +=================+=================+\n | | |\n | +y upward | +y upward |\n | | |\n +-----------------+-----------------+\n | | |\n | +y downward | +y downward |\n | | |\n +-----------------+-----------------+\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from __future__ import division\n\nimport numpy as np\n\nfrom vispy import app\nfrom vispy import scene\n\n# gloo.gl.use('desktop debug')\n\n\n# Create lines for use in ndc and pixel coordinates\nN = 1000\ncolor = np.ones((N, 4), dtype=np.float32)\ncolor[:, 0] = np.linspace(0, 1, N)\ncolor[:, 1] = color[::-1, 0]\n\npos = np.empty((N, 2), np.float32)\npos[:, 0] = np.linspace(0., 1., N)\npos[:, 1] = np.random.normal(loc=0.5, scale=0.03, size=N)\npos[N//2:N//2+20, 1] = 0.9 # So we can see which side is up\n\n\n# Create canvas\ncanvas = scene.SceneCanvas(size=(800, 600), show=True, keys='interactive')\n\n#\n# Create viewboxes on left ...\n#\n\nw, h = canvas.size\nw2 = w / 2.\nh2 = h / 2.\n\n# left (+y up)\nvb1 = scene.widgets.ViewBox(parent=canvas.scene, name='vb1', \n margin=2, border_color='red')\nvb1.pos = 0, 0\nvb1.size = w2, h\nvb1.camera = 'panzoom'\nvb1.camera.rect = (0, 0, 1, 1)\nvb1.camera.interactive = False\n\n# bottom-left (+y down)\nvb11 = scene.widgets.ViewBox(parent=vb1.scene, name='vb11', border_width=2e-3, \n margin=0.02, border_color='green')\nvb11.pos = 0, 0\nvb11.size = 1, 0.5\nvb11.camera = 'panzoom'\nvb11.camera.rect = (0, 0, 1, 1)\nline11 = scene.visuals.Line(pos=pos, color=color, method='gl', \n parent=vb11.scene)\n\n# top-left (+y up)\nvb12 = scene.widgets.ViewBox(parent=vb1.scene, name='vb12', border_width=2e-3, \n margin=0.02, border_color='blue')\nvb12.pos = 0, 0.5\nvb12.size = 1, 0.5\nvb12.camera = 'base' # use parent cs\n# vb12 does not apply any scaling, so we do that manually here to match vb11\nline12 = scene.visuals.Line(pos=pos * [[1.0, 0.5]], color=color, method='gl', \n parent=vb12.scene)\n\n\n#\n# Create viewboxes on right ...\n#\n\n# right (+y down)\nvb2 = scene.widgets.ViewBox(parent=canvas.scene, name='vb2', \n margin=2, border_color='yellow')\nvb2.pos = w2, 0\nvb2.size = w2, h\nvb2.camera = 'base'\nvb2.camera.interactive = False\n\n# top-right (+y up)\nvb21 = scene.widgets.ViewBox(parent=vb2.scene, name='vb21', \n margin=10, border_color='purple')\nvb21.pos = 0, 0\nvb21.size = w2, h2\nvb21.camera = 'panzoom'\nvb21.camera.rect = (0, 0, 1, 1)\nline21 = scene.visuals.Line(pos=pos, color=color, method='gl', \n parent=vb21.scene)\n\n# bottom-right (+y down)\nvb22 = scene.widgets.ViewBox(parent=vb2.scene, name='vb22', \n margin=10, border_color='teal')\nvb22.pos = 0, h2\nvb22.size = w2, h2\nvb22.camera = 'base' # use parent cs\n# vb22 does not apply any scaling, so we do that manually here to match vb21\nline22 = scene.visuals.Line(pos=pos * [[w2, h2]], color=color, method='gl', \n parent=vb22.scene)\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 }