我在试着用硬件选择器.py例如,https://lorensen.github.io/VTKExamples/site/Python/Visualization/HardwareSelector/ 我唯一更改的部分是将“UserInput”替换为“middlebuttonpressent”。你知道吗
问题是这只是间歇性的。你知道吗
我的目标是获取一个stl文件,并仅从某个视点找到那些可见的元素。 我使用的是Python3.7.3 64位和vtk 8.2.0。用水蟒包装。你知道吗
我似乎找不到任何关于这个问题的信息,但我尝试过创造一个新的水蟒环境,并得到同样的问题。我不是一个有经验的程序员,所以我不知道该怎么解决这个问题。你知道吗
预期结果是interactor窗口中的可见单元格列表。这只是有时印刷的。 其余时间,interactior窗口关闭,终端中没有输出。你知道吗
理想情况下,这将得到解决,但如果有人有任何更好的方法获得这些细胞的建议,我将不胜感激。你知道吗
这是我第一次在这里发布一个问题,所以如果我错过了任何重要的信息,我深表歉意,并将很高兴提供进一步的细节,如果/当要求。你知道吗
编辑-现在根据请求附加代码(这与前面所述的示例代码基本相同)。你知道吗
from __future__ import print_function
import vtk
import vtk.util.numpy_support as VN
# Callback for when selection is changed
# This is global - fix later.
ren1 = vtk.vtkRenderer()
def selectionCallback(caller, eventId):
hsel = vtk.vtkHardwareSelector()
hsel.SetFieldAssociation(vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS)
hsel.SetRenderer(ren1)
x, y = caller.GetRenderWindow().GetSize()
# Create a small area around clicked point for selector area
hsel.SetArea(0, 0, x, y)
res = hsel.Select()
numNodes = res.GetNumberOfNodes()
if (numNodes < 1):
print("No visible cells")
else:
sel_node = res.GetNode(0)
print('Visible cell IDs: ', VN.vtk_to_numpy(sel_node.GetSelectionList()).tolist())
def main():
colors = vtk.vtkNamedColors()
sphere = vtk.vtkSphereSource()
sphere.SetCenter(0, 0, 0)
sphere.SetRadius(5.0)
sphereMapper = vtk.vtkPolyDataMapper()
sphereMapper.SetInputConnection(sphere.GetOutputPort())
sphereActor = vtk.vtkActor()
sphereActor.SetMapper(sphereMapper)
sphereActor.GetProperty().SetColor(colors.GetColor3d('Bisque'))
ren1.AddActor(sphereActor)
ren1.SetBackground(0.1, 0.2, 0.4)
ren1.GetActiveCamera().ParallelProjectionOn()
ren1.SetBackground(colors.GetColor3d('Navy'))
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
renWin.SetSize(300, 300)
renWin.Render()
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
iren.AddObserver('LeftButtonPressEvent', selectionCallback)
style = vtk.vtkInteractorStyleTrackballCamera()
iren.SetInteractorStyle(style)
renWin.GetInteractor().SetInteractorStyle(style)
ren1.ResetCamera()
renWin.Render()
iren.Initialize()
iren.Start()
if __name__ == '__main__':
main()
在硬件选择器.py示例使用“u”键调用selectionCallback() 所以它可以打印出“可见的细胞ID”,你的代码工作得很好。没有水蟒。 在lorensen的示例中,如果鼠标光标离开示例窗口,Hardselector可能会丢失窗口。所以我们有“可见细胞ID:[6711651]”。但如果窗口最大化,所有的工作都很好。
P.S.问题可能会在您的链接讨论中解决吗?
hsel.设置区域(0,0,x-1,y-1)代替hsel.设置区域(0,0,x,y)
相关问题 更多 >
编程相关推荐