[Paraview] Programmable sphere source - update position each timestep from csv file

James Avery j.avery at ucl.ac.uk
Wed Jul 13 04:59:23 EDT 2016


Hi all,

I am trying to create a programmable source to create a sphere, the 
location of which updates per time step based on coordinates in a csv 
file. However, I have sort of got my head around the python library 
(thanks to tracing what I do in the GUI!), but I think one needs to use 
the vtk library instead? I have written a python script which does the 
job when called from the python shell, but this is not updating when the 
timestep changes. I have tried adapting this code to work as a 
programmable source, but to no avail.

Here is the code for the programmable source I have so far:

import vtk
import os
import csv

csvfilename = '../../resources/vtk/testpos.csv'
csvfilename= os.path.abspath(csvfilename)

animationScene1 = GetAnimationScene()
target = int(animationScene1.AnimationTime)
print "Target value is: " + str(target)

pos = [0.0, 0.0, 0.0]
count=0
with open(csvfilename) as f:
     r = csv.reader(f)
     for row in r:
         print "Current row :" + str(row)
         if count == target:
             print "found it"
             pos = [float(i) for i in row]
             break
         count += 1
print "Pos is now : " + str(pos)

s=vtk.vtkSphereSource()
s.SetCenter(pos)
s.SetRadius(10)
s.Update()


The csv stuff works as far as I can tell, but it gives an error because 
GetAnimationScene is not defined. However, there is another problem, 
even if I ignore all of the time dependent things and just try to create 
a sphere in this manner:

import vtk
s=vtk.vtkSphereSource()
s.SetCenter([0,0,0])
s.SetRadius(10)
s.Update()

there are no errors, but no sphere either! So I guess I am missing 
something fundamental about the difference between python scripting and 
programmable sources. Further, I wonder if it would be easier to change 
the position of an already created sphere source with a programmable 
filter instead?

Has anybody solved a similar problem and can point me in the correct 
direction? Any help would be greatly appreciated.

Kind regards,

James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/paraview/attachments/20160713/4009daac/attachment.html>


More information about the ParaView mailing list