python 中删除VTK鼠标交互函数

tt posted @ 2008年11月29日 23:15 in Python with tags python vtk 交互函数 , 5277 阅读

在VTK文档中看到的有些函数在python中没进行封装,也没有相关文档,通过测试,下面的程序可以实现删除指定的交互函数

#!/usr/bin/env python

import vtk

t1 = 0
t2 = 0
t3 = 0
iren = vtk.vtkRenderWindowInteractor()

def pickerfunc (object, event):
    if event == 'LeftButtonPressEvent':
    print 'DOK'
    print t1
   
    if event == 'LeftButtonReleaseEvent':
    print 'ROK'
    print t2

    if event == 'RightButtonPressEvent':
    print t3
    iren.RemoveObserver (t1)
    iren.RemoveObserver (t2)
    iren.RemoveObserver (t3)
   

def main():
    cone = vtk.vtkConeSource()
    cone.SetHeight( 3.0 )
    cone.SetRadius( 1.0 )
    cone.SetResolution( 10 )

    map = vtk.vtkPolyDataMapper()
    map.SetInputConnection(cone.GetOutputPort())

    actor = vtk.vtkActor()
    actor.SetMapper(map)

    ren = vtk.vtkRenderer()
    ren.AddActor(actor)
    ren.SetBackground(0.1, 0.2, 0.4)

    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    renWin.SetSize(300, 300)

    iren.SetRenderWindow(renWin)
    style = vtk.vtkInteractorStyleTrackballCamera()
    iren.SetInteractorStyle(style)
   
    global t1
    global t2
    global t3
    t1 = iren.AddObserver ("LeftButtonPressEvent", pickerfunc)
    t2 = iren.AddObserver ("LeftButtonReleaseEvent", pickerfunc)
    t3 = iren.AddObserver ("RightButtonPressEvent", pickerfunc)

    iren.Initialize()
    iren.Start()

if __name__ == "__main__":
    main()

通过交互函数的返回值,获取相关t1,t2,t3信息,依据此删除指定事件的交互函数,

如果用 iren.AddObserver("RightButtonPressEvent")将删除右键相关的所有交互函数,

Avatar_small
net worth 说:
2023年7月19日 15:43

Checking out the information of any celebrity on idol net worth to know how much their name and fame worth and their family members.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter