-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain_Vispy-pyside2_TinyDemo.py
51 lines (43 loc) · 1.82 KB
/
Main_Vispy-pyside2_TinyDemo.py
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
from Ui_test_vispy import Ui_MainWindow
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
import sys
import vispy.scene
from vispy.scene import visuals
import numpy as np
class IndexController(QMainWindow,Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
# vispy.scene
self.canvas = vispy.scene.SceneCanvas(keys='interactive', show=True)
self.view = self.canvas.central_widget.add_view()
# addWidget
self.verticalLayout_2.addWidget(self.canvas.native)
self.pushButton.clicked.connect(self.showVispy)
def showVispy(self):
# generate data
pos = np.random.normal(size=(100000, 3), scale=0.2)
# one could stop here for the data generation, the rest is just to make the
# data look more interesting. Copied over from magnify.py
centers = np.random.normal(size=(50, 3))
indexes = np.random.normal(size=100000, loc=centers.shape[0] / 2.,
scale=centers.shape[0] / 3.)
indexes = np.clip(indexes, 0, centers.shape[0] - 1).astype(int)
scales = 10 ** (np.linspace(-2, 0.5, centers.shape[0]))[indexes][:, np.newaxis]
pos *= scales
pos += centers[indexes]
# create scatter object and fill in the data
scatter = visuals.Markers()
scatter.set_data(pos, edge_color=None, face_color=(1, 1, 1, .5), size=5)
self.view.add(scatter)
self.view.camera = 'turntable' # or try 'arcball'
# add a colored 3D axis for orientation
axis = visuals.XYZAxis(parent=self.view.scene)
if __name__ == '__main__':
app = QApplication([])
main = IndexController()
main.show()
# vispy.app.run()
sys.exit(app.exec_())