[vtkusers] vtkCellPicker failing to pick vtkPolyLine (using Python and wx)
David vanEe
david.vanee at convergent.ca
Tue Dec 11 11:26:14 EST 2012
Hi all,
I've recently updated my VTK from 5.4 to 5.10.1, and some old vtkCellPicker code isn't doing what I want anymore. This 'simple' example works fine in 5.4 (both the blue and red actor highlight when you mouse-over them), but in 5.10.1 only the blue (quad) actor works. The only difference between the two actors (aside from coordinates and colors) is the cellType of vtk.VTK_POLY_LINE vs vtk.VTK_QUAD.
I've tried looking for changes in the pick routine, but vtkCellPicker.cxx has undergone substantial changes and I was unable to locate the cause. Any suggestions for getting the picker to pick the polyline?
Thanks in advance,
Dave
import wx
import vtk
from vtk.wx.wxVTKRenderWindowInteractor import wxVTKRenderWindowInteractor
class myVTKInteractor(wxVTKRenderWindowInteractor):
def __init__(self, parent):
wxVTKRenderWindowInteractor.__init__(self, parent, -1)
self.Enable(1)
self.AddObserver("ExitEvent", lambda o,e,f=self: f.Close())
self.ren = vtk.vtkRenderer()
self.GetRenderWindow().AddRenderer(self.ren)
# simple point coords used by both actors
coords = [(0.0, 0.0),
(1.0, 0.0),
(1.0, 1.0),
(0.0, 1.0)]
self.actorData = [(1.0, vtk.VTK_POLY_LINE, (0.5,0.0,0.0), (1.0, 0.0, 0.0)),
(0.0, vtk.VTK_QUAD, (0.0, 0.0, 0.5), (0.0, 0.0, 1.0))]
self.actorList = []
for data in self.actorData:
(zValue, cellType, dimColor, brightColor) = data
points = vtk.vtkPoints()
for (pointIndex, coord) in enumerate(coords):
points.InsertPoint(pointIndex, coord[0], coord[1], zValue)
idList = vtk.vtkIdList()
idList.SetNumberOfIds(len(coords))
for pointIndex in range(len(coords)):
idList.SetId(pointIndex, pointIndex)
cells = vtk.vtkCellArray()
cells.InsertNextCell(idList)
grid = vtk.vtkUnstructuredGrid()
grid.SetPoints(points)
grid.SetCells(cellType, cells)
mapper = vtk.vtkDataSetMapper()
mapper.SetInput(grid)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetRepresentation(1)
actor.GetProperty().SetLineWidth(5.0)
actor.GetProperty().SetDiffuseColor(*dimColor)
self.ren.AddActor(actor)
self.actorList.append(actor)
self.cellPicker = vtk.vtkCellPicker()
def OnMotion(self, event):
# invert Y value
actualY = self.ren.GetSize()[1] - event.GetY()
# dim all actors
for (index, actor) in enumerate(self.actorList):
(zValue, cellType, dimColor, brightColor) = self.actorData[index]
actor.GetProperty().SetDiffuseColor(*dimColor)
self.cellPicker.Pick(event.GetX(), actualY, 0, self.ren)
dataSet = self.cellPicker.GetDataSet()
if dataSet is not None:
# highlight picked actor
for (index, actor) in enumerate(self.actorList):
if actor.GetMapper().GetInput() == dataSet:
(zOffset, cellType, dimColor, brightColor) = self.actorData[index]
actor.GetProperty().SetDiffuseColor(*brightColor)
self.Render()
def wxVTKRenderWindowInteractorExample():
app = wx.PySimpleApp()
frame = wx.Frame(None, -1, "wxVTKRenderWindowInteractor", size=(400,400))
widget = myVTKInteractor(frame)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(widget, 1, wx.EXPAND)
frame.SetSizer(sizer)
frame.Layout()
frame.Show()
app.MainLoop()
if __name__ == "__main__":
wxVTKRenderWindowInteractorExample()
--
David A. Van Ee, BASc, EIT
Convergent Manufacturing Technologies Inc.
6190 Agronomy Rd, Suite 403
Vancouver BC Canada V6T 1Z3
Email: david.vanee at convergent.ca<mailto:david.vanee at convergent.ca> | Tel: 604-822-9682 x103
WWW: http://www.convergent.ca<http://www.convergent.ca/> | Fax: 604-822-9659
CONFIDENTIALITY NOTICE
This e-mail contains privileged and confidential information which is the property of Convergent, intended only for the use of the intended recipient(s).
Unauthorized use or disclosure of this information is prohibited. If you are not an intended recipient, please immediately notify Convergent and destroy any copies of this email. Receipt of this e-mail shall not be deemed a waiver by Convergent of any privilege or the confidential nature of the information.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20121211/6d183ad9/attachment.htm>
More information about the vtkusers
mailing list