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.')
|