[vtkusers] vtkInteractorStyleUser

Jothy jothybasu at gmail.com
Wed Sep 15 05:17:36 EDT 2010


Hi David,

Here is an axample form the vtk\Examples dir on how to use "Observers".

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()


Jothy


On Tue, Sep 14, 2010 at 10:05 PM, David Doria
<daviddoria+vtk at gmail.com<daviddoria%2Bvtk at gmail.com>
> wrote:

> On Tue, Sep 14, 2010 at 4:56 PM, Jim Peterson <jimcp at cox.net> wrote:
>
>> Adding to this context,
>>
>> 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.
>>
>> Jim
>>
>
> 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 :
>
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Interaction/InteractorStyleUser
>
> <http://www.vtk.org/Wiki/VTK/Examples/Cxx/Interaction/InteractorStyleUser>Would
> someone be so kind as to post an example of how to use observers (or
> otherwise handle interaction) in Python?
>
> Thanks,
>
> David
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK 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/20100915/2083a81e/attachment.htm>


More information about the vtkusers mailing list