python code:

import vtk
# Call back function

def lineCallback(obj, event):
    print('The position of first end point: {}, {}, {}'.format(*obj.GetPoint1()))

# A renderer and render window
renderer = vtk.vtkRenderer()
renderer.SetBackground(0, 0, 0)

renwin = vtk.vtkRenderWindow()
renwin.AddRenderer(renderer)

# An interactor
interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(renwin)

# A Line widget
lineWidget = vtk.vtkLineWidget()
lineWidget.SetInteractor(interactor)
#lineWidget.SetRepresentationToSurface()
lineWidget.On()

# Connect the event to a function
lineWidget.AddObserver("InteractionEvent", lineCallback)

# Start
interactor.Initialize()
interactor.Start()

分类: python

发表评论

电子邮件地址不会被公开。 必填项已用*标注