【问题标题】:Paraview: NameError: name 'inputs' is not definedParaview:NameError:未定义名称“输入”
【发布时间】:2015-02-27 04:48:45
【问题描述】:

我正在尝试使用 Python 在 Paraview 中创建 ProgrammableFilter。过滤器应该取当前选择的点并计算它们(过滤器会更详细,但这足以解释我的问题)。

在我的代码中,我没有使用任何名为“输入”的变量,但是当我执行它时,我得到了这个输出(注意最后有一个错误,代码似乎被执行了两次):

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

代码如下,我的管道有2个步骤,第一个是“Sphere source”,第二个是带有此代码的ProgrammableFilter:

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)

你知道是什么导致了我的问题吗?

【问题讨论】:

  • 您是否尝试过查找第 22 行(调用输入的行)?
  • 这不是我的代码的第22行,如果你看到输出,我的代码的最后一行正在成功执行(它会打印一条消息)
  • 确实!我的预感是 paraview 脚本之一的第 22 行正在调用某些对象inputs,在某些情况下该对象未定义。
  • 你知道我如何检查 Paraview 的哪个脚本是那个吗?
  • 强烈建议不要在可编程过滤器中使用 paraview.simple 或 paraview.servermanager,也不支持。无需赘述,只要说数据处理管道不能混合客户端控制代码就足够了。

标签: python paraview


【解决方案1】:

经过一些工作,我发现了如何在不产生上述奇怪错误的情况下访问 Paraview 中的选定点。

代码如下:

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)

如果我在 Sphere Source 中选择 6 个点,这就是输出:

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

可以看到每个选中的点都会生成2个ID,第一个是“进程ID”,第二个是你的点的实际ID。

无论如何,我仍然不清楚原始错误的原因。

【讨论】:

    猜你喜欢
    • 2013-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-22
    相关资源
    最近更新 更多