在python上启动VTK示例时崩溃

问题描述 投票:0回答:1

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)

有线索吗?

python vtk
1个回答
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()
© www.soinside.com 2019 - 2024. All rights reserved.