ParaView/Python/Lookup tables

From KitwarePublic
< ParaView
Revision as of 18:34, 16 October 2018 by JPouderoux (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search


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.


The following API is provided for LUT manipulation in

<source lang="python">

  1. -----------------------------------------------------------------------------

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."""
  1. -----------------------------------------------------------------------------

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

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.

<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

  1. verify default laoding

if len(GetLookupTableNames())<1:

 raise smtesting.TestError('Failed to load the default LUTs.')
  1. 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.')
  1. exercise simple assignment

print print 'Rendering with %d LUTs'%(len(names)) print 'The available LUTs are:' print names print for name in names:

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


Back to ParaView/PythonRecipes.

ParaView: [Welcome | Site Map]