[Paraview] Reading json colormap files in Python and exporting color data

Cory Quammen cory.quammen at kitware.com
Wed Apr 27 10:23:30 EDT 2016


Hi Andy,

On Tue, Apr 26, 2016 at 10:15 AM, Andy Smith <agsmith424 at gmail.com> wrote:
> I have two questions:
>
> 1. I am trying to load colormaps in a Python script so that I have access to
> the lookup table later in the script.  I have successfully used the
> LoadLookupTable function with xml colormap files but this does not seem to
> work on json files.  I get a parsing error:
>
> ERROR: parsing lut file /path/to/my/colormap.json
>
> The json colormap file loads correctly inside the GUI.  Is there another
> function that I should be calling instead of LoadLookupTable or is there an
> issue with this function?  Should it call a different parser based on the
> file extension?

LoadLookupTable works only for XML files. I don't believe there is a
similar compact function for loading JSON files, but one should be
available.

> 2. Is there a way to export the discretized color data?  For example, my
> colormap may have seven control points in Lab space but I'd like to export
> 256 control points and the associated R,G,B values for use in other tools.
> Alternatively, are there any ParaView Python functions that I can use to
> extract R,G,B values from a colormap based on input array values?

This Python is surprisingly slow, but works:

lut = GetColorTransferFunction(arrayName)
dct = lut.SMProxy.GetClientSideObject()
range = dct.GetRange()
for i in xrange(256):
  x = (i*(range[1] - range[0]) / 255.0) + range[0]
  r = dct.GetRedValue(x)
  g = dct.GetGreenValue(x)
  b = dct.GetBlueValue(x)
  print x, r, g, b

HTH,
Cory

>
> Thanks,
> Andy
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ParaView Wiki at:
> http://paraview.org/Wiki/ParaView
>
> Search the list archives at: http://markmail.org/search/?q=ParaView
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/paraview
>



-- 
Cory Quammen
R&D Engineer
Kitware, Inc.


More information about the ParaView mailing list