-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathvtkVolumeExample.py
More file actions
executable file
·138 lines (111 loc) · 3.62 KB
/
vtkVolumeExample.py
File metadata and controls
executable file
·138 lines (111 loc) · 3.62 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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python
from __future__ import print_function
from vtk import *
tse = vtkTimeSourceExample()
ex = tse.GetExecutive()
tse.UpdateInformation()
#inspect available time range and time steps
print(ex.GetOutputInformation())
#make it grow because bounds are easy to inspect
# tse.SetGrowing(1)
ex.SetUpdateTimeStep(0,0.0)
tse.Update()
print(tse.GetOutput().GetBounds())
#pick some other time inside the time range
ex.SetUpdateTimeStep(0,0.5)
tse.Update()
print(tse.GetOutput().GetBounds())
grid = tse.GetOutput()
print(grid)
tri = vtkDataSetTriangleFilter()
tri.SetInputData(grid)
tri.SetTetrahedraOnly(1)
tri.Update()
output = tri.GetOutput()
iss = output.GetPointData().SetActiveScalars("Point Label")
# iss = gridMapper.GetInput().GetCellData().SetActiveScalars(options.scalarName)
assert(iss>-1)
drange = [0, 1]
# Create transfer mapping scalar value to opacity.
opacityFunction = vtkPiecewiseFunction()
opacityFunction.AddPoint(drange[0], 0.0)
opacityFunction.AddPoint(drange[1], 1.0)
# Create transfer mapping scalar value to color.
colorFunction = vtkColorTransferFunction()
colorFunction.SetColorSpaceToHSV()
colorFunction.HSVWrapOff()
colorFunction.AddRGBPoint(drange[0], 0.0, 0.0, 1.0)
colorFunction.AddRGBPoint(drange[1], 1.0, 0.0, 0.0)
volumeProperty = vtkVolumeProperty()
volumeProperty.SetScalarOpacity(opacityFunction)
volumeProperty.SetColor(colorFunction)
volumeProperty.ShadeOff()
volumeProperty.SetInterpolationTypeToLinear()
# volumeProperty.SetScalarOpacityUnitDistance(options.unit)
volumeMapper = vtkUnstructuredGridVolumeRayCastMapper()
# volumeMapper = vtkUnstructuredGridVolumeZSweepMapper()
# volumeMapper = vtkProjectedTetrahedraMapper()
# volumeMapper.SetBlendModeToMaximumIntensity()
volumeMapper.SetInputData(output)
volume = vtkVolume()
volume.SetMapper(volumeMapper)
volume.SetProperty(volumeProperty)
# create a rendering window and renderer
renderer = vtkRenderer()
renderer.SetBackground(0,0,0)
window = vtkRenderWindow()
window.SetSize(512,512)
window.AddRenderer(renderer)
interactor = vtkRenderWindowInteractor()
interactor.SetRenderWindow(window)
style = vtkInteractorStyleTrackballCamera();
interactor.SetInteractorStyle(style);
renderer.AddVolume(volume)
scalarBar = vtkScalarBarActor()
scalarBar.SetLookupTable(colorFunction);
scalarBar.SetOrientationToVertical();
scalarBar.SetPosition( 0.85, 0.7 );
scalarBar.SetPosition2( 0.1, 0.3 );
propT = vtkTextProperty()
propL = vtkTextProperty()
propT.SetFontFamilyToArial()
propT.ItalicOff()
propT.BoldOn()
propL.BoldOff()
scalarBar.SetTitleTextProperty(propT);
scalarBar.SetLabelTextProperty(propL);
scalarBar.SetLabelFormat("%5.2f")
renderer.AddActor(scalarBar)
# setup the text and add it to the window
textActor = vtkTextActor()
textActor.GetTextProperty().SetFontSize(12)
textActor.SetPosition2(10, 40)
renderer.AddActor2D(textActor)
textActor.SetInput("time = ")
textActor.GetTextProperty().SetColor(1.0,1.0,1.0)
renderer.ResetCameraClippingRange()
renderer.ResetCamera()
counter = 1
time = 0
while time<=1:
print("time = ", time)
textActor.SetInput("time = %g" % time)
window.Render()
# TODO FIXME if this block is not here than the volume renders wrongly
#renderer.RemoveVolume(volume)
# del volume
volume = vtkVolume()
volume.SetMapper(volumeMapper)
volume.SetProperty(volumeProperty)
renderer.AddVolume(volume)
counter = counter + 1
time = time + 1./10
ex.SetUpdateTimeStep(0,time)
tse.Modified()
if output.GetPointData().GetScalars():
print(output.GetPointData().GetScalars().GetRange())
# if grid.GetPointData().GetScalars():
# print(grid.GetPointData().GetScalars().GetRange())
# print(grid.GetPointData().GetScalars())
# while True:
# window.Render()