2017-08-31 1 views

Répondre

2

Il semble que vous devriez utiliser vtkIdList de paires d'index dans lines.InsertNextCell. Ce code fonctionne parfaitement pour moi:

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()