Scalar Inputs and Point Picking

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

Scalar Inputs and Point Picking

Chiping Yeh
Hello,
    I am still somewhat new to Mayavi, so please forgive me for asking a seemingly simple question. For the pipeline sources, there is usually a 'scalar' option, which the documentation simply says is for scalar data. Specifically, for the grid_source data type, I have the x,y,z coordinates in 2D arrays as specified, and have a specific scalar value for each point. As each sub-array in the coordinate arrays represent a set of connected points, I thought of representing the scalars in such a way too, i.e. [[pt1scalar, pt2scalar, pt3scalar], [...], ...] but when I try to access the mlab_source.scalars[point_picker.getPointId()] from a point being picked, it returns 3 values instead of 1 - yet the automatic popup gui for point picking returns 1 scalar, as desired. Is my scalar input incorrect, or my method of accessing the scalars? 

This ties in to my next question, which concerns point picking; I am using a mlab scene embedded in a Traits ui, and have a simple snippet:
    @on_trait_change('scene.activated')
    def update_plot(self):
          ...
          self.scene.picker.pointpicker.add_observer("PickEvent", self.printPickEvent)
    def printPickEvent(self, obj, event):
           print "event triggered"

but this event only triggers the first time I pick the plot (i.e. press 'p'). Is the default GUI overriding the event? How do I disable this GUI, but still get the data it normally extracts? Thank you.

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

Re: Scalar Inputs and Point Picking

Gael Varoquaux
On Thu, Jul 18, 2013 at 10:57:04PM -0400, Chiping Yeh wrote:
> For the pipeline sources, there is usually a 'scalar' option, which the
> documentation simply says is for scalar data. Specifically, for the
> grid_source data type, I have the x,y,z coordinates in 2D arrays as
> specified, and have a specific scalar value for each point. As each
> sub-array in the coordinate arrays represent a set of connected points,
> I thought of representing the scalars in such a way too, i.e.
> [[pt1scalar, pt2scalar, pt3scalar], [...], ...] but when I try to
> access the mlab_source.scalars[point_picker.getPointId()] from a point
> being picked, it returns 3 values instead of 1

As I don't know the exact code that you are using, I am doing some
guessing work, but I believe that your problem is that you are giving an
array of the wrong shape as a 'scalars' argument. This argument should
always have the same shape as the x, y, z arrays.

> This ties in to my next question, which concerns point picking; I am using a
> mlab scene embedded in a Traits ui, and have a simple snippet:
>     @on_trait_change('scene.activated')
>     def update_plot(self):
>           ...
>           self.scene.picker.pointpicker.add_observer("PickEvent",
> self.printPickEvent)
>     def printPickEvent(self, obj, event):
>            print "event triggered"

> but this event only triggers the first time I pick the plot (i.e. press 'p').
> Is the default GUI overriding the event? How do I disable this GUI, but still
> get the data it normally extracts? Thank you.

The GUI should not override the callback. To disable it, there is an
attribute on it, 'show_ui' from memory, that you can set to 'False'.

I quickly tried to wire a callback as you are doing, but could not
reproduce your problem:

In [15]: f = mlab.gcf()

In [16]: def print_pick(obj, event):
   ....:     print event
   ....:    

In [17]: f.scene.picker.pointpicker.add_observer('PickEvent', print_pick)
Out[17]: 2

In [18]: PickEvent
PickEvent
PickEvent
PickEvent

HTH,

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