[Paraview] Color by array component from Python script not working

Cory Quammen cory.quammen at kitware.com
Wed Aug 26 11:13:26 EDT 2015


Hi Matei,

Do your vectors really have up to 672 components? That's fine, just
surprisingly high.

Changing among vector components seems to be working fine in ParaView 4.3.1
On Windows. Here is the test script I ran.

#### import the simple module from the paraview
from paraview.simple import *
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()

# create a new 'Sphere'
sphere1 = Sphere()

# get active view
renderView1 = GetActiveViewOrCreate('RenderView')
# uncomment following to set a specific view size
# renderView1.ViewSize = [659, 468]

# show data in view
sphere1Display = Show(sphere1, renderView1)
# trace defaults for the display properties.
sphere1Display.ColorArrayName = [None, '']

# reset view to fit data
renderView1.ResetCamera()

# set scalar coloring
ColorBy(sphere1Display, ('POINTS', 'Normals'))

# rescale color and/or opacity maps used to include current data range
sphere1Display.RescaleTransferFunctionToDataRange(True)

# show color bar/color legend
sphere1Display.SetScalarBarVisibility(renderView1, True)

# get color transfer function/color map for 'Normals'
normalsLUT = GetColorTransferFunction('Normals')

# get opacity transfer function/opacity map for 'Normals'
normalsPWF = GetOpacityTransferFunction('Normals')

#change array component used for coloring
normalsLUT.RGBPoints = [-0.9749279022216797, 0.231373, 0.298039, 0.752941,
0.0, 0.865003, 0.865003, 0.865003, 0.9749279022216797, 0.705882, 0.0156863,
0.14902]
normalsLUT.VectorMode = 'Component'

# Properties modified on normalsPWF
normalsPWF.Points = [-0.9749279022216797, 0.0, 0.5, 0.0,
0.9749279022216797, 1.0, 0.5, 0.0]

normalsLUT.VectorComponent = 0
RenderAllViews()
SaveScreenshot('component0.png')

#change array component used for coloring
normalsLUT.VectorComponent = 1
RenderAllViews()
SaveScreenshot('component1.png')

#change array component used for coloring
normalsLUT.RGBPoints = [-1.0, 0.231373, 0.298039, 0.752941, 0.0, 0.865003,
0.865003, 0.865003, 1.0, 0.705882, 0.0156863, 0.14902]
normalsLUT.VectorComponent = 2
RenderAllViews()
SaveScreenshot('component2.png')

# Properties modified on normalsPWF
normalsPWF.Points = [-1.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]

#### saving camera placements for all active views

# current camera placement for renderView1
renderView1.CameraPosition = [0.0, 0.0, 3.2903743041222895]
renderView1.CameraParallelScale = 0.8516115354228021

#### uncomment the following to render all views
RenderAllViews()
# alternatively, if you want to write images, you can use
SaveScreenshot(...).

Can you confirm this works on your ParaView installation? There might be
some errors about file writing if the current working directory on your
system is write-protected - you can ignore those.

Cheers,
Cory


On Thu, Aug 20, 2015 at 6:54 PM, Matei Stroila <matei.stroila at gmail.com>
wrote:

