Hello again,

I still have one issue remaining that I couldn't solve:

I added the RequestInformation Sript to my programmable filter, which 
dynamically sets the WHOLE_EXTENT attribute so that it corresponds to the 
extent of the input (polyData) and everything renders properly.

However, if I save the state like this, and reload it in a fresh session, the 
RequestInformation script reports self.GetInputDataObject(0,0).GetBounds() for 
be (1.0, -1.0, 1.0, -1.0, 1.0, -1.0). And then of course the output of the 
filter is not rendered.



I assume the mistake here is to query self.GetInputDataObject in the 
RequestInformation, because what I understand is, when loading, all 
RequestInformation scripts are called before any requestData. Thus, the 
upstream data doesn't exist.



If all of this is true, how can I access the upstream WHOLE_EXTENT from the 
informationRequest script to propagate the value in my filter ?



You can find attached an example save state.



Best regards,

--

Dorian Vogel



On Thursday, May 18, 2017 2:53:17 PM CEST Favre Jean wrote:

Dorian

it is a frequent error to forget to set the RequestInformationScript of the 
ProgrammableFilter.

I have quickly hacked your code to make it work and give it here as an example 
to be polished further.

try to load the following python script.

-----------------
Jean/CSCS


# state file generated using paraview version 5.3.0

# ----------------------------------------------------------------
# setup views used in the visualization
# ----------------------------------------------------------------

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

# Create a new 'Render View'
renderView1 = CreateView('RenderView')
renderView1.ViewSize = [936, 1000]
renderView1.AxesGrid = 'GridAxes3DActor'
renderView1.CenterOfRotation = [-0.0499999999999999, 0.5, -0.0499999999999999]
renderView1.StereoType = 0
renderView1.CameraPosition = [0.482700520220015, 56.6970415421498, 9.0988527113203]
renderView1.CameraFocalPoint = [-0.0500000000000029, 0.499999999999997, -0.0499999999999979]
renderView1.CameraViewUp = [0.033713222813006496, -0.16090408007209697, 0.9863940873827828]
renderView1.CameraParallelScale = 0.849145697931444
renderView1.Background = [0.32, 0.34, 0.43]

# init the 'GridAxes3DActor' selected for 'AxesGrid'
renderView1.AxesGrid.Visibility = 1

# ----------------------------------------------------------------
# setup the data processing pipelines
# ----------------------------------------------------------------

# create a new 'Box'
box1 = Box()
box1.XLength = 10.0
box1.YLength = 10.0
box1.ZLength = 10.0

# create a new 'Transform'
transform1 = Transform(Input=box1)
transform1.Transform = 'Transform'

# init the 'Transform' selected for 'Transform'
transform1.Transform.Rotate = [6.23937685744707, -9.98160528931485, -32.6306073159542]
transform1.Transform.Scale = [0.999999999999999, 0.999999999999997, 0.999999999999999]

# create a new 'Programmable Filter'
programmableFilter2 = ProgrammableFilter(Input=transform1)
programmableFilter2.OutputDataSetType = 'vtkImageData'
programmableFilter2.Script = 'import math\nfrom vtk import vtkImageData, vtkPolyDataToImageStencil, vtkImageStencil, VTK_UNSIGNED_CHAR\nimport numpy as np\nfrom vtk.util import numpy_support\n\nexecutive = self.GetExecutive()\noutInfo = executive.GetOutputInformation(0)\nexts = [executive.UPDATE_EXTENT().Get(outInfo, i) for i in range(6)]\noutput.SetExtent(exts)\ndims = [exts[1]-exts[0]+1, exts[3]-exts[2]+1, exts[5]-exts[4]+1]\n\nPOLY_input= self.GetInputDataObject(0,0)\n\ninputBounds= POLY_input.GetBounds()\n\nwhiteImage=vtkImageData()\nwhiteImage.SetSpacing(self.imageSpacing)\n\nwhiteImage.SetDimensions(dims)\n\nwhiteImage.SetOrigin(min(inputBounds[0:2])- self.imageSpacing[0],\n                      min(inputBounds[2:4])- self.imageSpacing[1],\n                      min(inputBounds[4:])- self.imageSpacing[2])\n\nwhiteImage.AllocateScalars(VTK_UNSIGNED_CHAR, 1)\n\nfor i in range(0, whiteImage.GetNumberOfPoints()):\n    whiteImage.GetPointData().GetScalars().SetTuple1(i, 255)\n\npoly2stencil = vtkPolyDataToImageStencil()\npoly2stencil.SetInputData(POLY_input)\npoly2stencil.SetOutputOrigin(whiteImage.GetOrigin())\npoly2stencil.SetOutputSpacing(whiteImage.GetSpacing())\npoly2stencil.SetOutputWholeExtent(whiteImage.GetExtent())\npoly2stencil.Update()\n\nimageStencil= vtkImageStencil()\nimageStencil.SetInputData(whiteImage)\nimageStencil.SetStencilConnection(poly2stencil.GetOutputPort())\nimageStencil.ReverseStencilOff()\nimageStencil.SetBackgroundValue(0)\nimageStencil.Update()\n\noutput.ShallowCopy(imageStencil.GetOutput())'
programmableFilter2.RequestInformationScript = "executive = self.GetExecutive ()\noutInfo = executive.GetOutputInformation(0)\ninput0=self.GetInputDataObject(0,0)\n\ninputBounds= input0.GetBounds()\n\nprint('inputBounds: %s'%str(inputBounds))\n\nself.imageSpacing=(0.1,0.1,0.1)\n\ndims = [int(math.ceil(abs(inputBounds[1]-inputBounds[0])/self.imageSpacing[0])+2), \n        int(math.ceil(abs(inputBounds[3]-inputBounds[2])/self.imageSpacing[1])+2), \n        int(math.ceil(abs(inputBounds[5]-inputBounds[4])/self.imageSpacing[2])+2)\n        ]\n\noutInfo.Set(executive.WHOLE_EXTENT(), 0, dims[0]-1 , 0, dims[1]-1 , 0, dims[2]-1)\noutInfo.Set(vtk.vtkDataObject.SPACING(), self.imageSpacing[0], self.imageSpacing[1], self.imageSpacing[2])"
programmableFilter2.RequestUpdateExtentScript = 'executive = self.GetExecutive ()\noutInfo = executive.GetOutputInformation(0)\ninput0=self.GetInputDataObject(0,0)\n\ninputBounds= input0.GetBounds()\n\nself.imageSpacing=(0.1,0.1,0.1)\n\ndims = [int(math.ceil(abs(inputBounds[1]-inputBounds[0])/self.imageSpacing[0])+2), \n        int(math.ceil(abs(inputBounds[3]-inputBounds[2])/self.imageSpacing[1])+2), \n        int(math.ceil(abs(inputBounds[5]-inputBounds[4])/self.imageSpacing[2])+2)\n        ]\n\noutInfo.Set(executive.UPDATE_EXTENT(), 0, dims[0]-1 , 0, dims[1]-1 , 0, dims[2]-1)\noutInfo.Set(vtk.vtkDataObject.SPACING(), self.imageSpacing[0], self.imageSpacing[1], self.imageSpacing[2])\n'
programmableFilter2.PythonPath = ''

