Hello all,<br><br>I'm trying two things which I cannot seem to get to work. I would appreciate any pointers or helpful advice you can give.<br><br><br>Problem 1. : I've created a lookuptable which I want to use to map glyphs created at certain points to certain colors. In the sample code below i've created 8 points which i try to map to two colors, the first four points to one color and the second four points to a different color. From what i've been able to figure out I'm supposed to give the lookuptable to the mapper... My visualisation however shows no colors whatever but gives no errors either. Any clarification how to properly use a lookuptable combined with pointids would be greatly appreciated.
<br><br><br>Problem 2. : I'm currently using a programmable glyph filter to map the glyphs to the points. I also defined a picker on the glyphs so I'm able to pick the glyphs in the visualisation. Currently however whenever I pick a glyph I get a high point-id instead of 0 to 7 (for the points i'm using). I understand why this happens, but I can't seem to be able to circumvent this or create a proper workaround. I read the following post :
<br> <a href="http://public.kitware.com/pipermail/vtkusers/2001-April/055637.html" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://public.kitware.com/pipermail/vtkusers/2001-April/055637.html
</a><br>but that only seems to work if you don't alter the sources... which is something I might want to do later. Basically what I want is to be able to retrieve the pointId which is used to create the glyph. Again any help would be greatly appreciated.
<br><br>Regards - Geofram<br><br>The sample code :<br><br><span style="color: rgb(0, 0, 153);">import vtk</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">import random</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">from vtk.util.colors import *</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">#create some arbitrary vectordata identified by a string
</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">points = vtk.vtkPoints()</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">data = {'avector':(0,0,0), 'bvector':(0,0,1),'cvector':(0,1,0),'dvector':(1,0,0),
</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"> 'evector':(1,1,0), 'fvector':(1,0,1),'gvector':(0,1,1),'hvector':(1,1,1)}</span><br style="color: rgb(0, 0, 153);">
<br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">keys = data.keys()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">keys.sort()</span><br style="color: rgb(0, 0, 153);">
<br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">for i, key in enumerate(keys):</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"> vector = data.get(key)</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);"> points.InsertPoint(i, vector[0], vector[1], vector[2])</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">graph = vtk.vtkGraph
()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">graph.SetPoints(points)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">graph.SetNumberOfVertices(len(data))</span>
<br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">[graph.AddEdge(0,i+1) for i in range(len(data)-1)]</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">
</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">graphtopoly = vtk.vtkGraphToPolyData()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">graphtopoly.SetInput
(graph)</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">#create the tube, mapper and actor for the edges</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">
tubes = vtk.vtkTubeFilter()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">tubes.SetInputConnection(graphtopoly.GetOutputPort())</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">
tubes.SetRadius(0.002)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">tubes.SetNumberOfSides(3)</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">
mapEdges = vtk.vtkPolyDataMapper()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">mapEdges.SetInputConnection(tubes.GetOutputPort())</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">edgeActor = vtk.vtkActor()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">edgeActor.SetMapper(mapEdges)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">
edgeActor.GetProperty().SetColor(peacock)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">edgeActor.GetProperty().SetSpecularColor(1, 1, 1)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">
edgeActor.GetProperty().SetSpecular(0.3)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">edgeActor.GetProperty().SetSpecularPower(20)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">
edgeActor.GetProperty().SetAmbient(0.2)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">edgeActor.GetProperty().SetDiffuse(0.8)</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">#create the lookuptable for colors, ball, programmable glyph and glyphactor</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">lut = vtk.vtkLookupTable()</span>
<br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">lut.SetNumberOfColors(2)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">lut.SetNumberOfTableValues(8)</span><br style="color: rgb(0, 0, 153);">
<br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">lut.SetTableValue(0, 1.0, 1.0, 1.0, 1.0)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">lut.SetTableValue(1, 1.0, 1.0
,
1.0, 1.0)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">lut.SetTableValue(2, 1.0, 1.0, 1.0, 1.0)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">lut.SetTableValue
(3, 1.0, 1.0, 1.0, 1.0)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">lut.SetTableValue(4, 0.5, 0.5, 0.5, 1.0)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">
lut.SetTableValue(5, 0.5, 0.5, 0.5, 1.0)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">lut.SetTableValue(6, 0.5, 0.5, 0.5, 1.0)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">
lut.SetTableValue(7, 0.5, 0.5, 0.5, 1.0)</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">def Glyph():</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">
ptId = glypher.GetPointId()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"> #print ptId</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"> pd = glypher.GetPointData
()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"> xyz = glypher.GetPoint()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"> x = xyz[0]</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);"> y = xyz[1]</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"> z = xyz[2]</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">
ball.SetCenter(xyz)</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">ball = vtk.vtkSphereSource()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">
ball.SetRadius(0.010)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">ball.SetThetaResolution(12)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">ball.SetPhiResolution
(12)</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">glypher = vtk.vtkProgrammableGlyphFilter()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">
glypher.SetInputConnection(graphtopoly.GetOutputPort())</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">glypher.SetSource(ball.GetOutput())</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">
glypher.SetGlyphMethod(Glyph)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">glyphMapper = vtk.vtkPolyDataMapper()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">
glyphMapper.SetInputConnection(glypher.GetOutputPort())</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">glyphMapper.SetLookupTable(lut)</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">glyphActor = vtk.vtkActor()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">glyphActor.SetMapper(glyphMapper)</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">#create a text mapper and actor</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">textMapper = vtk.vtkTextMapper()</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">textProp = textMapper.GetTextProperty()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">textProp.SetFontSize(20)</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">textProp.SetColor(1,0,0)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">textActor = vtk.vtkActor2D()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">
textActor.VisibilityOff()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">textActor.SetMapper(textMapper)</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">
#create a point picker.</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">picker = vtk.vtkPointPicker()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">picker.AddPickList
(glyphActor)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">picker.PickFromListOn()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">picker.SetTolerance(0.001)</span>
<br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">def pointCoords(object, event):</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"> global picker, textActor, textMapper
</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"> if picker.GetPointId() < 0:</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"> textActor.VisibilityOff
()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"> else:</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"> selPt = picker.GetSelectionPoint()</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);"> pickPos = picker.GetPickPosition()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"> print picker.GetPointId()</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);"> textMapper.SetInput("(%.6f, %.6f, %.6f)"%pickPos)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"> textActor.SetPosition(selPt[:2])
</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"> textActor.VisibilityOn()</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">
# at the end of pick call pointcoords</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">picker.AddObserver("EndPickEvent", pointCoords)</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);"># create the renderwindow, interactor</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">ren = vtk.vtkRenderer()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">
renWin = vtk.vtkRenderWindow()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">renWin.AddRenderer(ren)</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">
interact = vtk.vtkRenderWindowInteractor()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">interact.SetRenderWindow(renWin)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">
interact.SetPicker(picker)</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">ren.AddActor2D(textActor)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">
ren.AddActor(edgeActor)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">ren.AddActor(glyphActor)</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">
renWin.GetInteractor().Initialize()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">renWin.Render()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">renWin.GetInteractor
().Start()</span><br style="color: rgb(51, 102, 255);">