-
Notifications
You must be signed in to change notification settings - Fork 0
/
tviewer.py
129 lines (110 loc) · 3.62 KB
/
tviewer.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
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
import sys, getopt
import vtk
from vtk.util import numpy_support
import h5py
import numpy as np
import timeit, time
def main(argv):
#Just get something working for testing...
try:
opts, args = getopt.getopt(argv,"hi:", ["ifile="])
except getopt.GetoptError as err:
print 'tviewer.py -i <inputfile.vtk>'
print (str(err))
for opt, arg in opts:
if opt == '-h':
print 'tviewer.py -i <inputfile.vtk>'
sys.exit()
elif opt in ("-i", "--ifile"):
inputfile = arg
print("Going to load and view ", inputfile)
#Read data
reader = vtk.vtkXMLImageDataReader()
reader.SetFileName(inputfile)
reader.Update()
#lut = vtk.vtkLookupTable()
#lut.SetNumberOfColors(65535)
#lut.SetHueRange(0.0, 2.667)
#lut.SetVectorMode(vtk.vtkScalarsToColors.MAGNITUDE)
#lut.Build()
image = reader.GetOutput()
#image.SetSpacing(1,1,1)
#image.GetPointData().SetScalars(image.GetPointData().GetVectors())
#Compute Q Criterion for texture mapping
vorticity = vtk.vtkGradientFilter()
vorticity.SetInputData(image)
vorticity.SetInputScalars(image.FIELD_ASSOCIATION_POINTS,"Velocity")
vorticity.ComputeQCriterionOn()
#vorticity.SetComputeGradient(0)
vorticity.Update()
#Generate contour for comparison
c = vtk.vtkContourFilter()
#c.SetValue(0,1128)
c.SetValue(0,450)
image.GetPointData().SetScalars(vorticity.GetOutput().GetPointData().GetVectors("Q-criterion"))
c.SetInputData(image)
c.Update()
contour = c.GetOutput()
#contour.GetCellData().SetScalars(image.GetPointData().GetVectors("Velocity"))
normals = vtk.vtkPolyDataNormals()
normals.SetInputData(contour)
normals.SetFeatureAngle(45) #?
normals.Update()
print normals.GetOutput()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(normals.GetOutput())
mapper.ScalarVisibilityOn()
mapper.SetScalarRange(-1,1)
mapper.SetScalarModeToUsePointFieldData()
mapper.ColorByArrayComponent("Velocity", 0)
#print image
#print contour
#mapper.SelectColorArray("Q-criterion")
#mapper.SetLookupTable(lut)
print mapper
actor = vtk.vtkActor()
actor.SetMapper(mapper)
ren = vtk.vtkRenderer()
ren.AddActor(actor)
ren.SetBackground(1,1,1)
ren.ResetCamera()
renWin = vtk.vtkRenderWindow()
renWin.SetSize(600,600)
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
def MouseMove(self, data):
print("Load Cache %s" % data )
print ("Iren data")
#print iren
#addcube
#print ren
print ren.GetViewPoint()
print ren.GetDisplayPoint()
print ren.WorldToView()
print ren.ComputeVisiblePropBounds()
ysize = renWin.GetSize()[1]
c.SetValue(0,ysize)
c.Update()
normals = vtk.vtkPolyDataNormals()
normals.SetInputData(c.GetOutput())
normals.SetFeatureAngle(25) #?
normals.Update()
normals.SetFeatureAngle(45) #?
normals.Update()
mapper2 = vtk.vtkPolyDataMapper()
mapper2.SetInputData(normals.GetOutput())
mapper2.ScalarVisibilityOn()
mapper2.SetScalarRange(-.5,1)
mapper2.SetScalarModeToUsePointFieldData()
mapper2.ColorByArrayComponent("Velocity", 0)
actor2 = vtk.vtkActor()
actor2.SetMapper(mapper2)
ren.AddActor(actor2)
iren.AddObserver("MiddleButtonPressEvent", MouseMove)
iren.SetRenderWindow(renWin)
iren.Initialize()
iren.Start()
#time.sleep(2)
print("adding another cube")
if __name__ == "__main__":
main(sys.argv[1:])