How to use the vispy.scene function in vispy

To help you get started, we’ve selected a few vispy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vispy / vispy / examples / basics / visuals / line_agg.py View on Github external
def move(self, (dx, dy)):
        """I call this when I want to translate."""
        self.translate = self.translate + (dx, -dy, 0, 0)
        
    def zoom(self, (dx, dy), center=(0., 0.)):
        """I call this when I want to zoom."""
        scale = (exp(0.01*dx), exp(0.01*dy), 1, 1)
        center = center + (0., 1.)
        self.translate = center + ((self.translate - center) * scale)
        self.scale = self.scale * scale




class PlotCanvas(scene.SceneCanvas):
    #def _normalize(self, (x, y)):
        #w, h = float(self.size[0]), float(self.size[1])
        #return x/(w/2.)-1., y/(h/2.)-1.
    
    def __init__(self, **kwargs):
        scene.SceneCanvas.__init__(self, keys='interactive', **kwargs)
        self._visuals = []
        self.panzoom = PanZoomTransform()
        self.panzoom.scale = (200, -200)
        self.panzoom.translate = (300, 300)
        self.doc_px_transform = STTransform(scale=(1, 1), translate=(0, 0))
        self.px_ndc_transform = STTransform(scale=(1, 1), translate=(0, 0))
        self._update_transforms()
        
    def _update_transforms(self):
        # Update doc and pixel transforms to account for new canvas shape.
github EtienneCmb / visbrain / visbrain / brain / base / CrossSecBase.py View on Github external
def __init__(self, parent=None):
        """Init."""
        logger.debug("Splitted cross-section should be a single image and not "
                     "three.")
        # Add PanZoom cameras to each box :
        parent['Sagit'].camera = scene.PanZoomCamera()
        parent['Coron'].camera = scene.PanZoomCamera()
        parent['Axial'].camera = scene.PanZoomCamera()
        # Define three images (Sagittal, Coronal, Axial) :
        kwargs_im = {'interpolation': 'bilinear'}
        self._cspSagit = visu.Image(name='SagitSplit', **kwargs_im)
        self._cspCoron = visu.Image(name='CoronSplit', **kwargs_im)
        self._cspAxial = visu.Image(name='AxialSplit', **kwargs_im)
        # Define three text object :
        kwargs_txt = {'color': 'white', 'font_size': 2, 'anchor_x': 'left',
                      'anchor_y': 'bottom'}
        self._cspTxtSagit = visu.Text(text='Sagit', **kwargs_txt)
        self._cspTxtCoron = visu.Text(text='Coron', **kwargs_txt)
        self._cspTxtAxial = visu.Text(text='Axial', **kwargs_txt)
        # Add each image to parent :
        parent['Sagit'].add(self._cspSagit)
        parent['Coron'].add(self._cspCoron)
