def p2pline(P0, P1, width=1,modelName="Line",color = "blue"):
points = vtk.vtkPoints()
points.SetNumberOfPoints(2)
points.SetPoint(0, P0[0], P0[1], P0[2])
points.SetPoint(1, P1[0], P1[1], P1[2])
line = vtk.vtkLineSource()
line.SetPoints(points)
lineNode = slicer.modules.models.logic().AddModel(line.GetOutputPort())
lineNode.SetName(modelName)
modelDisplay = lineNode.GetDisplayNode()
modelDisplay.SetColor(myColor(color)) # yellow
modelDisplay.SetLineWidth(width)
modelDisplay.SetOpacity(1)
modelDisplay.SetVisibility2D(1)
以上的代码想用2点画一条直线,可不知道为啥在2D视图里看不到,我发现用projection可以看到,我该怎么实现呢?
The above code wants to draw a straight line with 2 points, but I don’t know why I can’t see it in 2D view, but I found that I can see it with projection, how can I achieve it?