forked from CFD-GO/TCLB_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VTICompressor.py
64 lines (41 loc) · 1.31 KB
/
VTICompressor.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
# -*- coding: utf-8 -*-
import vtk
import sys
import os
from multiprocessing import Pool
NP = 1
save = sys.argv[1].split(",")
if save == [ sys.argv[1] ]:
save = ['Rho', 'U', 'BOUNDARY']
startWith = 1
else:
startWith = 2
print save
def revti(name):
in_vtifname = name
out_vtifname = "/tmp/"+os.path.basename( os.path.splitext(name)[0] )+'.vti'
reader = vtk.vtkXMLPImageDataReader()
reader.SetFileName(in_vtifname)
reader.Update()
data = reader.GetOutput()
cd = data.GetCellData()
k = 0
bc = cd.GetNumberOfArrays()
while cd.GetNumberOfArrays() > len(save) or k > 10:
k = k + 1
for i in range(cd.GetNumberOfArrays()):
if not ( cd.GetArrayName(i) in save ):
# print "Removing:", cd.GetArrayName(i)
cd.RemoveArray(cd.GetArrayName(i))
break
# else:
# print "Keeping:", cd.GetArrayName(i)
print out_vtifname +" : ", bc, '/', cd.GetNumberOfArrays()
writer = vtk.vtkXMLImageDataWriter()
writer.SetFileName(out_vtifname)
writer.SetInputData(data)
writer.Write()
#pool = Pool(NP)
#pool.map( revti, sys.argv[startWith:])
for f in sys.argv[startWith:]:
revti(f)