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
from paraview.simple import *
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()

# Create a new 'Render View'
viewID = GetRenderView()

sphere1 = Sphere()
sphere1.Radius = 5.0
sphere1.ThetaResolution = 32
sphere1.PhiResolution = 32
sphere1.UpdatePipeline()

RequestData = """
import math
from vtk import vtkImageData, vtkPolyDataToImageStencil, vtkImageStencil, VTK_UNSIGNED_CHAR, vtkMetaImageWriter
import numpy as np
from vtk.util import numpy_support

executive = self.GetExecutive()
outInfo = executive.GetOutputInformation(0)
exts = [executive.UPDATE_EXTENT().Get(outInfo, i) for i in range(6)]
output.SetExtent(exts)
dims = [exts[1]-exts[0]+1, exts[3]-exts[2]+1, exts[5]-exts[4]+1]

POLY_input= self.GetInputDataObject(0,0)

inputBounds= POLY_input.GetBounds()

whiteImage=vtkImageData()
whiteImage.SetSpacing(self.imageSpacing)

whiteImage.SetDimensions(dims)

whiteImage.SetOrigin(min(inputBounds[0:2])- self.imageSpacing[0],
                      min(inputBounds[2:4])- self.imageSpacing[1],
                      min(inputBounds[4:])- self.imageSpacing[2])

whiteImage.AllocateScalars(VTK_UNSIGNED_CHAR, 1)

for i in range(0, whiteImage.GetNumberOfPoints()):
    whiteImage.GetPointData().GetScalars().SetTuple1(i, 255)

poly2stencil = vtkPolyDataToImageStencil()
poly2stencil.SetInputData(POLY_input)
poly2stencil.SetOutputOrigin(whiteImage.GetOrigin())
poly2stencil.SetOutputSpacing(whiteImage.GetSpacing())
poly2stencil.SetOutputWholeExtent(whiteImage.GetExtent())
poly2stencil.Update()

imageStencil= vtkImageStencil()
imageStencil.SetInputData(whiteImage)
imageStencil.SetStencilConnection(poly2stencil.GetOutputPort())
imageStencil.ReverseStencilOff()
imageStencil.SetBackgroundValue(0)
imageStencil.Update()

output.ShallowCopy(imageStencil.GetOutput())
"""

RequestInfo = """
executive = self.GetExecutive ()
outInfo = executive.GetOutputInformation(0)

dims = [102,102, 102]
self.imageSpacing=(0.1, 0.1, 0.1)
outInfo.Set(executive.WHOLE_EXTENT(), 0, dims[0]-1 , 0, dims[1]-1 , 0, dims[2]-1)
outInfo.Set(vtk.vtkDataObject.SPACING(), self.imageSpacing[0], self.imageSpacing[1], self.imageSpacing[2])
"""

programmableFilter = ProgrammableFilter(Input=sphere1)
programmableFilter.OutputDataSetType = 'vtkImageData'
programmableFilter.Script = RequestData
programmableFilter.RequestInformationScript = RequestInfo
programmableFilter.UpdatePipelineInformation()

# 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


rep0 = Show(programmableFilter, viewID)
rep0.Representation = 'Surface'
rep0.ColorArrayName = ['POINTS', 'ImageScalars']
rep0.LookupTable = imageScalarsLUT
rep0.ScalarOpacityFunction = imageScalarsPWF

Render()
viewID.ResetCamera()
Render()
_______________________________________________
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