在 python 上启动 VTK 示例时崩溃
crash when starting VTK example on python
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)
有线索吗?
看来您应该在 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()
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)
有线索吗?
看来您应该在 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()