# ----------------------------------------------------------------
# setup color maps and opacity mapes used in the visualization
# note: the Get..() functions create a new object, if needed
# ----------------------------------------------------------------

# get color transfer function/color map for 'ImageScalars'
imageScalarsLUT = GetColorTransferFunction('ImageScalars')
imageScalarsLUT.RGBPoints = [0.0, 0.231373, 0.298039, 0.752941, 127.5, 0.865003, 0.865003, 0.865003, 255.0, 0.705882, 0.0156863, 0.14902]
imageScalarsLUT.ScalarRangeInitialized = 1.0

# get opacity transfer function/opacity map for 'ImageScalars'
imageScalarsPWF = GetOpacityTransferFunction('ImageScalars')
imageScalarsPWF.Points = [0.0, 0.0, 0.5, 0.0, 255.0, 1.0, 0.5, 0.0]
imageScalarsPWF.ScalarRangeInitialized = 1

# ----------------------------------------------------------------
# setup the visualization in view 'renderView1'
# ----------------------------------------------------------------

# show data from programmableFilter2
programmableFilter2Display = Show(programmableFilter2, renderView1)
# trace defaults for the display properties.
programmableFilter2Display.Representation = 'Slice'
programmableFilter2Display.ColorArrayName = ['POINTS', 'ImageScalars']
programmableFilter2Display.LookupTable = imageScalarsLUT
programmableFilter2Display.Interpolation = 'Flat'
programmableFilter2Display.OSPRayScaleArray = 'ImageScalars'
programmableFilter2Display.OSPRayScaleFunction = 'PiecewiseFunction'
programmableFilter2Display.SelectOrientationVectors = 'None'
programmableFilter2Display.ScaleFactor = 1.33
programmableFilter2Display.SelectScaleArray = 'None'
programmableFilter2Display.GlyphType = 'Arrow'
programmableFilter2Display.PolarAxes = 'PolarAxesRepresentation'
programmableFilter2Display.ScalarOpacityUnitDistance = 0.183748441073244
programmableFilter2Display.SliceMode = 'XZ Plane'
programmableFilter2Display.Slice = 112

# show color legend
programmableFilter2Display.SetScalarBarVisibility(renderView1, True)

# show data from transform1
transform1Display = Show(transform1, renderView1)
# trace defaults for the display properties.
transform1Display.Representation = 'Wireframe'
transform1Display.ColorArrayName = [None, '']
transform1Display.OSPRayScaleArray = 'Normals'
transform1Display.OSPRayScaleFunction = 'PiecewiseFunction'
transform1Display.SelectOrientationVectors = 'None'
transform1Display.ScaleFactor = 0.155897665023804
transform1Display.SelectScaleArray = 'None'
transform1Display.GlyphType = 'Arrow'
transform1Display.PolarAxes = 'PolarAxesRepresentation'
transform1Display.GaussianRadius = 0.0779488325119019
transform1Display.SetScaleArray = [None, '']
transform1Display.ScaleTransferFunction = 'PiecewiseFunction'
transform1Display.OpacityArray = [None, '']
transform1Display.OpacityTransferFunction = 'PiecewiseFunction'

# setup the color legend parameters for each legend in this view

# get color legend/bar for imageScalarsLUT in view renderView1
imageScalarsLUTColorBar = GetScalarBar(imageScalarsLUT, renderView1)
imageScalarsLUTColorBar.Position = [0.85, 0.52]
imageScalarsLUTColorBar.Title = 'ImageScalars'
imageScalarsLUTColorBar.ComponentTitle = ''

# ----------------------------------------------------------------
# finally, restore active source
SetActiveSource(programmableFilter2)
# ----------------------------------------------------------------
_______________________________________________
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

Reply via email to