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

Cory Quammen cory.quammen at kitware.com
Thu Jul 14 16:38:22 EDT 2016


Hi James,

Instead of the Programmable Source, you should be able to use the
paraview.simple module to do this in a Python script. Here's code to
create and show a Sphere source:

s = Sphere()
Show(s)

You can update the sphere position with

s.Center = [1, 2, 3]

Obviously, you can use the above line in your loop over the positions
from the CSV file. After each Center update, you should re-render with

RenderAllViews()

You can run Python script files through the Python console by clicking
the "Run Script" button and navigating to your script file.

HTH,
Cory

On Wed, Jul 13, 2016 at 4:59 AM, James Avery <j.avery at ucl.ac.uk> wrote:
> 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
>
> _______________________________________________
> 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
>



-- 
Cory Quammen
R&D Engineer
Kitware, Inc.


More information about the ParaView mailing list