simple picker

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

simple picker

Ben Axelrod
I am trying to implement a data picker that can select data points plotted with points3d().  Below is a simple script to demonstrate:

#simple picker
from enthought.mayavi import mlab
from enthought.tvtk.api import tvtk

def picker_callback(picker_obj, evt):
    print 'picker callback'
    print type(picker_obj)
    picker_obj = tvtk.to_tvtk(picker_obj)
    print type(picker_obj)
#end def

xs = (0, 1, 0, 1, 0, 1, 0, 1, 0.5)
ys = (0, 0, 1, 1, 0, 0, 1, 1, 0.5)
zs = (0, 0, 0, 0, 1, 1, 1, 1, 0.5)

data = mlab.points3d(xs, ys, zs)

mlab.gcf().scene.picker.pointpicker.add_observer('EndPickEvent', picker_callback)

mlab.show()
#end code

How can I get the index or coordinates of the actual data point in the picker_callback()?  If I print picker_obj and evt, I can see that they contain the coordinates of the point on the surface of the sphere.  But I would like to get the actual data point.

Also, if I print the type of picker_obj, I can see that it is:
<class 'tvtk_classes.point_picker.PointPicker'>

I cannot find documentation for this class anywhere.  I have searched all these pages:
http://code.enthought.com/projects/files/ETS32_API/
http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/
http://code.enthought.com/projects/files/ets_api/enthought.pyface.html
http://code.enthought.com/projects/traits/docs/html/TUIUG/index.html

However, I see that there is a vtkPointPicker class with a GetPointId() member.  But unfortunately, when I try to call that member, I get an attribute not found error.

Thanks,
-Ben
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: simple picker

Gael Varoquaux
Hey Ben,

On Thu, Feb 04, 2010 at 01:12:41PM -0800, Ben Axelrod wrote:
> I am trying to implement a data picker that can select data points plotted with points3d().  Below is a simple script to demonstrate:

> #simple picker
> from enthought.mayavi import mlab
> from enthought.tvtk.api import tvtk

> def picker_callback(picker_obj, evt):
>     print 'picker callback'
>     print type(picker_obj)
>     picker_obj = tvtk.to_tvtk(picker_obj)
>     print type(picker_obj)
> #end def

> xs = (0, 1, 0, 1, 0, 1, 0, 1, 0.5)
> ys = (0, 0, 1, 1, 0, 0, 1, 1, 0.5)
> zs = (0, 0, 0, 0, 1, 1, 1, 1, 0.5)

> data = mlab.points3d(xs, ys, zs)

> mlab.gcf().scene.picker.pointpicker.add_observer('EndPickEvent', picker_callback)

> mlab.show()
> #end code

> How can I get the index or coordinates of the actual data point in the picker_callback()?  If I print picker_obj and evt, I can see that they contain the coordinates of the point on the surface of the sphere.  But I would like to get the actual data point.

You've already made quite a lot of progress. This part of Mayavi/tvtk is
not well documented. I have started work on that, but it has lead me to
implement an abstraction layer, to fix the fact that different versions
of VTK were inconsistent.

Any how, I believe that the following example script might help you:
https://svn.enthought.com/enthought/browser/Mayavi/trunk/examples/mayavi/data_interaction/select_red_balls.py
Chance are that it won't work with the released version of Mayavi (and
that's why its not in the docs), but I do hope you should find the
answer to your question. If not, simply ask here.

> Also, if I print the type of picker_obj, I can see that it is:
> <class 'tvtk_classes.point_picker.PointPicker'>



> I cannot find documentation for this class anywhere.  I have searched all these pages:
> http://code.enthought.com/projects/files/ETS32_API/
> http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/
> http://code.enthought.com/projects/files/ets_api/enthought.pyface.html
> http://code.enthought.com/projects/traits/docs/html/TUIUG/index.html

I don't believe that there is an API documentation for TVTK. Basicaly,
TVTK is a simple mapping of VTK, so, once you understand the
relationships a bit better, the VTK documentation helps. If you have a
somewhat recent version of Mayavi, you can use the 'tvtk_docs' script to
dig in this documentation. Now you are left with the fact that the VTK
documentation is terribly poor, IMHO. I resort to a lot of googling, and
quite often I don't understand everything.

> However, I see that there is a vtkPointPicker class with a GetPointId()
> member.  But unfortunately, when I try to call that member, I get an
> attribute not found error.

Most often, if you have a VTK object with a 'GetFooBar' method, the
corresponding TVTK object will have a 'foo_bar' attribute, that you can
get or set, and that should work. Now in you case, you are getting a raw
VTK object, and not the TVTK object. You can easily wrap it in a TVTK
object using:

    from enthought.tvtk.api import tvtk
    tvtk_obj = tvtk.to_tvtk(vtk_obj)

In the example I put you to above, the 'on_mouse_pick' framework do that
for you. But it exists only in the SVN version of Mayavi. In that
example, the 'picker' object is simply the VTK picker object that has
been converted to a TVTK picker object.

HTH,

Gaƫl
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev