设置显示屏幕上所有项目的vispy自动缩放,如pyqtgraph autoRange()函数

2024-05-19 15:05:14 发布

您现在位置:Python中文网/ 问答频道 /正文

是否可以像pyqtgraph一样为vispy实现自动范围功能?我有搜索功能,但找不到实现它的任何方法或替代方法

下面是示例代码

from itertools import cycle

import numpy as np

from vispy import app, scene, io
from vispy.color import get_colormaps, BaseColormap

# Read volume
vol2 = np.load(io.load_data_file('brain/mri.npz'))['data']
vol2 = np.flipud(np.rollaxis(vol2, 1))

# Prepare canvas
canvas = scene.SceneCanvas(keys='interactive', size=(800, 600), show=True)
canvas.measure_fps()

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

# Set whether we are emulating a 3D texture
emulate_texture = False

# Create the volume visuals, only one is visible
volume1 = scene.visuals.Volume(vol2, parent=view.scene, threshold=0.225,
                               emulate_texture=emulate_texture)
# volume1.transform = scene.STTransform(translate=(64, 64, 0))
volume1.transform = scene.STTransform(scale=(3,3,3))
volume2 = scene.visuals.Volume(vol2, parent=view.scene, threshold=0.2,
                               emulate_texture=emulate_texture)
volume2.visible = False

print(volume1.bounds(0), volume1.bounds(1), volume1.bounds(2))

# Create two cameras (1 for firstperson, 3 for 3d person)
fov = 60.
cam1 = scene.cameras.FlyCamera(parent=view.scene, fov=fov)
cam2 = scene.cameras.TurntableCamera(parent=view.scene, fov=fov)
cam3 = scene.cameras.ArcballCamera(parent=view.scene, fov=fov)
view.camera = cam2  # Select turntable at first

if __name__ == '__main__':
    print(__doc__)
    app.run()

Tags: fromimportviewnpsceneparentcanvasvispy