[vtkusers] PointPicker to select only visible points

Dirk Fressmann dirk.fressmann at dynamore.de
Wed Nov 26 12:45:29 EST 2008


I have a vtkUnstructuredGrid with corresponding nodes, cells and actors.
I want to be able to pick single nodes, where the pick should only apply 
to the visible nodes.

My code looks like this (python)

-------------------------
import vtk
nodes = vtk.vtkPoints()
nodes.InsertPoint(0,[0.0, 0.0, 0.0])
nodes.InsertPoint(1,[1.0, 0.0, 0.0])
nodes.InsertPoint(2,[1.0, 1.0, 0.0])
nodes.InsertPoint(3,[0.0, 1.0, 0.0])
nodes.InsertPoint(4,[0.0, 0.0, 1.0])
nodes.InsertPoint(5,[1.0, 0.0, 1.0])
nodes.InsertPoint(6,[1.0, 1.0, 1.0])
nodes.InsertPoint(7,[0.0, 1.0, 1.0])

grid = vtk.vtkUnstructuredGrid()
grid.SetPoints(nodes)

pts = vtk.vtkIdList()
pts.InsertId(0,0)
pts.InsertId(1,1)
pts.InsertId(2,2)
pts.InsertId(3,3)
pts.InsertId(4,4)
pts.InsertId(5,5)
pts.InsertId(6,6)
pts.InsertId(7,7)
grid.InsertNextCell(12,pts)

mapper = vtk.vtkDataSetMapper()
mapper.SetInput(grid)
actor = vtk.vtkActor()
actor.SetMapper(mapper)

renderer = vtk.vtkRenderer()
renderer.AddActor(actor)

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

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renwin)


def lPickCallback(object,event):
     nid = object.GetPointId()
     print "picked point", nid

lpicker = vtk.vtkPointPicker()
iren.SetPicker(lpicker)
lpicker.AddObserver("StartPickEvent", lPickCallback)
lpicker.AddObserver("PickEvent", lPickCallback)
lpicker.AddObserver("EndPickEvent", lPickCallback)

iren.Initialize()
renwin.Render()
iren.Start()
--------------------------------

I figured out that I have to use the vtkSelectVisiblePoints() class, i.e.

visPts = vtk.vtkSelectVisiblePoints()
visPts.SetInput(grid)
visPts.SetRenderer(renderer)

Can anyone give me a hint how to connect this class to the pick-observer 
events? And how would the above example be used using the newer 
AddInputConnection() pipeline connections?

I would greatly appreciate any help on this

Cheers Dirk











More information about the vtkusers mailing list