forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtImageTest.py
executable file
·144 lines (116 loc) · 3.65 KB
/
rtImageTest.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
142
143
144
#!/usr/bin/env python
# This is the script that runs a testing python script.
# The script to be run must be the first argument.
import sys
if len(sys.argv) < 2:
print("Usage %s <test script> [<addition arguments>]" % sys.argv[0])
sys.exit(1)
for i in range(2, len(sys.argv)):
if sys.argv[i] == '-A' and i < len(sys.argv)-1:
sys.path = sys.path + [sys.argv[i+1]]
import vtk
#these are the modules that define methods/variables
#used by many scripts. We just include them always
from backdrop import *
from mccases import *
import catch
import expr
import file
import info
import math
from vtk.util.colors import *
# Mock class that overrides the Start() method from vtkRenderWindowInteractor
# to do nothing. This allows VTK's python tests to be standard VTK scripts that
# call Start() on the interactor.
class vtkTestingInteractor(vtk.vtkRenderWindowInteractor):
def Start(self):
pass
#implementation for lindex.
def lindex(list, index):
if type(list) == type("string"):
return list.split()[index]
return list[index]
#gets with no varName (returns the read string)
def gets(file):
line = file.readline()
if line[-1] == "\n":
line = line[:-1]
return line
def gets(file, varName, global_vars):
line = gets(file)
ret = len(line)
global_vars[varName] = line
return ret
def tcl_platform(what):
if what != "platform":
raise ValueError("Only platform supported as yet!")
plat = sys.platform
if plat[:5] == "linux":
return "unix"
return plat
def get_variable_name(*args):
var_name = ""
for arg in args:
if arg == "":
continue
# it is essential to qualify the scope of type since
# some test define type variable which messes up the
# builtin call.
if __builtins__.type(arg) == __builtins__.type("string"):
var_name += arg
else:
var_name += repr(arg)
return var_name
#init Tk
try:
import Tkinter
pythonTk = Tkinter.Tk()
pythonTk.withdraw()
except:
pythonTk = None
pass #no hassles if Tk is not present.
# setup some common things for testing
rtTempObject = vtk.vtkObject()
rtExMath = vtk.vtkMath()
rtExMath.RandomSeed(6)
# create the testing class to do the work
rtTester = vtk.vtkTesting()
for arg in sys.argv[2:]:
rtTester.AddArgument(arg)
VTK_DATA_ROOT = rtTester.GetDataRoot()
if rtTester.IsInteractiveModeSpecified() == 0:
vtk.vtkRenderWindowInteractor = vtkTestingInteractor
# load in the script
test_script = sys.argv[1]
# set the default threshold, the Tcl script may change this
threshold = -1
# we pass the locals over so that the test script has access to
# all the locals we have defined here.
exec(compile(open(test_script).read(), test_script, 'exec'), globals(), locals())
local_variables_dict = locals()
if "iren" in local_variables_dict:
renWin.Render()
if pythonTk:
# run the event loop quickly to map any tkwidget windows
pythonTk.update()
rtResult = 0
if rtTester.IsValidImageSpecified() != 0:
# look for a renderWindow ImageWindow or ImageViewer
# first check for some common names
if "renWin" in local_variables_dict:
rtTester.SetRenderWindow(renWin)
if threshold == -1:
threshold = 0.15
else:
if threshold == -1:
threshold = 0.15
if "viewer" in local_variables_dict:
rtTester.SetRenderWindow(viewer.GetRenderWindow())
viewer.Render()
elif "imgWin" in local_variables_dict:
rtTester.SetRenderWindow(imgWin)
imgWin.Render()
rtResult = rtTester.RegressionTest(threshold)
if rtResult == 0:
sys.exit(1)
sys.exit(0)