> Hi,
>
> I am using ParaView 4.3.1 on Mac OSX.
> I used to be able to loop through the components of an attribute array and
> change the color of the representation. I am not sure why this is no longer
> working (don't recall when it was working, maybe 4.2?). It does work from
> GUI. This is the GUI trace for changing the color attribute three times:
>
> #### import the simple module from the paraview
>
> from paraview.simple import *
>
> #### disable automatic camera reset on 'Show'
>
> paraview.simple._DisableFirstRenderCameraReset()
>
>
> # get color transfer function/color map for 'SpeedArray'
>
> speedArrayLUT = GetColorTransferFunction('SpeedArray')
>
> speedArrayLUT.InterpretValuesAsCategories = 0
>
> speedArrayLUT.EnableOpacityMapping = 0
>
> speedArrayLUT.RGBPoints = [0.0, 1.0, 0.0, 0.0, 150.0, 0.0, 0.0, 1.0]
>
> speedArrayLUT.UseLogScale = 0
>
> speedArrayLUT.LockScalarRange = 1
>
> speedArrayLUT.ColorSpace = 'HSV'
>
> speedArrayLUT.UseBelowRangeColor = 0
>
> speedArrayLUT.BelowRangeColor = [0.0, 0.0, 0.0]
>
> speedArrayLUT.UseAboveRangeColor = 0
>
> speedArrayLUT.AboveRangeColor = [1.0, 1.0, 1.0]
>
> speedArrayLUT.NanColor = [0.498039, 0.498039, 0.498039]
>
> speedArrayLUT.Discretize = 1
>
> speedArrayLUT.NumberOfTableValues = 256
>
> speedArrayLUT.ScalarRangeInitialized = 1.0
>
> speedArrayLUT.HSVWrap = 0
>
> speedArrayLUT.VectorComponent = 96
>
> speedArrayLUT.VectorMode = 'Component'
>
> speedArrayLUT.AllowDuplicateScalars = 1
>
> speedArrayLUT.Annotations = []
>
> speedArrayLUT.IndexedColors = []
>
>
> # get opacity transfer function/opacity map for 'SpeedArray'
>
> speedArrayPWF = GetOpacityTransferFunction('SpeedArray')
>
> speedArrayPWF.Points = [0.0, 0.0, 0.5, 0.0, 150.0, 1.0, 0.5, 0.0]
>
> speedArrayPWF.AllowDuplicateScalars = 1
>
> speedArrayPWF.ScalarRangeInitialized = 1
>
>
> #change array component used for coloring
>
> speedArrayLUT.RGBPoints = [2.0, 1.0, 0.0, 0.0, 134.079086144, 0.0, 0.0, 1.0]
>
> speedArrayLUT.VectorComponent = 111
>
>
> # Properties modified on speedArrayPWF
>
> speedArrayPWF.Points = [2.0, 0.0, 0.5, 0.0, 134.079086144, 1.0, 0.5, 0.0]
>
>
> #change array component used for coloring
>
> speedArrayLUT.RGBPoints = [2.0, 1.0, 0.0, 0.0, 131.302099153, 0.0, 0.0, 1.0]
>
> speedArrayLUT.VectorComponent = 127
>
>
> # Properties modified on speedArrayPWF
>
> speedArrayPWF.Points = [2.0, 0.0, 0.5, 0.0, 131.302099153, 1.0, 0.5, 0.0]
>
>
> #change array component used for coloring
>
> speedArrayLUT.RGBPoints = [2.0, 1.0, 0.0, 0.0, 143.468496117, 0.0, 0.0, 1.0]
>
> speedArrayLUT.VectorComponent = 175
>
>
> # Properties modified on speedArrayPWF
>
> speedArrayPWF.Points = [2.0, 0.0, 0.5, 0.0, 143.468496117, 1.0, 0.5, 0.0]
>
>
> #### uncomment the following to render all views
>
> # RenderAllViews()
>
> # alternatively, if you want to write images, you can use SaveScreenshot(...).
>
>
> I try to do the same from a script, this time keeping the color map the
> same (not rescaling), and that does not work, the color of the geometry
> stays the same:
>
> ###############
>
> *speedArrayLUT = GetColorTransferFunction('SpeedArray')*
> *speedArrayLUT.RGBPoints = [0.0, 1.0, 0.0, 0.0, 150.0, 0.0, 0.0, 1.0]*
> *speedArrayLUT.LockScalarRange = 1*
> *speedArrayLUT.ColorSpace = 'HSV'*
> *speedArrayLUT.NanColor = [0.498039, 0.498039, 0.498039]*
> *speedArrayLUT.ScalarRangeInitialized = 1.0*
> *speedArrayLUT.VectorComponent = 671*
> *speedArrayLUT.VectorMode = 'Component'*
>
> *speedArrayPWF = GetOpacityTransferFunction('SpeedArray')*
> *speedArrayPWF.Points = [0.0, 0.0, 0.5, 0.0, 150.0, 1.0, 0.5, 0.0]*
> *speedArrayPWF.ScalarRangeInitialized = 1*
>
> *attributesLUTColorBar = GetScalarBar(speedArrayLUT, renderView1)*
> *attributesLUTColorBar.Title = 'Speed (km/h)'*
>
> *for i in range_15min: *
>
> * speedArrayLUT.VectorComponent = i*
> *        Render()*
> #################
>
> If I add:
>
> *readerDisplay.RescaleTransferFunctionToDataRange() *
>
> in the loop, I do see the range of the color bar changing with each
> iteration, but the color of the rendered geometry does not change. Is there
> a way to force an update on the readerDisplay (where, *readerDisplay =
> GetDisplayProperties(reader, view=renderView1)*)
>
> Thanks for any suggestions.
>
> Matei
>
>
>
>
> _______________________________________________
> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/paraview/attachments/20150826/e0b08301/attachment.html>


More information about the ParaView mailing list