http://www.vtk.org/Wiki/VTK/Examples/Python/Widgets/ContourWidget
上有这个官方的VTK ContourWidget示例我正在尝试在Python 3.4和VTK 7.0.0和7.1.1上运行这个非常好的示例而不做任何更改,并且让线上的Python完全无声地崩溃
contourWidget.Initialize(pd,1)
任何线索?
答案 0 :(得分:2)
看来你应该在lines.InsertNextCell中使用索引对的vtkIdList。 这段代码非常适合我:
import vtk
import math
def mkVtkIdList(it):
vil = vtk.vtkIdList()
for i in it:
vil.InsertNextId(int(i))
return vil
if __name__ == '__main__':
renderer = vtk.vtkRenderer()
renderWindow = vtk.vtkRenderWindow()
renderWindow.AddRenderer(renderer)
interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(renderWindow)
renderer.SetBackground(0.1, 0.2, 0.4)
renderWindow.SetSize(600, 600)
contourRep = vtk.vtkOrientedGlyphContourRepresentation()
contourRep.GetLinesProperty().SetColor(1, 0, 0) # set color to red
contourWidget = vtk.vtkContourWidget()
contourWidget.SetInteractor(interactor)
contourWidget.SetRepresentation(contourRep)
contourWidget.On()
points = vtk.vtkPoints()
lines = vtk.vtkCellArray()
for i in range(0, 21):
angle = 2.0 * math.pi * i / 20.0
points.InsertPoint(i, (0.1 * math.cos(angle), 0.1 * math.sin(angle), 0.0))
lines.InsertNextCell(mkVtkIdList([i, i+1]))
pd = vtk.vtkPolyData()
pd.SetPoints(points)
pd.SetLines(lines)
contourWidget.Initialize(pd, 1)
contourWidget.Render()
renderer.ResetCamera()
renderWindow.Render()
interactor.Initialize()
interactor.Start()
contourWidget.Off()