[vtkusers] ​SetClientData in python (David Gobbi)

Andrew Maclean andrew.amaclean at gmail.com
Sat Nov 11 20:06:36 EST 2017


We should be able to do this.

Andrew Maclean

On 12 Nov 2017 10:32, "Bill Lorensen" <bill.lorensen at gmail.com> wrote:

> Andrew,
>
> I do want to make the examples available to at least 6.0 users. We can
> add c++ 11 stuff if we can exclude those examples based on VTK
> versions.
>
> Bill
>
>
> On Sat, Nov 11, 2017 at 6:07 PM, Andrew Maclean
> <andrew.amaclean at gmail.com> wrote:
> > I'll do an example for this.
> >
> > I'm also thinking that since we are using C++11 we should be able to use
> > lambda expressions. I'll also do an example for that.
> >
> > Regards
> >    Andrew
> >
> >
> > On Sun, Nov 12, 2017 at 8:59 AM, Andrew Maclean <
> andrew.amaclean at gmail.com>
> > wrote:
> >>
> >> David,
> >>
> >> When I try this I get:
> >> TypeError: DummyFunc() missing 1 required positional argument: 'data'
> >>
> >> I used a slightly different approach in
> >> https://lorensen.github.io/VTKExamples/site/Python/
> VisualizationAlgorithms/StreamlinesWithLineWidget/
> >>
> >> Regards
> >>    Andrew
> >>
> >>    2. Re:
> >> SetClientData in python (David Gobbi)
> >>>
> >>> ---------- Forwarded message ----------
> >>> From: David Gobbi <david.gobbi at gmail.com>
> >>> To:
> >>>  "Serge K." <skab12 at gmail.com>
> >>> Cc: VTK Users <vtkusers at vtk.org>
> >>> Bcc:
> >>> Date: Fri, 10 Nov 2017 11:17:26 -0700
> >>> Subject: Re: [vtkusers] SetClientData in python
> >>> Hi Serge,
> >>>
> >>> The way to do this in Python is to add attributes to your callback
> >>> function.
> >>>
> >>>     def DummyFunc(obj, ev, data):
> >>>         print(ev, data)
> >>>
> >>>
> >>> DummyFunc.CallData = whatever
> >>>
> >>>     interactor.AddObserver('LeftButtonPressEvent', DummyFunc)
> >>>
> >>> So the vtkCallbackCommand really isn't needed in Python (and, as you
> have
> >>> noticed, it really can't be used in Python anyway).
> >>>
> >>>  - David
> >>>
> >>>
> >>>
> >>> On Fri, Nov 10, 2017 at 10:32 AM, Serge K. <skab12 at gmail.com> wrote:
> >>>>
> >>>> Hi All,
> >>>>
> >>>> I am playing with MouseEventObserver.py example and I would like to
> add
> >>>> a ClientData on my callback function. There are many examples in C++
> like
> >>>> this one: https://www.vtk.org/Wiki/VTK/Examples/Cxx/Interaction/
> ClientData
> >>>>
> >>>> However, I do not know how to do that in Python.
> >>>>
> >>>> Indeed, if I create a  vtkCallbackCommand , SetCallBack function does
> >>>> not exist.
> >>>>
> >>>> Any Idea? Thanks for your answer.
> >>>>
> >>>> Serge
> >>>>
> >>>> ps: python36 - vtk 7.1.1
> >>>>
> >>>>
> >>>> #!/usr/bin/env python
> >>>> from __future__ import print_function
> >>>>
> >>>> 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.vtkInteractorStyleTrackballCam
> era())
> >>>> interactor.SetRenderWindow(renwin)
> >>>>
> >>>> def DummyFunc(obj, ev, my_obj_2):
> >>>>     print(obj, my_obj_2)
> >>>>
> >>>> # obj_2 = vtk.whatever()
> >>>> # How do I pass my obj_2 ?
> >>>> interactor.AddObserver('LeftButtonPressEvent', DummyFunc)
> >>>> interactor.Initialize()
> >>>> interactor.Start()
> >>>
> >>>
> >>>
> >>
> >> --
> >> ___________________________________________
> >> Andrew J. P. Maclean
> >>
> >> ___________________________________________
> >
> >
> >
> >
> > --
> > ___________________________________________
> > Andrew J. P. Maclean
> >
> > ___________________________________________
> >
> > _______________________________________________
> > 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
> >
> > Search the list archives at: http://markmail.org/search/?q=vtkusers
> >
> > Follow this link to subscribe/unsubscribe:
> > http://public.kitware.com/mailman/listinfo/vtkusers
> >
>
>
>
> --
> Unpaid intern in BillsBasement at noware dot com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20171112/d66a4a04/attachment.html>


More information about the vtkusers mailing list