-
Notifications
You must be signed in to change notification settings - Fork 9
/
vtkColorActor.py
54 lines (40 loc) · 1.15 KB
/
vtkColorActor.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
'''
Author: Qin Shuo
Date: 2016/03/22
Description:
Create a sphere (vtkpolydata type)
Assign color and display
'''
import vtk
import sys
import string
def CreateSphere():
# sphere source
# Document: http://www.vtk.org/doc/nightly/html/classvtkSphereSource.html
sphereSrc = vtk.vtkSphereSource()
sphereSrc.SetRadius(10.0)
sphereSrc.SetCenter(0.0,0.0,0.0)
sphereSrc.SetThetaResolution(20)
sphereSrc.Update()
return sphereSrc.GetOutput()
def display_color_actor(poly):
# visualization
print "visualizing..."
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(poly)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
#============ key line =============#
actor.GetProperty().SetColor(0.5,0.5,0.0)
#============ key line =============#
renderer = vtk.vtkRenderer()
renderer.AddActor(actor)
window = vtk.vtkRenderWindow()
window.AddRenderer(renderer)
interactor = vtk.vtkRenderWindowInteractor()
window.SetInteractor(interactor)
window.Render()
interactor.Start()
if __name__ == '__main__':
sphere = CreateSphere()
display_color_actor(sphere)