github vispy / vispy / examples / scene / subplots.py View on Github external
"""

import time
from vispy import scene

from vispy import app
from vispy.util import transforms

# app.use('glut')

RES = 600
NCOLS = 6
NROWS = 6

# Create a figure
fig = scene.CanvasWithScene()
fig.size = RES, RES
fig.show()

# Add a simple normal pixelcamera. This camera looks at the many
# subplots. Each subplot has its own world with a visual and a camera.
scene.PixelCamera(fig.viewbox)

for col in range(NCOLS):
    for row in range(NROWS):
        # Create viewbox
        viewbox = scene.ViewBox(fig.viewbox)
        viewbox.transform[-1, 0] = col * RES / NCOLS
        viewbox.transform[-1, 1] = row * RES / NROWS
        viewbox.transform[0,0] = RES/NCOLS
        viewbox.transform[1,1] = RES/NROWS
        # Create a camera in the viewbox
github EtienneCmb / visbrain / visbrain / visuals / cbar / CbarVisual.py View on Github external
def __init__(self, parent=None, **kwargs):
        """Init."""
        # _____________________ INIT _____________________
        self._n = 1000
        self._ratio = 4 / 5
        CbarBase.__init__(self, **kwargs)

        # _____________________ CANVAS _____________________
        if parent is None:
            # Define a canvas :
            self._canvas = scene.SceneCanvas(keys='interactive', show=False,
                                             resizable=True, dpi=600,
                                             bgcolor=self._bgcolor,
                                             size=(300, 900))
            self._wc = self._canvas.central_widget.add_view()
            parent = self._wc.scene
            # Define the camera :
            self._camera = FixedCam(rect=(-1.2, -1.2, 2.4, 2.4))
            self._wc.camera = self._camera
        self.parent = parent

        # _____________________ OBJECTS _____________________
        # --------------------- Node ---------------------
        # Define node parent and limit node :
        self._cbNode = Node(name='Colorbar', parent=parent)
        self._limNode = Node(name='Limits', parent=self._cbNode)
        # Rescale between (-1., 1.) :
github EtienneCmb / visbrain / visbrain / gui / sleep / interface / ui_init.py View on Github external
# Create the main canvas :
        self.canvas = scene.SceneCanvas(keys=None, bgcolor=bgcolor, show=False,
                                        title=name)
        _ = [self.canvas.connect(k) for k in fcn]  # noqa

        # Add axis :
        if axis:
            # Create a grid :
            grid = self.canvas.central_widget.add_grid(margin=0)

            # Add y-axis :
            if use_pad:
                pad = grid.add_widget(row=1, col=0)
                pad.width_max = 50
            else:
                self.yaxis = scene.AxisWidget(orientation='left',
                                              text_color='black')
                self.yaxis.width_max = 50
                grid.add_widget(self.yaxis, row=1, col=0)

            # Add right padding :
            bottom_pad = grid.add_widget(row=2, col=0, row_span=1)
            bottom_pad.height_max = 10
            top_pad = grid.add_widget(row=0, col=0, row_span=1)
            top_pad.height_max = 10

            # Main plot :
            self.wc = grid.add_view(row=1, col=1, border_color='white')
        # Ignore axis :
        else:
            self.wc = self.canvas.central_widget.add_view()
github vispy / vispy / examples / basics / scene / isosurface.py View on Github external
# -----------------------------------------------------------------------------
# Copyright (c) Vispy Development Team. All Rights Reserved.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.
# -----------------------------------------------------------------------------

"""
This example demonstrates the use of the Isosurface visual.
"""

import sys
import numpy as np

from vispy import app, scene

# Create a canvas with a 3D viewport
canvas = scene.SceneCanvas(keys='interactive')
view = canvas.central_widget.add_view()


## Define a scalar field from which we will generate an isosurface
def psi(i, j, k, offset=(25, 25, 50)):
    x = i-offset[0]
    y = j-offset[1]
    z = k-offset[2]
    th = np.arctan2(z, (x**2+y**2)**0.5)
    r = (x**2 + y**2 + z**2)**0.5
    a0 = 1
    ps = ((1./81.) * 1./(6.*np.pi)**0.5 * (1./a0)**(3/2) * (r/a0)**2 *
          np.exp(-r/(3*a0)) * (3 * np.cos(th)**2 - 1))
    return ps

print("Generating scalar field..")
github MontrealCorpusTools / speechcorpustools / speechtools / plot / visuals.py View on Github external
def update_boundary(self, selected_index, new_time):
        if 0 <= selected_index < len(self.pos):
            p = self.pos
            p[selected_index][0] = new_time
            p[selected_index + 1][0] = new_time
            if selected_index % 6 == 0:
                p[selected_index+2][0] = new_time
            else:
                p[selected_index - 1][0] = new_time

            scene.visuals.Line.set_data(self, pos = p)
github vispy / vispy / examples / scene / stereo.py View on Github external
from vispy import app
from vispy.util import transforms


class MyFigure(scene.CanvasWithScene):
    def on_mouse_move(self, event):
        cam0.on_mouse_move(event)
#         cam2.on_mouse_move(event)

# Create figure with one pixel camera
fig = MyFigure()#scene.Figure()
fig.size = 800, 400
fig.show()
#camera = scene.NDCCamera(fig.viewvbox)
camera = scene.PixelCamera(fig.viewbox)

# Create two viewbox, use the same scene
vp1 = scene.ViewBox(fig.viewbox)
vp2 = scene.ViewBox(fig.viewbox)

# Put them next to each-other
transforms.scale(vp1.transform, 400, 400)
transforms.scale(vp2.transform, 400, 400)
transforms.translate(vp1.transform, 0)
transforms.translate(vp2.transform, 400, 0, 0)

# Create a world object to act as a container
# It is a child of both viewports
world = scene.Entity()
world.parents = vp1, vp2
github vispy / vispy / examples / basics / scene / contour.py View on Github external
canvas = scene.SceneCanvas(keys='interactive')
canvas.size = 600, 800
canvas.show()

# Set up a viewbox to display the image with interactive pan/zoom
view = canvas.central_widget.add_view()

interpolation = 'bicubic'
img_data = read_png(load_data_file('mona_lisa/mona_lisa_sm.png'))
image = scene.visuals.Image(img_data, interpolation=interpolation,
                            parent=view.scene, method='impostor')
level = 10
iso = IsolineFilter(level=level, width=1., color='white')

# Set 2D camera (the camera will scale to the contents in the scene)
view.camera = scene.PanZoomCamera(aspect=1)
# flip y-axis to have correct aligment
view.camera.flip = (0, 1, 0)
# select face part
view.camera.rect = (160, 130, 240, 200)

canvas.title = ('Spatial Filtering using %s Filter - Isoline %d level'
                % (image.interpolation, iso.level))

# get interpolation functions from Image
names = image.interpolation_functions
act = names.index(interpolation)


# Implement key presses
@canvas.events.key_press.connect
def on_key_press(event):
github DamCB / tyssue / tyssue / draw / vispy_draw.py View on Github external
def vp_view(sheet, coords=None, interactive=True, **draw_specs_kw):

    draw_specs = sheet_spec()
    spec_updater(draw_specs, draw_specs_kw)

    if coords is None:
        coords = ["x", "y", "z"]
    canvas = scene.SceneCanvas(keys="interactive", show=True)
    view = canvas.central_widget.add_view()
    view.camera = "turntable"
    view.camera.aspect = 1
    view.bgcolor = vp.color.Color("#222222")

    if draw_specs["face"]["visible"]:
        mesh = face_visual(sheet, coords, **draw_specs["face"])
        view.add(mesh)

    if draw_specs["edge"]["visible"]:
        wire = edge_visual(sheet, coords, **draw_specs["edge"])
        view.add(wire)

    canvas.show()
    view.camera.set_range()
    if interactive: