-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestanimate.py
92 lines (72 loc) · 1.94 KB
/
testanimate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# testanimate.py ---
#
# Filename: testanimate.py
# Description:
# Author: Subhasis Ray
# Maintainer:
# Created: Tue Sep 27 16:03:27 2011 (+0530)
# Version:
# Last-Updated: Tue Sep 27 16:03:30 2011 (+0530)
# By: Subhasis Ray
# Update #: 1
# URL:
# Keywords:
# Compatibility:
#
#
# Commentary:
#
#
#
#
# Change log:
#
#
#
# Code:
import vtk
class vtkTimerCallback():
def __init__(self):
self.timer_count = 0
def execute(self,obj,event):
print self.timer_count
self.actor.SetPosition(self.timer_count, self.timer_count,0);
iren = obj
iren.GetRenderWindow().Render()
self.timer_count += 1
def main():
#Create a sphere
sphereSource = vtk.vtkSphereSource()
sphereSource.SetCenter(0.0, 0.0, 0.0)
sphereSource.SetRadius(5)
#Create a mapper and actor
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(sphereSource.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
prop = actor.GetProperty()
# Setup a renderer, render window, and interactor
renderer = vtk.vtkRenderer()
renderWindow = vtk.vtkRenderWindow()
#renderWindow.SetWindowName("Test")
renderWindow.AddRenderer(renderer);
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)
#Add the actor to the scene
renderer.AddActor(actor)
renderer.SetBackground(1,1,1) # Background color white
#Render and interact
renderWindow.Render()
# Initialize must be called prior to creating timer events.
renderWindowInteractor.Initialize()
# Sign up to receive TimerEvent
cb = vtkTimerCallback()
cb.actor = actor
renderWindowInteractor.AddObserver('TimerEvent', cb.execute)
timerId = renderWindowInteractor.CreateRepeatingTimer(100);
#start the interaction and timer
renderWindowInteractor.Start()
if __name__ == '__main__':
main()
#
# testanimate.py ends here