python 中vtk交互函数设定

tt posted @ 2008年11月15日 19:10 in vtk , 6904 阅读

由于在python中没有vtkCallbackCommand属性,只能采取其他方式设定鼠标交互,其实在python中设定交互更方便,看一个简单的例子tl.py

#!/usr/bin/env python

import vtk

picker = vtk.vtkCellPicker()

def pickerfunc (object, event):
    #style = clientdata;
    #pickPos = picker.GetPickPosition()
    #print event
    if event == 'LeftButtonPressEvent':
    print 'DOK'
    if event == 'LeftButtonReleaseEvent':
    print 'ROK'

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 = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

style = vtk.vtkInteractorStyleTrackballCamera()
iren.SetInteractorStyle(style)

picker.AddObserver("EndPickEvent", pickerfunc)     #将事件与回调函数建立连接
style.AddObserver ('LeftButtonPressEvent', pickerfunc)
style.AddObserver ('LeftButtonReleaseEvent', pickerfunc)
style.AddObserver ('MouseMoveEvent', pickerfunc)

#style.RemoveObservers ('LeftButtonPressEvent')        ##删除消息事件连接
#style.RemoveObservers ('LeftButtonReleaseEvent')
#style.RemoveObservers ('MouseMoveEvent')

iren.SetPicker (picker)

iren.Initialize()
iren.Start()

上面的函数可以实现在python中设定picker的消息处理函数,

Avatar_small
Things to do 说:
2023年10月12日 17:19

We understand the importance of staying up to date with the latest trends and hidden gems. things to do post constantly scours the city, uncovering new attractions and upcoming events to keep our content fresh and exciting. We aim to be your constant source of inspiration, making sure you're always in the know about the hottest happenings.


登录 *


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