1

I'm trying to create a ProgrammableFilter in Paraview using Python. The filter should take the current selected points and count them (the filter will be more elaborated, but this is enough for explaining my problem).

In my code I'm not using any variable called 'inputs', but when I execute it I get this output (note there is an error at the end, and the code seems to be executed twice):

Generated random int: 13 using time 1419991906.3
13 Execution start
13 Selection is active

Generated random int: 59 using time 1419991906.34
59 Execution start
59 No selection is active
59 Execution end

13 Extr_Sel_raw was not None
13 Number of cells: 44
13 Execution end

Traceback (most recent call last):
  File "<string>", line 22, in <module>
NameError: name 'inputs' is not defined

The code is the following, my pipeline has 2 steps, the first is a "Sphere source" and the second is the ProgrammableFilter with this code:

import paraview
import paraview.simple
import paraview.servermanager
import random
import time

a = time.time()
random.seed(a)
#time.sleep(1)
tmp_id = random.randint(1,100)
print "\nGenerated random int: %s using time %s" % (tmp_id, a)

print "%s Execution start" % (tmp_id)

proxy = paraview.simple.GetActiveSource()
active_selection = proxy.GetSelectionInput(proxy.Port)

if active_selection is None:
    print "%s No selection is active" % (tmp_id)
else: 
    print "%s Selection is active" % (tmp_id)
    Extr_Sel = paraview.simple.ExtractSelection(Selection=active_selection)
    Extr_Sel_raw = paraview.servermanager.Fetch(Extr_Sel)
    if Extr_Sel_raw is None:
        print "%s Extr_Sel_raw was None" % (tmp_id)
    else:
        print "%s Extr_Sel_raw was not None" % (tmp_id)
        print "%s Number of cells: %s" % (tmp_id, Extr_Sel_raw.GetNumberOfCells())

    pdi = self.GetPolyDataInput()
    pdo =  self.GetPolyDataOutput()
    pdo.SetPoints(pdi.GetPoints())

print "%s Execution end\n" % (tmp_id)

Do you know what can be causing my problem?

Daniel
  • 21,933
  • 14
  • 72
  • 101
  • did you try hunting down line 22 (the line that calls inputs)? – duhaime Jan 02 '15 at 03:47
  • It's not line 22 of my code, if you see the output, the last line of my code is being successfully executed (it prints a message) – Daniel Jan 02 '15 at 15:58
  • Indeed! My hunch is that line 22 in one of the paraview scripts is calling some object `inputs` that is undefined in some cases. – duhaime Jan 02 '15 at 21:31
  • Do you know how I can check which of Paraview's script is that one ? – Daniel Jan 03 '15 at 04:23
  • Well, you could run a grep search over the paraview directory. Check this out: http://stackoverflow.com/questions/15622328/how-to-grep-a-string-in-a-directory-and-all-its-subdirectories-files-in-linux Otherwise, you could write a quick search in Python, or you could go old fashioned and just open the files and control f, depending on how many there are... – duhaime Jan 03 '15 at 13:57
  • The Paraview sources are too big to run a "grep -r inputs *" (It took 29 hours to compile, so imagine). If I had a more specific string, sure, but with just "inputs" that search doesn't seem to have a good future. – Daniel Jan 03 '15 at 15:26
  • You should try to use a macro for this, you are not supposed to manipulate the pipeline inside a programmable filter – lib Jan 06 '15 at 12:22
  • 1
    Using paraview.simple or paraview.servermanager in a Programmable Filter is highly discouraged and not supported. Without going into to much detail, suffice it to say that data processing pipelines cannot mix client-control code. – Utkarsh Jan 16 '15 at 15:31

1 Answers1

0

After some work I found how to achieve to access the selected points in Paraview without generating that weird error mentioned above.

Here is the code:

import paraview
import paraview.simple

proxy = paraview.simple.GetActiveSource()

if proxy is None:
    print "Proxy is None" 
    return

active_selection = proxy.GetSelectionInput(proxy.Port)

if active_selection is None:
    print "No selection is active" 
    return

print "Selected points: %s" % (active_selection.IDs)
print "Amount of points: %s" % (len(active_selection.IDs) / 2)

And this is the output if I select 6 points in a Sphere Source:

Selected points: [0, 14, 0, 15, 0, 16, 0, 20, 0, 21, 0, 22]
Amount of points: 6

You can see that each selected point generates 2 IDs, the first one is the "Process ID" and the second one is the actual ID of your point.

Anyway, the reason of the original error remains unclear to me.

Daniel
  • 21,933
  • 14
  • 72
  • 101