Repository navigation
Expand file tree
/
Copy pathanimation.py
More file actions
executable file
·60 lines (49 loc) · 1.8 KB
/
Copy pathanimation.py
File metadata and controls
executable file
·60 lines (49 loc) · 1.8 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import vtk
refresh_rate = 60 # In Hertz
def callback_func(caller, timer_event):
# We rotate the arrow by 1 degree in the Z direction.
# This creates a nice counterclockwise motion
# for the default camera postion/direction.
# It is possible to speed/slow the motion by changing
# this value, or the refresh rate.
actor.RotateZ(1)
# This needs to be called to render the updated actor
# orientation.
window.Render()
# These next few lines are pretty standard.
# Create an arrow, polydata mapper, and actor.
arrow = vtk.vtkArrowSource()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(arrow.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
# Create the window, renderer, and interactor.
renderer = vtk.vtkRenderer()
renderer.AddActor(actor)
window = vtk.vtkRenderWindow()
window.AddRenderer(renderer)
interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(window)
# The interactor needs to be initialised before we
# can create a timer or add observers.
interactor.Initialize()
# The repeating timer takes the interval in 1/1000th
# of a second. Each time it fires off a TimerEvent.
interactor.CreateRepeatingTimer(int(1/refresh_rate))
# In python you can add an observer directly like this.
# In other languages there is a layer of indireciton where
# a vtkCallbackCommand is created, and the function is set
# in the vtkCallbackCommand.
# We set the callback function to be called for each
# activation of the timer.
interactor.AddObserver("TimerEvent", callback_func)
# The default position of the camera
# is a little too close to see the entire
# motion of the arrow. Zoom out a litle.
cam = renderer.GetActiveCamera()
cam.SetPosition(0,0,5)
window.SetSize(500, 500)
window.Render()
interactor.Start()