ParaView/Python/Lookup tables: Difference between revisions
(Created page with "In ParaView 4.1 lookup tables can be accessed by name from python scripts. In addition user created lookup tables can be saved and loaded.") |
JPouderoux (talk | contribs) mNo edit summary |
||
(3 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
= Summary = | |||
The simple API provides functions to manipulate look-up tables by name. The same LUTs found in the GUI are available by default. LUTs are associated with arrays, so first get the array from ''PointData'' or ''CellData'' of another proxy, next get the representation and set the ''ColorArrayName'', and finally pass the LUT array and LUT name to ''AssignLookupTable''. User provided LUTs may be loaded into the dictionary from disk using ''LoadLookupTable'' function. | |||
==API== | |||
The following API is provided for LUT manipulation in ''simple.py''. | |||
<source lang="python"> | |||
# ----------------------------------------------------------------------------- | |||
def AssignLookupTable(arrayObject, LUTName, rangeOveride=[]): | |||
"""Assign a lookup table to an array by lookup table name. The array | |||
may be obtained from a ParaView source in it's point or cell data. | |||
The lookup tables available in ParaView's GUI are loaded by default. | |||
To get a list of the available lookup table names see GetLookupTableNames. | |||
To load a custom lookup table see LoadLookupTable.""" | |||
# ----------------------------------------------------------------------------- | |||
def GetLookupTableNames(): | |||
"""Return a list containing the currently available lookup table names. | |||
A name maybe used to assign a lookup table to an array. See | |||
AssignLookupTable. | |||
""" | |||
# ----------------------------------------------------------------------------- | |||
def LoadLookupTable(fileName): | |||
"""Read the lookup tables in the named file and append them to the | |||
global collection of lookup tables. The newly loaded lookup tables | |||
may then be used with AssignLookupTable function. | |||
""" | |||
</source> | |||
==Example== | |||
The following example (from ParaView's regression tests) exercises the new API. | |||
<source lang="python"> | |||
from paraview.simple import * | |||
from paraview import smtesting | |||
smtesting.ProcessCommandLineArguments() | |||
lutfile='%s/testlut.xml'%(smtesting.TempDir) | |||
testlut="""<ColorMaps> | |||
<ColorMap name="testlut" space="RGB" indexedLookup="false"> | |||
<Point x="1.86486" o="0" r="0.0392157" g="0.0392157" b="0.94902"/> | |||
<Point x="70.1081" o="0.6954" r="0" g="1" b="0"/> | |||
<Point x="100" o="1" r="0.94902" g="0.94902" b="0.0392157"/> | |||
<NaN r="1" g="0" b="0"/> | |||
</ColorMap> | |||
</ColorMaps>""" | |||
f = open(lutfile,'w') | |||
f.write(testlut) | |||
f.close() | |||
w = Wavelet() | |||
wa = w.PointData.GetArray('RTData') | |||
o = Outline(w) | |||
Show(o) | |||
s = Slice(w) | |||
s.SliceType.Normal = [0.0, 0.0, 1.0] | |||
r = Show(s) | |||
r.ColorArrayName='RTData' | |||
r.Representation='Surface' | |||
v = GetRenderView() | |||
v.CameraViewUp = [0,1,0] | |||
v.CameraPosition = [-32,32,60] | |||
v.CameraClippingRange = [33, 110] | |||
v.UseGradientBackground = 1 | |||
v.Background2 = [0.0, 0.0, 0.16471] | |||
v.Background = [0.3216, 0.3412, 0.4314] | |||
v.CenterAxesVisibility = 0 | |||
# verify default laoding | |||
if len(GetLookupTableNames())<1: | |||
raise smtesting.TestError('Failed to load the default LUTs.') | |||
# exercsie the simple loader | |||
if not LoadLookupTable(lutfile): | |||
raise smtesting.TestError('Failed to load the testlut file.') | |||
names = GetLookupTableNames() | |||
if 'testlut' not in names: | |||
raise smtesting.TestError('Failed to parse the testlut lut.') | |||
# exercise simple assignment | |||
print | |||
print 'Rendering with %d LUTs'%(len(names)) | |||
print 'The available LUTs are:' | |||
print names | |||
print | |||
for name in names: | |||
r.LookupTable=AssignLookupTable(wa,name) | |||
Render() | |||
# choose one of them for the baseline | |||
r.LookupTable=AssignLookupTable(wa,'Cold and Hot') | |||
ren = Render() | |||
if not smtesting.DoRegressionTesting(ren.SMProxy): | |||
raise smtesting.TestError('Image comparison failed.') | |||
</source> | |||
Back to [[ParaView/PythonRecipes]]. | |||
{{ParaView/Template/Footer}} |
Revision as of 18:34, 16 October 2018
Summary
The simple API provides functions to manipulate look-up tables by name. The same LUTs found in the GUI are available by default. LUTs are associated with arrays, so first get the array from PointData or CellData of another proxy, next get the representation and set the ColorArrayName, and finally pass the LUT array and LUT name to AssignLookupTable. User provided LUTs may be loaded into the dictionary from disk using LoadLookupTable function.
API
The following API is provided for LUT manipulation in simple.py.
<source lang="python">
- -----------------------------------------------------------------------------
def AssignLookupTable(arrayObject, LUTName, rangeOveride=[]):
"""Assign a lookup table to an array by lookup table name. The array may be obtained from a ParaView source in it's point or cell data. The lookup tables available in ParaView's GUI are loaded by default. To get a list of the available lookup table names see GetLookupTableNames. To load a custom lookup table see LoadLookupTable."""
- -----------------------------------------------------------------------------
def GetLookupTableNames():
"""Return a list containing the currently available lookup table names. A name maybe used to assign a lookup table to an array. See AssignLookupTable. """
- -----------------------------------------------------------------------------
def LoadLookupTable(fileName):
"""Read the lookup tables in the named file and append them to the global collection of lookup tables. The newly loaded lookup tables may then be used with AssignLookupTable function. """
</source>
Example
The following example (from ParaView's regression tests) exercises the new API.
<source lang="python"> from paraview.simple import * from paraview import smtesting
smtesting.ProcessCommandLineArguments() lutfile='%s/testlut.xml'%(smtesting.TempDir) testlut="""<ColorMaps> <ColorMap name="testlut" space="RGB" indexedLookup="false">
<Point x="1.86486" o="0" r="0.0392157" g="0.0392157" b="0.94902"/> <Point x="70.1081" o="0.6954" r="0" g="1" b="0"/> <Point x="100" o="1" r="0.94902" g="0.94902" b="0.0392157"/> <NaN r="1" g="0" b="0"/>
</ColorMap> </ColorMaps>""" f = open(lutfile,'w') f.write(testlut) f.close()
w = Wavelet() wa = w.PointData.GetArray('RTData')
o = Outline(w) Show(o)
s = Slice(w) s.SliceType.Normal = [0.0, 0.0, 1.0]
r = Show(s) r.ColorArrayName='RTData' r.Representation='Surface'
v = GetRenderView() v.CameraViewUp = [0,1,0] v.CameraPosition = [-32,32,60] v.CameraClippingRange = [33, 110] v.UseGradientBackground = 1 v.Background2 = [0.0, 0.0, 0.16471] v.Background = [0.3216, 0.3412, 0.4314] v.CenterAxesVisibility = 0
- verify default laoding
if len(GetLookupTableNames())<1:
raise smtesting.TestError('Failed to load the default LUTs.')
- exercsie the simple loader
if not LoadLookupTable(lutfile):
raise smtesting.TestError('Failed to load the testlut file.')
names = GetLookupTableNames() if 'testlut' not in names:
raise smtesting.TestError('Failed to parse the testlut lut.')
- exercise simple assignment
print print 'Rendering with %d LUTs'%(len(names)) print 'The available LUTs are:' print names print for name in names:
r.LookupTable=AssignLookupTable(wa,name) Render()
- choose one of them for the baseline
r.LookupTable=AssignLookupTable(wa,'Cold and Hot') ren = Render()
if not smtesting.DoRegressionTesting(ren.SMProxy):
raise smtesting.TestError('Image comparison failed.')
</source>
Back to ParaView/PythonRecipes.