File: TestImageJSONWriter.py

package info (click to toggle)
paraview 5.4.1%2Bdfsg4-3.1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 218,616 kB
  • sloc: cpp: 2,331,508; ansic: 322,365; python: 111,051; xml: 79,203; tcl: 47,013; yacc: 4,877; java: 4,438; perl: 3,238; sh: 2,920; lex: 1,908; f90: 748; makefile: 273; pascal: 228; objc: 83; fortran: 31
file content (65 lines) | stat: -rw-r--r-- 1,666 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/env python
import os, json, sys
import vtk

args = sys.argv[1:]
temp_dir = args[args.index("-T") + 1]

# Always use / to prevent windows/python issue with backslash
tmp_file = temp_dir + '/wavelet_slice_3.json'

expected_first_values = [75.9335, 102.695, 91.2387, 115.507, 105.995, 125.724, 118.773, 132.24, 128.255, 134.254, 133.446, 131.431, 133.843, 123.998, 129.505]

# Image pipeline
image1 = vtk.vtkRTAnalyticSource()
image1.Update()
output = image1.GetOutput()
dim_ref = [value for value in output.GetDimensions()]
origin_ref = [value for value in output.GetOrigin()]
spacing_ref = [value for value in output.GetSpacing()]

print(dim_ref)
print(origin_ref)
print(spacing_ref)

writer = vtk.vtkJSONImageWriter()
writer.SetInputData(image1.GetOutput())
writer.SetFileName(tmp_file)
writer.SetArrayName("RTData")
writer.SetSlice(3)
writer.Write()

# Try to load JSON file and compare with dumped data
print("Writing file:", tmp_file)
json_file = open(tmp_file, "r")
json_obj = json.load(json_file)
json_file.close()

slice = json_obj['RTData']
if json_obj["dimensions"] != dim_ref:
    print("Dimension ERROR")
    sys.exit(1)
else:
    print("Dimension OK")
if json_obj["origin"] != origin_ref:
    print("Origin ERROR")
    sys.exit(1)
else:
    print("Origin OK")
if json_obj["spacing"] != spacing_ref:
    print("Spacing ERROR")
    sys.exit(1)
else:
    print("Spacing OK")
if len(slice) == 441:
    print("Slice size OK")
else:
    print("Slice size ERROR - Size of ", str(len(slice)))
    sys.exit(1)

for i in range(len(expected_first_values)):
    if expected_first_values[i] != slice[i]:
        sys.exit(1)

print("All good...")
sys.exit()