1

I have an automated clip script which i run and as a part of it I would like to have and option to rescale the colour scheme to visible data in range - boolean.

I have found this command clipDisplay.SetScalarBarVisibility(renderView1, True) in the Paraview User Guide (Chapter 10.1.2) and placed at the end of Colour Transfer function within paraview tracked script for the clip.

Running script doesn't give any error but just doesn't do the job of rescaling the colour scheme when compared to same operation done in GUI.

I want to use the code universally, so manually selecting the data in range with number definition is out of the question...

edit

Using trace you'd get:

# trace generated using paraview version 5.7.0
#
# To ensure correct image size when batch processing, please search 
# for and uncomment the line `# renderView*.ViewSize = [*,*]`

#### 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 'p'
pLUT = GetColorTransferFunction('p')
pLUT.AutomaticRescaleRangeMode = "Grow and update on 'Apply'"
pLUT.InterpretValuesAsCategories = 0
pLUT.AnnotationsInitialized = 0
pLUT.ShowCategoricalColorsinDataRangeOnly = 0
pLUT.RescaleOnVisibilityChange = 0
pLUT.EnableOpacityMapping = 0
pLUT.RGBPoints = [-714.7062377929688, 0.231373, 0.298039, 0.752941, -259.51192474365234, 0.865003, 0.865003, 0.865003, 195.68238830566406, 0.705882, 0.0156863, 0.14902]
pLUT.UseLogScale = 0
pLUT.ColorSpace = 'Diverging'
pLUT.UseBelowRangeColor = 0
pLUT.BelowRangeColor = [0.0, 0.0, 0.0]
pLUT.UseAboveRangeColor = 0
pLUT.AboveRangeColor = [0.5, 0.5, 0.5]
pLUT.NanColor = [1.0, 1.0, 0.0]
pLUT.NanOpacity = 1.0
pLUT.Discretize = 1
pLUT.NumberOfTableValues = 256
pLUT.ScalarRangeInitialized = 1.0
pLUT.HSVWrap = 0
pLUT.VectorComponent = 0
pLUT.VectorMode = 'Magnitude'
pLUT.AllowDuplicateScalars = 1
pLUT.Annotations = []
pLUT.ActiveAnnotatedValues = []
pLUT.IndexedColors = []
pLUT.IndexedOpacities = []

# Rescale transfer function
pLUT.RescaleTransferFunction(-413.7960510253906, 192.35369873046875)

# get opacity transfer function/opacity map for 'p'
pPWF = GetOpacityTransferFunction('p')
pPWF.Points = [-714.7062377929688, 0.0, 0.5, 0.0, 195.68238830566406, 1.0, 0.5, 0.0]
pPWF.AllowDuplicateScalars = 1
pPWF.UseLogScale = 0
pPWF.ScalarRangeInitialized = 1

# Rescale transfer function
pPWF.RescaleTransferFunction(-413.7960510253906, 192.35369873046875)

Any ideas please? Cheers

1 Answers1

3

clip1Display.RescaleTransferFunctionToDataRange(False, True) is the line you want. For information, when looking for the python version of an interface action you can use the Trace (Tools/Start Trace). It records each action from the interface and when you stop (Tools/Stop Trace) it prints the python version of those actions.

edit

You can not easily rescale to visible range in python.

One workaround consist of extracting visible data to get the visible range and finally apply it on the original data transfer function. This Macro does the trick


from paraview.simple import *
v=GetActiveView()
source=GetActiveSource()
SelectSurfacePoints(Rectangle=[0, 0, v.ViewSize[0], v.ViewSize[1]])# Or SelectPointsThrough 
extractSelection1=ExtractSelection()
# s=Show()
arrayInfo = e.PointData['X'] # replace 'X' by the array you want
r=arrayInfo.GetRange(0)
Delete(extractSelection1)
del extractSelection1
SetActiveSource(source)
ClearSelection()

pLUT = GetColorTransferFunction('X')
pLUT.RescaleTransferFunction(r[0], r[1])


Nico Vuaille
  • 2,310
  • 1
  • 6
  • 14
  • Thank you, for the trace tip, however, the trace function defines the current data in range, which is not something I want. – Ota Michálek Jul 22 '20 at 07:36
  • 'clip1Display.RescaleTransferFunctionToDataRange(False, True)' is the line I used, but it doesn't rescale the colour scheme. – Ota Michálek Jul 22 '20 at 07:39
  • I am sorry, I see the problem now. What i want is not Data Range, but Visible Data Range. Is there a line clip1Display.RescaleTransferFunctionToVisibleDataRange(False, True) ?? – Ota Michálek Jul 22 '20 at 08:10
  • Thank you, I understand. I've replaced the 'X' with my array, with this I am getting this error now. Is there something else to do? `>>> exec(open('/home/otamichalek/Documents/Scripts/V5/test.py').read()) Traceback (most recent call last): File "/usr/lib/python3.8/code.py", line 90, in runcode exec(code, self.locals) File "", line 1, in File "", line 5, in NameError: name 'SelectSurfacePoints' is not defined` – Ota Michálek Jul 22 '20 at 11:17
  • 1
    This method is in PV since version 5.8. With previous versions you need to use `view.SelectSurfacePoints` API (that may be different) – Nico Vuaille Jul 22 '20 at 11:38
  • Thanks, where can I find documentation for this please? – Ota Michálek Jul 22 '20 at 12:26
  • 1
    See the implementation of the current `SelectSurfacePoints` method: https://gitlab.kitware.com/paraview/paraview/-/blob/master/Wrapping/Python/paraview/selection.py#L169 What you want to rewrite is the line 182 – Nico Vuaille Jul 22 '20 at 12:37
  • Ok, so I got `v.SelectSurfacePoints([0, 0, v.ViewSize[0], v.ViewSize[1]], , source,0)`, what do I place instead of the vtkCollection please? i. e. What is SelectedReps? Also, what does 'e.' refer to in line 7 in your solution please? – Ota Michálek Jul 24 '20 at 10:31