-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_window.py
More file actions
38 lines (30 loc) · 1.07 KB
/
test_window.py
File metadata and controls
38 lines (30 loc) · 1.07 KB
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
import sys
import numpy as np
from mayavi import mlab
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
# 创建一个随机的体素网格
voxelgrid = np.random.randint(0, 2, size=(10, 10, 10))
# 创建PyQtGraph的窗口
app = QtGui.QApplication([])
win = pg.GraphicsLayoutWidget(show=True, title="Voxelgrid Example")
view = win.addViewBox()
view.setAspectLocked(True)
# 创建Mayavi的场景
fig = mlab.figure(size=(500, 500), bgcolor=(0.7, 0.7, 0.7))
mlab.clf()
# 将体素网格数据传递给Mayavi
src = mlab.pipeline.scalar_field(voxelgrid)
# 创建体素网格的等值面
mlab.pipeline.iso_surface(src, contours=[0.5], opacity=0.5)
# 将Mayavi的场景渲染到PyQtGraph的窗口中
mlab.view(azimuth=45, elevation=45)
mlab.orientation_axes()
mlab.savefig("voxelgrid.png")
mlab.show()
# 将Mayavi的渲染结果显示在PyQtGraph的窗口中
img = pg.ImageItem(np.array(mlab.screenshot(antialiased=True)))
view.addItem(img)
# 运行PyQtGraph的事件循环
if sys.flags.interactive != 1 or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()