<div dir="ltr">Hi David,<br><br>Here is an axample form the vtk\Examples dir on how to use "Observers".<br><br><span style="color: rgb(0, 0, 153);">import vtk</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);"># create a sphere source, mapper, and actor</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">sphere = vtk.vtkSphereSource()</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">sphereMapper = vtk.vtkPolyDataMapper()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">sphereMapper.SetInputConnection(sphere.GetOutputPort())</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">sphereMapper.GlobalImmediateModeRenderingOn()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">sphereActor = vtk.vtkLODActor()</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">sphereActor.SetMapper(sphereMapper)</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"># create the spikes by glyphing the sphere with a cone. Create the</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);"># mapper and actor for the glyphs.</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">cone = vtk.vtkConeSource()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">glyph = vtk.vtkGlyph3D()</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">glyph.SetInputConnection(sphere.GetOutputPort())</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">glyph.SetSource(cone.GetOutput())</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">glyph.SetVectorModeToUseNormal()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">glyph.SetScaleModeToScaleByVector()</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">glyph.SetScaleFactor(0.25)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">spikeMapper = vtk.vtkPolyDataMapper()</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">spikeMapper.SetInputConnection(glyph.GetOutputPort())</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">spikeActor = vtk.vtkLODActor()</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">spikeActor.SetMapper(spikeMapper)</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 to display the results of picking.</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);">tprop = textMapper.GetTextProperty()</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">tprop.SetFontFamilyToArial()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">tprop.SetFontSize(10)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">tprop.BoldOn()</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">tprop.ShadowOn()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">tprop.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 cell picker.</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">picker = vtk.vtkCellPicker()</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);"># Create a Python function to create the text for the text mapper used</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"># to display the results of picking.</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">def annotatePick(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.GetCellId() < 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);"> 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);"><span style="color: rgb(0, 0, 153);"> </span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"># Now at the end of the pick event call the above function.</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">picker.AddObserver("EndPickEvent", annotatePick)</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"># Create the Renderer, RenderWindow, etc. and set the Picker.</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);">
<span style="color: rgb(0, 0, 153);">iren = vtk.vtkRenderWindowInteractor()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">iren.SetRenderWindow(renWin)</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">iren.SetPicker(picker)</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"># Add the actors to the renderer, set the background and size</span><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(sphereActor)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">ren.AddActor(spikeActor)</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">ren.SetBackground(1, 1, 1)</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">renWin.SetSize(300, 300)</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);"># Get the camera and zoom in closer to the image.</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">ren.ResetCamera()</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">cam1 = ren.GetActiveCamera()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">cam1.Zoom(1.4)</span><br style="color: rgb(0, 0, 153);"><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">iren.Initialize()</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"># Initially pick the cell at this location.</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">picker.Pick(85, 126, 0, ren)</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);">iren.Start()</span><br><br><br>Jothy<br style="color: rgb(0, 0, 153);"><br><br><div class="gmail_quote">
On Tue, Sep 14, 2010 at 10:05 PM, David Doria <span dir="ltr"><<a href="mailto:daviddoria%2Bvtk@gmail.com">daviddoria+vtk@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im"><div><div class="gmail_quote">On Tue, Sep 14, 2010 at 4:56 PM, Jim Peterson <span dir="ltr"><<a href="mailto:jimcp@cox.net" target="_blank">jimcp@cox.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Adding to this context,<br>
<br>
It might be the value of this vtkInteractorStyleUser class is deprecated with the use of the Observer's, I am not really up to speed on the why's and what's of the Observer style of interaction specification to this point, only the how. and a MiddleButtonPressMethod would be an observer event fired by the IneractionWindow callback to an observer function set of the MiddlePuttonPressEvent.<br>
<font color="#888888">
<br>
Jim</font><div><div></div><div></div></div></blockquote></div><br></div></div><div>Thanks Jim. So in summary vtkInteractorStyleUser is old and it is no different than any other vtkInteractorStyle* . To use it, one should just use observers like this :<div class="im">
<div>
<br></div><div><a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Interaction/InteractorStyleUser" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Cxx/Interaction/InteractorStyleUser</a></div><div><br></div></div><div>
<a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Interaction/InteractorStyleUser" target="_blank"></a>Would someone be so kind as to post an example of how to use observers (or otherwise handle interaction) in Python?</div>
<div><br clear="all">Thanks,<br><font color="#888888"><br>David</font></div></div>
<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br></div>