1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright (c) Vispy Development Team. All Rights Reserved.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.
# -----------------------------------------------------------------------------
# vispy: gallery 2
"""
Nested Viewboxes
================
Simple test of nested viewboxes, demonstrating the three methods that
can be used by a viewbox to provide clipping.
In the root scene are two viewboxes: the left viewbox uses the 'viewport'
clipping method and a PanZoomCamera, whereas the right viewbox uses the 'fbo'
clipping method and a base Camera (null transform).
Each of these viewboxes contains again two viewboxes, with the same
differences. In this way we test embedding each type of viewbox inside each
type.
This is what it should look like:
The plot line has a "marker" region on the left side that points in the +y
direction. In pixel coordinates, this is normally expected to point downward
(because the pixel y-axis points down). However, the default behavior for
PanZoomCamera is to reverse its internal y-axis relative to its parent.
+-----------------+-----------------+
| | vb1 uses | | vb2 uses |
| | PanZoomCamera | | base Camera |
| | (+y upward) | | (+y downward) |
+=================+=================+
| | |
| +y upward | +y upward |
| | |
+-----------------+-----------------+
| | |
| +y downward | +y downward |
| | |
+-----------------+-----------------+
"""
from __future__ import division
import numpy as np
from vispy import app
from vispy import scene
# gloo.gl.use('desktop debug')
# Create lines for use in ndc and pixel coordinates
N = 1000
color = np.ones((N, 4), dtype=np.float32)
color[:, 0] = np.linspace(0, 1, N)
color[:, 1] = color[::-1, 0]
pos = np.empty((N, 2), np.float32)
pos[:, 0] = np.linspace(0., 1., N)
pos[:, 1] = np.random.normal(loc=0.5, scale=0.03, size=N)
pos[N//2:N//2+20, 1] = 0.9 # So we can see which side is up
# Create canvas
canvas = scene.SceneCanvas(size=(800, 600), show=True, keys='interactive')
#
# Create viewboxes on left ...
#
w, h = canvas.size
w2 = w / 2.
h2 = h / 2.
# left (+y up)
vb1 = scene.widgets.ViewBox(parent=canvas.scene, name='vb1',
margin=2, border_color='red')
vb1.pos = 0, 0
vb1.size = w2, h
vb1.camera = 'panzoom'
vb1.camera.rect = (0, 0, 1, 1)
vb1.camera.interactive = False
# bottom-left (+y down)
vb11 = scene.widgets.ViewBox(parent=vb1.scene, name='vb11', border_width=2e-3,
margin=0.02, border_color='green')
vb11.pos = 0, 0
vb11.size = 1, 0.5
vb11.camera = 'panzoom'
vb11.camera.rect = (0, 0, 1, 1)
line11 = scene.visuals.Line(pos=pos, color=color, method='gl',
parent=vb11.scene)
# top-left (+y up)
vb12 = scene.widgets.ViewBox(parent=vb1.scene, name='vb12', border_width=2e-3,
margin=0.02, border_color='blue')
vb12.pos = 0, 0.5
vb12.size = 1, 0.5
vb12.camera = 'base' # use parent cs
# vb12 does not apply any scaling, so we do that manually here to match vb11
line12 = scene.visuals.Line(pos=pos * [[1.0, 0.5]], color=color, method='gl',
parent=vb12.scene)
#
# Create viewboxes on right ...
#
# right (+y down)
vb2 = scene.widgets.ViewBox(parent=canvas.scene, name='vb2',
margin=2, border_color='yellow')
vb2.pos = w2, 0
vb2.size = w2, h
vb2.camera = 'base'
vb2.camera.interactive = False
# top-right (+y up)
vb21 = scene.widgets.ViewBox(parent=vb2.scene, name='vb21',
margin=10, border_color='purple')
vb21.pos = 0, 0
vb21.size = w2, h2
vb21.camera = 'panzoom'
vb21.camera.rect = (0, 0, 1, 1)
line21 = scene.visuals.Line(pos=pos, color=color, method='gl',
parent=vb21.scene)
# bottom-right (+y down)
vb22 = scene.widgets.ViewBox(parent=vb2.scene, name='vb22',
margin=10, border_color='teal')
vb22.pos = 0, h2
vb22.size = w2, h2
vb22.camera = 'base' # use parent cs
# vb22 does not apply any scaling, so we do that manually here to match vb21
line22 = scene.visuals.Line(pos=pos * [[w2, h2]], color=color, method='gl',
parent=vb22.scene)
if __name__ == '__main__':
app.run()
|