<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p>Hi Cory,</p>
    <p>Thanks for your help. Sorry if the message was rambling, but I
      had a script which made the spheres is called from the python
      shell as you suggest. However, I was looking for a solution that
      was automatically updated when changing the timestep in the GUI -
      I was not clear on this, apologies. So I thought I had to use a
      programmable source or programmable filter. <br>
    </p>
    <p>The spheres are designed to indicate locations inside a larger
      dataset, so I compromised by having a spherical clip which updates
      its centre. The code for the programmable filter to do this is:</p>
    <p><font size="-2">import vtk<br>
        import csv<br>
        csvfilename = '../../resources/vtk/testpos.csv'<br>
        input = self.GetInputDataObject(0, 0)<br>
        output = self.GetOutputDataObject(0)<br>
        <br>
        t =
self.GetInputDataObject(0,0).GetInformation().Get(vtk.vtkDataObject.DATA_TIME_STEP())<br>
        TimePoint  = int(t)<br>
            # read the specific line from the csv file<br>
        Centre = [0.0, 0.0, 0.0]<br>
        count = 0<br>
        <br>
        with open(csvfilename) as f:<br>
            r = csv.reader(f)<br>
            for row in r:<br>
                if count == TimePoint:<br>
                    Centre = [float(i) for i in row]<br>
                    break<br>
                count += 1<br>
        <br>
        s = vtk.vtkSphere()<br>
        s.SetCenter(Centre)<br>
        s.SetRadius(10)<br>
        <br>
        clip = vtk.vtkClipDataSet()<br>
        clip.SetInputDataObject(input)<br>
        clip.SetClipFunction(s)<br>
        clip.SetValue(0.0)<br>
        clip.InsideOutOn()<br>
        clip.Update()<br>
        print clip<br>
        <br>
        output.ShallowCopy(clip.GetOutputDataObject(0))</font><br>
    </p>
    <p>Probably not the most elegant solution, but it seems to be doing
      the job!</p>
    <p>Kind regards,</p>
    <p>James<br>
    </p>
    <div class="moz-cite-prefix">On 14/07/2016 21:38, Cory Quammen
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAB5Fpx75krOrZ55+iiJNMhE9xiZ+D96Hgm1=iGNxokrAn8_cFA@mail.gmail.com"
      type="cite">
      <pre wrap="">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 <a class="moz-txt-link-rfc2396E" href="mailto:j.avery@ucl.ac.uk"><j.avery@ucl.ac.uk></a> wrote:
</pre>
      <blockquote type="cite">
        <pre wrap="">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 <a class="moz-txt-link-abbreviated" href="http://www.kitware.com">www.kitware.com</a>

Visit other Kitware open-source projects at
<a class="moz-txt-link-freetext" href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a>

Please keep messages on-topic and check the ParaView Wiki at:
<a class="moz-txt-link-freetext" href="http://paraview.org/Wiki/ParaView">http://paraview.org/Wiki/ParaView</a>

Search the list archives at: <a class="moz-txt-link-freetext" href="http://markmail.org/search/?q=ParaView">http://markmail.org/search/?q=ParaView</a>

Follow this link to subscribe/unsubscribe:
<a class="moz-txt-link-freetext" href="http://public.kitware.com/mailman/listinfo/paraview">http://public.kitware.com/mailman/listinfo/paraview</a>

</pre>
      </blockquote>
      <pre wrap="">


</pre>
    </blockquote>
    <br>
  </body>
</html>