File: PythonSMTraceTest1.py

package info (click to toggle)
paraview 5.1.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 221,108 kB
  • ctags: 236,092
  • sloc: cpp: 2,416,026; ansic: 190,891; python: 99,856; xml: 81,001; tcl: 46,915; yacc: 5,039; java: 4,413; perl: 3,108; sh: 1,974; lex: 1,926; f90: 748; asm: 471; pascal: 228; makefile: 198; objc: 83; fortran: 31
file content (105 lines) | stat: -rw-r--r-- 3,069 bytes parent folder | download | duplicates (2)
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
# This test runs through the steps described in the python trace tutorial
# to appear in a Kitware Source newsletter.
#
#  Trace is enabled and the following actions are captured and then replayed:
#
#  An octree fractal source is created, dimension set to 3, contour filter is
#  applied, then the active source is changed back to the fractal source and
#  an extract cells by region filter is applied.  The clip plane of the extract
#  filter is adjusted, the camera is adjusted, a colormap is applied, and a 
#  scalar bar widget is added to the scene and its position is adjusted.
#

from paraview.simple import *
from paraview import smtrace
from paraview import smtesting
import sys

settings = servermanager.vtkPVGeneralSettings()
settings.SetScalarBarMode(settings.MANUAL_SCALAR_BARS)

# Process command line args and get temp dir
smtesting.ProcessCommandLineArguments()
tempDir = smtesting.TempDir

# Create a render view before starting trace
ren = CreateRenderView()

# Start trace
config = smtrace.start_trace()

########################################################
# Begin build pipeline
def create_pipeline():
  w = Wavelet()
  Show()
  Render()

  # note property changes won't be recorded directly so don't do any outside the
  # constructor and expect that to work.
  contour = Contour(ComputeScalars=1,
      Isosurfaces=[100, 150, 200])
  Show()
  #Hide(w)
  Render()
  ColorBy(value=("POINTS", "RTData"))
  GetDisplayProperties().SetScalarBarVisibility(ren, True)
  Render()

  clip = Clip()
  Show()
  Hide(contour)
  Render()

create_pipeline()

# End build pipeline
########################################################

# Stop trace and grab the trace output string
trace_string = smtrace.stop_trace()
print trace_string
# Uncomment these lines to print the trace string or save it to a file
print trace_string
#smtrace.save_trace(tempDir + "/PythonSMTraceTest1.py")

# Clear all the sources
for source in GetSources().values():
    Delete(source)


# Confirm that all the representations have been removed from the view except 1
# for the scalar bar.
if len(ren.Representations) != 1:
    print "View should not have any representations except the scalar bar!"
    sys.exit(1)

# destroy the scalar bar too
Delete(ren.Representations[0])

if len(ren.Representations) != 0:
    print "View should not have any representations at this point!"
    sys.exit(1)

# Confirm that the clip filter has been removed
if GetSources():
    print "All sources should have be removed."
    sys.exit(1)

# change camera to confirm that trace restores it.
ren.CameraPosition = [-1, -1, -1]
Render()

# Compile the trace code and run it
code = compile(trace_string, "<string>", "exec")
exec(code)

# Confirm that the clip filter has been recreated
clip = [x for x in GetSources().values() if x.GetXMLLabel() == "Clip"]
if not clip:
    print "After replaying trace, could not find Clip filter."
    sys.exit(1)

# Do a screenshot regression test
if not smtesting.DoRegressionTesting(ren.SMProxy):
    raise smtesting.TestError('Image comparison failed.')