Dear all,

I am relatively new to scripting in paraview using vtk wrappers. However one 
situation I always find myself in is writing a python script to be executed 
with pvpython and then having to include a miniature python script as an input 
to programmableFilters. As far as I understand, this allows the manipulation of 
pipeline data on the server side (so you don't have to retrieve data to the 
client) inside a tailored script. What I don't understand is why the process 
has to be so convoluted. At the very least it makes debugging very annoying as 
you don't know exactly where in the script that you input into the programmable 
filter a potential error might be. I have an example to illustrate.

Below are two pieces of code within an if/else switch where I add some 
temperature data to a vtkSphereSource. The first uses the programmableFilter 
approach and the second attempts to do the manipulation on the client side and 
then "upload/update" the server side. However the second approach does not 
result in any temperature data when I view it in paraview. What am I missing?



from paraview.simple import *
paraview.simple._DisableFirstRenderCameraReset()
import math
import vtk

use_prog_filt = False

# What I dont want to be doing:
if use_prog_filt:
    sphereSourceProxy = Sphere()
    renderView1 = GetActiveViewOrCreate('RenderView')
    sphereDisplay = Show(sphereSourceProxy, renderView1)
    sphereDisplay.ColorArrayName = [None, '']
    renderView1.ResetCamera()

    my_script= [
        'pdi = self.GetPolyDataInput()',
        'pdo = self.GetPolyDataOutput()',
        '',
        'temperature= vtk.vtkDoubleArray()',
        'npoints = pdi.GetNumberOfPoints() ',
        'for i in range(npoints):',
        '   x, y, z = pdi.GetPoint(i)',
        '   temperature.InsertNextValue(x)',
        'temperature.SetName("Temperature")',
        'pdo.GetPointData().AddArray(temperature)']


    programmableFilter = ProgrammableFilter(Input=sphereSourceProxy)
    programmableFilter.Script = str("\n".join(my_script))
    programmableFilter.RequestInformationScript = ''
    programmableFilter.RequestUpdateExtentScript = ''
    programmableFilter.PythonPath = ''

    programmableFilterDisplay = Show(programmableFilter, renderView1)

# What I want to be doing:
else:
    #sphereSource = vtk.vtkSphereSource()
    #print dir(sphereSource)

    sphereSourceProxy = Sphere()
    renderView1 = GetActiveViewOrCreate('RenderView')
    sphereDisplay = Show(sphereSourceProxy, renderView1)
    sphereDisplay.ColorArrayName = [None, '']
    renderView1.ResetCamera()

    pdi = servermanager.Fetch(input=sphereSourceProxy)
    npoints = pdi.GetNumberOfPoints() 

    temperature = vtk.vtkDoubleArray()
    temperature.SetName("Temperature")
    for i in range(npoints):
        x, y, z = pdi.GetPoint(i)
        temperature.InsertNextValue(x)
    pdi.GetPointData().AddArray(temperature)


    new_SphereSource = TrivialProducer()
    filt = new_SphereSource.GetClientSideObject()  # filter is a 
vtkTrivialProducer
    filt.SetOutput(pdi)
    new_SphereSource.UpdatePipeline()

    # The temperature data is available, but not in the paraview renderview...  
    print servermanager.Fetch(input=new_SphereSource)
_______________________________________________
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:
https://public.kitware.com/mailman/listinfo/paraview

Reply via email to