[vtkusers] pb with text annotation of picking

Geoframer geoframer at gmail.com
Wed Sep 5 04:27:09 EDT 2007


Hi Jean-Pierre,

I've checked and your example is identical to my CVS-checkout of VTK.
Additionally when i copy/paste your code in a file, and run it in python,
the example works. I assume you understand that the picking occurs when
pressing the 'p'-button after navigating your mouse to the point you want to
pick and not the mouse button. If not...  that's your solution! :-).
Otherwise we need more clues (error messages perhaps?) on what's going on.

Regards - Geoframer

On 9/3/07, jb116896 <jean-pierre.both at cea.fr> wrote:
>
> Hello everybody,
>
> having problem to get a text annotation of a picking
> I checked the example in Examples/Annotation/Python downloaded with my
> 5.0.3 version of Vtk
> and it doesn not work. I get no display of text
>
> here is the script :
>
> ========================================================
>
> !/usr/bin/env python
>
> # This example demonstrates cell picking using vtkCellPicker.  It
> # displays the results of picking using a vtkTextMapper.
>
> import vtk
>
> # create a sphere source, mapper, and actor
> sphere = vtk.vtkSphereSource()
> sphereMapper = vtk.vtkPolyDataMapper()
> sphereMapper.SetInputConnection(sphere.GetOutputPort())
> sphereMapper.GlobalImmediateModeRenderingOn()
> sphereActor = vtk.vtkLODActor()
> sphereActor.SetMapper(sphereMapper)
>
> # create the spikes by glyphing the sphere with a cone.  Create the
> # mapper and actor for the glyphs.
> cone = vtk.vtkConeSource()
> glyph = vtk.vtkGlyph3D()
> glyph.SetInputConnection(sphere.GetOutputPort())
> glyph.SetSource(cone.GetOutput())
> glyph.SetVectorModeToUseNormal()
> glyph.SetScaleModeToScaleByVector()
> glyph.SetScaleFactor(0.25)
> spikeMapper = vtk.vtkPolyDataMapper()
> spikeMapper.SetInputConnection(glyph.GetOutputPort())
> spikeActor = vtk.vtkLODActor()
> spikeActor.SetMapper(spikeMapper)
>
> # Create a text mapper and actor to display the results of picking.
> textMapper = vtk.vtkTextMapper()
> tprop = textMapper.GetTextProperty()
> tprop.SetFontFamilyToArial()
> tprop.SetFontSize(10)
> tprop.BoldOn()
> tprop.ShadowOn()
> tprop.SetColor(1, 0, 0)
> textActor = vtk.vtkActor2D()
> textActor.VisibilityOff()
> textActor.SetMapper(textMapper)
>
> # Create a cell picker.
> picker = vtk.vtkCellPicker()
>
> # Create a Python function to create the text for the text mapper used
> # to display the results of picking.
> def annotatePick(object, event):
>     global picker, textActor, textMapper
>     if picker.GetCellId() < 0:
>         textActor.VisibilityOff()
>     else:
>         selPt = picker.GetSelectionPoint()
>         pickPos = picker.GetPickPosition()
>         textMapper.SetInput("(%.6f, %.6f, %.6f)"%pickPos)
>         textActor.SetPosition(selPt[:2])
>         textActor.VisibilityOn()
>
> # Now at the end of the pick event call the above function.
> picker.AddObserver("EndPickEvent", annotatePick)
>
> # Create the Renderer, RenderWindow, etc. and set the Picker.
> ren = vtk.vtkRenderer()
> renWin = vtk.vtkRenderWindow()
> renWin.AddRenderer(ren)
> iren = vtk.vtkRenderWindowInteractor()
> iren.SetRenderWindow(renWin)
> iren.SetPicker(picker)
>
> # Add the actors to the renderer, set the background and size
> ren.AddActor2D(textActor)
> ren.AddActor(sphereActor)
> ren.AddActor(spikeActor)
> ren.SetBackground(1, 1, 1)
> renWin.SetSize(300, 300)
>
> # Get the camera and zoom in closer to the image.
> ren.ResetCamera()
> cam1 = ren.GetActiveCamera()
> cam1.Zoom(1.4)
>
> iren.Initialize()
> # Initially pick the cell at this location.
> picker.Pick(85, 126, 0, ren)
> renWin.Render()
> iren.Start()
>
> ===============================================================
>
>
> Any solution to this problem ?
>
> Thanks a lot
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070905/3eb14f46/attachment.htm>


More information about the vtkusers mailing list