VTK Examples Python Animation - KitwarePublic
VTK Examples Python Animation - KitwarePublic
VTK/Examples/Python/AnimationKitwarePublic
VTK/Examples/Python/Animation
FromKitwarePublic
<VTK|Examples|Python
Thisexampleusesatimertomoveasphereacrossascene.
Contributedby:BryanConrad
Animation.py
importvtk
classvtkTimerCallback():
def__init__(self):
self.timer_count=0
defexecute(self,obj,event):
printself.timer_count
self.actor.SetPosition(self.timer_count,self.timer_count,0);
iren=obj
iren.GetRenderWindow().Render()
self.timer_count+=1
defmain():
#Createasphere
sphereSource=vtk.vtkSphereSource()
sphereSource.SetCenter(0.0,0.0,0.0)
sphereSource.SetRadius(5)
#Createamapperandactor
mapper=vtk.vtkPolyDataMapper()
mapper.SetInputConnection(sphereSource.GetOutputPort())
actor=vtk.vtkActor()
actor.SetMapper(mapper)
prop=actor.GetProperty()
#Setuparenderer,renderwindow,andinteractor
renderer=vtk.vtkRenderer()
renderWindow=vtk.vtkRenderWindow()
#renderWindow.SetWindowName("Test")
renderWindow.AddRenderer(renderer);
renderWindowInteractor=vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)
#Addtheactortothescene
renderer.AddActor(actor)
renderer.SetBackground(1,1,1)#Backgroundcolorwhite
#Renderandinteract
renderWindow.Render()
http://www.cmake.org/Wiki/VTK/Examples/Python/Animation
1/2
11/24/2014
VTK/Examples/Python/AnimationKitwarePublic
#Initializemustbecalledpriortocreatingtimerevents.
renderWindowInteractor.Initialize()
#SignuptoreceiveTimerEvent
cb=vtkTimerCallback()
cb.actor=actor
renderWindowInteractor.AddObserver('TimerEvent',cb.execute)
timerId=renderWindowInteractor.CreateRepeatingTimer(100);
#starttheinteractionandtimer
renderWindowInteractor.Start()
if__name__=='__main__':
main()
Retrievedfrom"http://www.cmake.org/Wiki/VTK/Examples/Python/Animation"
Thispagewaslastmodifiedon6January2010,at18:57.
ContentisavailableunderAttribution2.5.
http://www.cmake.org/Wiki/VTK/Examples/Python/Animation
2/2