ParaView/Python/Lookup tables

From KitwarePublic
< ParaView
Revision as of 16:50, 13 November 2013 by Burlen (talk | contribs)
Jump to navigationJump to search

The simple API provides functions to manipulate look-up tables by name. 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.

The same LUTs found in the GUI are available by default. User provided LUTs may be loaded into the dictionary from disk using LoadLookupTable function.


# -----------------------------------------------------------------------------
def AssignLookupTable(arrayObject, LUTName, rangeOveride=[]):
    """Assign a lookup table to an array by lookup table name. The array
    may ber 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

# -----------------------------------------------------------------------------
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.


The following example (from ParaView's regression tests) exercises the new API.

from paraview.simple import *
from paraview import smtesting                                                                                                                                                     

<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"/>
f = open(lutfile,'w')

w = Wavelet()
wa = w.PointData.GetArray('RTData')

o = Outline(w)

s = Slice(w)
s.SliceType.Normal = [0.0, 0.0, 1.0]

r = Show(s)

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 'Rendering with %d LUTs'%(len(names))
print 'The available LUTs are:'
print names
for name in names:

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