[vtkusers] custom renderwindowinteractorstyle
Florian Bruckner
e0425375 at gmail.com
Thu Sep 1 19:05:46 EDT 2011
perhaps the problem comes from the vtk python wrapper
(http://www.vtk.org/Wiki/VTK/Python_Wrapping_FAQ).
the solution that currently looks best for me, is to add an observer
directly to the vtkInteractor(). By means of priorities on can choose
if the new vtkCommand should be executed before or after the original
callback. Using RemoveObservers(event) allows to remove the default
action at all.
a short example of this method follows:
import vtk
source = vtk.vtkSphereSource()
source.SetCenter(0,0,0)
source.SetRadius(1)
source.Update()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(source.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
renderer = vtk.vtkRenderer()
renderer.SetBackground(1,1,1)
renderer.AddActor(actor)
renwin = vtk.vtkRenderWindow()
renwin.AddRenderer(renderer)
interactor = vtk.vtkRenderWindowInteractor()
interactor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
interactor.SetRenderWindow(renwin)
def DummyFunc1(obj, ev):
print "Before Event"
def DummyFunc2(obj, ev):
print "After Event"
## Print interator gives you a list of registered observers of the
current interactor style
print interactor
## adding priorities allow to control the order of observer execution
## (highest value first! if equal the first added observer is called first)
#interactor.RemoveObservers('LeftButtonPressEvent')
interactor.AddObserver('LeftButtonPressEvent', DummyFunc1, 1.0)
interactor.AddObserver('LeftButtonPressEvent', DummyFunc2, -1.0)
interactor.Initialize()
interactor.Start()
bye
FloB
On Thu, Sep 1, 2011 at 5:19 PM, David Doria <daviddoria at gmail.com> wrote:
> On Thu, Sep 1, 2011 at 11:16 AM, Florian Bruckner <e0425375 at gmail.com> wrote:
>> ok, sounds easy, but i didn't get it running with python.
>>
>> i tryied the following, but the new function is never called:
>> class InteractorStyleNew(vtk.vtkInteractorStyleTrackballCamera):
>> def OnLeftButtonUp(self):
>> print "Middle Button Pressed"
>>
>> seaching the net i found some other solutions:
>> 1.) http://vtk.org/gitweb?p=VTK.git;a=blob;f=Examples/GUI/Python/CustomInteraction.py
>> 2.) http://code.google.com/p/vtkpythonext/source/browse/trunk/spare/src/jolly/jolly_vtk2/vtkPythonInteractorStyle.py?r=35
>>
>> but they are not as beautiful as the method used in the c++ example.
>>
>>
>> is there an obvious error in my example, which i cannot see, or is
>> there a problem with the python support?
>>
>> greetings
>> Florian
>
> It would be great if you could add an example of this here:
> http://www.vtk.org/Wiki/VTK/Examples/Python
>
> once you get it working.
>
> David
>
More information about the vtkusers
mailing list