Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(
self, icurves, highlight=None, clrmap="husl", colors=None, parent=None, itermode=False
):
"""
:param icurves: input curve or list of curves
:param clrmap: (optional) what colormap name from vispy.colormap to use
:param colors: (optional) use list of colors instead of colormap
"""
self.canvas = scene.SceneCanvas(
size=(1280, 900),
position=(200, 200),
keys="interactive",
bgcolor=bg_clr,
parent=parent,
)
self.grid = self.canvas.central_widget.add_grid(spacing=0)
self.view = self.grid.add_view(row=0, col=1, camera="panzoom")
curves = np.array(icurves)
if len(curves.shape) == 1:
## Single curve
curves = np.array([icurves])
nb_traces, size = curves.shape
# Distributed under the (new) BSD License. See LICENSE.txt for more info.
"""
This example demonstrates how to visualise a NetworkX graph using a VisPy
Graph.
"""
import sys
import networkx as nx
from vispy import app, scene
from vispy.visuals.graphs import layouts
canvas = scene.SceneCanvas(title='Simple NetworkX Graph', size=(600, 600),
bgcolor='white', show=True)
view = canvas.central_widget.add_view('panzoom')
graph = nx.adjacency_matrix(
nx.fast_gnp_random_graph(500, 0.005, directed=True))
layout = layouts.get_layout('force_directed', iterations=100)
visual = scene.visuals.Graph(
graph, layout=layout, line_color='black', arrow_type="stealth",
arrow_size=30, node_symbol="disc", node_size=20,
face_color=(1, 0, 0, 0.2), border_width=0.0, animate=True, directed=False,
parent=view.scene)
@canvas.events.draw.connect
def on_draw(event):
"""
Demonstration of a mesh constructed in a grid about x,y,z coordinates.
"""
import sys
from vispy import scene
from vispy.color import get_colormap
import numpy as np
from scipy.special import sph_harm
canvas = scene.SceneCanvas(keys='interactive')
view = canvas.central_widget.add_view()
thetas, phis = np.meshgrid(np.linspace(0, np.pi, 100),
np.linspace(0, 2*np.pi, 150))
shape = thetas.shape
linear_shape = thetas.shape[0] * thetas.shape[1]
cm = get_colormap('hot')
for harm_degree in range(3):
for harm_order in range(harm_degree + 1):
harmonic_values = sph_harm(harm_order, harm_degree, phis, thetas).real
rs = 1. + 0.4*harmonic_values
xs = rs * np.sin(thetas) * np.cos(phis)
ys = rs * np.sin(thetas) * np.sin(phis)
zs = rs * np.cos(thetas)
def sheet_view(sheet, coords=None, interactive=True, **draw_specs_kw):
"""Uses VisPy to display an epithelium
"""
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, size=(1240, 720))
view = canvas.central_widget.add_view()
view.camera = "turntable"
view.camera.aspect = 1
view.bgcolor = vp.color.Color("#222222")
if draw_specs["edge"]["visible"]:
wire = edge_visual(sheet, coords, **draw_specs["edge"])
view.add(wire)
if draw_specs["face"]["visible"]:
mesh = face_visual(sheet, coords, **draw_specs["face"])
view.add(mesh)
canvas.show()
view.camera.set_range()
if interactive:
app.run()
return canvas, view
from vispy import app, scene
from vispy.color import get_colormaps
from vispy.visuals.transforms import STTransform
from vispy.ext.six import next
colormaps = itertools.cycle(get_colormaps())
# vertex positions of data to draw
N = 200
pos = np.zeros((N, 2), dtype=np.float32)
pos[:, 0] = np.linspace(10, 390, N)
pos[:, 1] = np.random.normal(size=N, scale=20, loc=0)
canvas = scene.SceneCanvas(keys='interactive', size=(400, 200), show=True)
# Create a visual that updates the line with different colormaps
color = next(colormaps)
line = scene.Line(pos=pos, color=color, method='gl')
line.transform = STTransform(translate=[0, 140])
line.parent = canvas.central_widget
text = scene.Text(color, bold=True, font_size=24, color='w',
pos=(200, 40), parent=canvas.central_widget)
def on_timer(event):
global colormaps, line, text, pos
color = next(colormaps)
line.set_data(pos=pos, color=color)
text.text = color
from vispy.scene.visuals import Mesh
from vispy.visuals.filters import TextureFilter
parser = argparse.ArgumentParser()
parser.add_argument('--shading', default='smooth',
choices=['none', 'flat', 'smooth'],
help="shading mode")
args = parser.parse_args()
mesh_path = load_data_file('spot/spot.obj.gz')
texture_path = load_data_file('spot/spot.png')
vertices, faces, normals, texcoords = read_mesh(mesh_path)
texture = np.flipud(imread(texture_path))
canvas = scene.SceneCanvas(keys='interactive', bgcolor='white',
size=(800, 600))
view = canvas.central_widget.add_view()
view.camera = 'arcball'
# Adapt the depth to the scale of the mesh to avoid rendering artefacts.
view.camera.depth_value = 10 * (vertices.max() - vertices.min())
shading = None if args.shading == 'none' else args.shading
mesh = Mesh(vertices, faces, shading=shading, color='white')
mesh.shininess = 1e-3
view.add(mesh)
texture_filter = TextureFilter(texture, texcoords)
mesh.attach(texture_filter)
@property
def vol(self):
return self.volumeRenderWidget.vol
#
# @volumeRenderWidget.connect
# def on_frame(self,event):
# self.volumeRenderWidget.cam1.auto_roll
def writevideo(self,fps=25):
writer = imageio.save('foo.mp4', fps=25)
self.volumeRenderWidget.events.draw.connect(lambda e: writer.append_data(self.render()))
self.volumeRenderWidget.events.close.connect(lambda e: writer.close())
class VolumeRenderWidget(scene.SceneCanvas):
def __init__(self,vol=None, path=None, size=(800,600), show=False):
super(VolumeRenderWidget, self).__init__(keys='interactive', size=size, show=show)
# Prepare canvas
self.measure_fps()
#self.unfreeze()
# Set up a viewbox to display the image with interactive pan/zoom
self.view = self.central_widget.add_view()
self.vol=None
self.setVolume(vol,path)
self.volume=None
def debug(self, measurements, file_path, add_geodesic):
# Model object
model = mesh_lib.Model(file_path)
model_point_coordinates = model.get_coords()
canvas = scene.SceneCanvas(keys='interactive')
view = canvas.central_widget.add_view()
# all model - GREEN
points = Markers(parent=view.scene)
points.set_data(
pos=model_point_coordinates,
edge_color=None,
face_color=(0, 1, 0, .3),
size=5
)
for m in measurements: # measurements in config file
# parsing key vertexes and description text
point_1 = int(m[1]) + 1
point_2 = int(m[2]) + 1
point_3 = int(m[3]) + 1
# -----------------------------------------------------------------------------
# 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 SurfacePlot visual.
"""
import sys
import numpy as np
from vispy import app, scene
from vispy.util.filter import gaussian_filter
canvas = scene.SceneCanvas(keys='interactive', bgcolor='w')
view = canvas.central_widget.add_view()
view.camera = scene.TurntableCamera(up='z', fov=60)
# Simple surface plot example
# x, y values are not specified, so assumed to be 0:50
z = np.random.normal(size=(250, 250), scale=200)
z[100, 100] += 50000
z = gaussian_filter(z, (10, 10))
p1 = scene.visuals.SurfacePlot(z=z, color=(0.3, 0.3, 1, 1))
p1.transform = scene.transforms.MatrixTransform()
p1.transform.scale([1/249., 1/249., 1/249.])
p1.transform.translate([-0.5, -0.5, 0])
view.add(p1)
# p1._update_data() # cheating.
"""
Simple test of SceneCanvas containing a single line entity
as its entire scenegraph.
"""
from vispy import app
from vispy.scene.visuals import LineAgg
from vispy.scene import SceneCanvas, LineAgg, ViewBox
import numpy as np
canvas = SceneCanvas(keys='interactive')
vb = ViewBox(parent=canvas.scene)
@canvas.events.resize.connect
def resize(event):
global vb, canvas
vb.size = canvas.size
canvas.size = 600, 600
canvas.show()
x = np.linspace(0, 1, 1000)
y = np.sin(15*x) + 0.5
vertices1 = np.c_[x,y]