0% found this document useful (0 votes)
297 views

VTK Examples Python Animation - KitwarePublic

This Python script uses VTK to animate a sphere moving across the scene. A timer callback method is used to increment the sphere's position each frame. The renderer, window, and interactor are set up to display the scene. The timer is started to trigger the callback and animate the sphere moving.

Uploaded by

Manu Mannu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
297 views

VTK Examples Python Animation - KitwarePublic

This Python script uses VTK to animate a sphere moving across the scene. A timer callback method is used to increment the sphere's position each frame. The renderer, window, and interactor are set up to display the scene. The timer is started to trigger the callback and animate the sphere moving.

Uploaded by

Manu Mannu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

11/24/2014

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

You might also like