-
Notifications
You must be signed in to change notification settings - Fork 1
/
vtk-rect-to-wall.py
141 lines (122 loc) · 4.24 KB
/
vtk-rect-to-wall.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
130
131
132
133
134
135
136
137
138
139
140
141
from vtk import *
from PIL import Image
import numpy as np
import math
import os
dx = 0.01
# open vtk file
file_name = "testcase.vtk"
reader = vtkRectilinearGridReader()
reader.SetFileName(file_name)
Data = reader.GetOutput()
reader.Update()
bounds = Data.GetBounds()
xmin, xmax, ymin, ymax, zmin, zmax = bounds
print bounds
npx = int(math.floor((xmax - zmin)/dx))
npy = int(math.floor((ymax - ymin)/dx))
npz = int(math.floor((zmax - zmin)/dx))
# print "Points in x: " + str(npx) + " in y: " + str(npy) + " in z: " + str(npz)
locator = vtkPointLocator()
locator.SetDataSet(Data)
locator.BuildLocator()
pointid = locator.FindClosestPoint([0.,0.,6.])
point = Data.GetPoint(pointid)
pointdata = Data.GetPointData()
pointdata.Update()
densityarray = pointdata.GetArray(0)
mindensity, maxdensity = densityarray.GetValueRange()
prefactor = 254./(maxdensity - mindensity)
print ("Minimum : " + str(mindensity))
print ("Maximum : " + str(maxdensity))
print ("Conversion Factor : " + str(prefactor))
imagedata = []
for k in range(npz):
for i in range(npx):
pointid = locator.FindClosestPoint([xmin+dx*i,
ymin+3,
zmin+dx*k])
if pointid == -1:
value = 0.0
else:
value = prefactor*(densityarray.GetValue(pointid) - mindensity)
imagedata.append(value)
smalldata = np.array(imagedata,dtype="uint8")
theimage = Image.frombytes('L',(npx,npz),smalldata)
print("Saving Wall")
theimage.save('Wallxz_ymin.png', 'PNG')
imagedata = []
for k in range(npz):
for i in range(npx):
pointid = locator.FindClosestPoint([xmin+dx*i,
ymax-3,
zmin+dx*k])
if pointid == -1:
value = 0.0
else:
value = prefactor*(densityarray.GetValue(pointid) - mindensity)
imagedata.append(value)
smalldata = np.array(imagedata,dtype="uint8")
theimage = Image.frombytes('L',(npx,npz),smalldata)
print("Saving Wall")
theimage.save('Wallxz_ymax.png', 'PNG')
imagedata = []
for k in range(npz):
for i in range(npy):
pointid = locator.FindClosestPoint([xmin+3,
ymin+dx*i,
zmin+dx*k])
if pointid == -1:
value = 0.0
else:
value = prefactor*(densityarray.GetValue(pointid) - mindensity)
imagedata.append(value)
smalldata = np.array(imagedata,dtype="uint8")
theimage = Image.frombytes('L',(npy,npz),smalldata)
print("Saving Wall")
theimage.save('Wallyz_xmin.png', 'PNG')
imagedata = []
for k in range(npz):
for i in range(npy):
pointid = locator.FindClosestPoint([xmax-3,
ymin+dx*i,
zmin+dx*k])
if pointid == -1:
value = 0.0
else:
value = prefactor*(densityarray.GetValue(pointid) - mindensity)
imagedata.append(value)
smalldata = np.array(imagedata,dtype="uint8")
theimage = Image.frombytes('L',(npy,npz),smalldata)
print("Saving Wall")
theimage.save('Wallyz_xmax.png', 'PNG')
imagedata = []
for k in range(npy):
for i in range(npx):
pointid = locator.FindClosestPoint([xmax+dx*i,
ymin+dx*k,
zmin+3])
if pointid == -1:
value = 0.0
else:
value = prefactor*(densityarray.GetValue(pointid) - mindensity)
imagedata.append(value)
smalldata = np.array(imagedata,dtype="uint8")
theimage = Image.frombytes('L',(npx,npy),smalldata)
print("Saving Wall")
theimage.save('Wallxy_zmin.png', 'PNG')
imagedata = []
for k in range(npy):
for i in range(npx):
pointid = locator.FindClosestPoint([xmax+dx*i,
ymin+dx*k,
zmax-3])
if pointid == -1:
value = 0.0
else:
value = prefactor*(densityarray.GetValue(pointid) - mindensity)
imagedata.append(value)
smalldata = np.array(imagedata,dtype="uint8")
theimage = Image.frombytes('L',(npx,npy),smalldata)
print("Saving Wall")
theimage.save('Wallxy_zmax.png', 'PNG')