整理于 https://www.icourse163.org/course/BIT-1001871001(Python科学计算三维可视化)
IVTK工具
引入该工具:
from tvtk.tools import ivtk
以下举例:
from tvtk.api import tvtk
from tvtk.tools import ivtk
from pyface.api import GUI
s = tvtk.CubeSource(x_length = 1.0,y_length=2.0,z_length = 3.0)
m = tvtk.PolyDataMapper(input_connection=s.output_port)
a = tvtk.Actor(mapper = m)
gui = GUI() #创建一个Crust窗口
win = ivtk.IVTKWithCrustAndBrowser()
win.open()
win.scene.add_actor(a)
gui.start_enent_loop()#开始界面消息循环
对比1.2.1的部分
r.add_actor(a)
w = tvtk.RenderWindow(size = (300,300)) #创建窗口
w.add_renderer(r)
i = tvtk.RenderWindowInteractor(render_window = w)
i.initialize() #开启交互
i.start()
gui = GUI() #创建一个Crust窗口
win = ivtk.IVTKWithCrustAndBrowser()
win.open()
win.scene.add_actor(a)
gui.start_event_loop()#开始界面消息循环
GUI修改之后:
from tvtk.api import tvtk
from tvtk.tools import ivtk
from pyface.api import GUI
s = tvtk.CubeSource(x_length = 1.0,y_length=2.0,z_length = 3.0)
m = tvtk.PolyDataMapper(input_connection=s.output_port)
a = tvtk.Actor(mapper = m)
gui = GUI()
win = ivtk.IVTKWithCrustAndBrowser()
win.open()
win.scene.add_actor(a)
#错误修正,确定窗口,让它成为一个子窗口
dialog = win.control.centralWidget().widget(0).widget(0)
from pyface.qt import QtCore
dialog.setWindowFlags(QtCore.Qt.WindowFlags(0x00000000))
dialog.show()
gui.start_event_loop()#开始界面消息循环
加强程序的可读性:
from tvtk.api import tvtk
def ivtk_scene(actors):
from tvtk.tools import ivtk
win = ivtk.IVTKWithCrustAndBrowser()
win.open()
win.scene.add_actor(actors)
dialog = win.control.centralWidget().widget(0).widget(0)
from pyface.qt import QtCore
dialog.setWindowFlags(QtCore.Qt.WindowFlags(0x00000000))
dialog.show()
return win
def event_loop():
from pyface.api import GUI
gui = GUI()
gui.start_event_loop()
s = tvtk.CubeSource(x_length = 1.0,y_length=2.0,z_length = 3.0)
m = tvtk.PolyDataMapper(input_connection=s.output_port)
a = tvtk.Actor(mapper = m)
win = ivtk_scene(a)
win.scene.isometric_view()
event_loop()
注意,左窗口提供了管线浏览器,树形展开,下方提供python命令窗口
照相机属性:
clipping_plane:包含两个元素,分别表示照相机到远近两个裁剪平面的距离。在这两个平面范围之外将不会显示。
position:照相机在三维空间中的坐标
focal_point:照相机所聚焦的焦点坐标
view_up:照相机上方向矢量
light可以对光源进行设置,颜色和光源数,scene中可以设置背景