Re: Changing mouse behavior in VisAD

<html>
Hi Tolga,<br>
<br>
Sorry for the confusion, I forgot that visad.bio is not part of the
regular<br>
VisAD distribution (it is something I am working on, but we are not<br>
yet including it in visad_src-2.0.jar).<br>
<br>
So, I've included the relevant code below.<br>
<br>
-Curtis<br>
<br>
------------------------<br>
<br>
&nbsp; /** Listens for left mouse clicks in the display. */<br>
&nbsp; public void displayChanged(DisplayEvent e) {<br>
&nbsp;&nbsp;&nbsp; int id = e.getId();<br>
&nbsp;&nbsp;&nbsp; int x = e.getX();<br>
&nbsp;&nbsp;&nbsp; int y = e.getY();<br>
&nbsp;&nbsp;&nbsp; if (id == DisplayEvent.MOUSE_RELEASED_LEFT) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // get domain coordinates of mouse
click<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double[] coords
cursorToDomain(pixelToCursor(x, y));<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // deal with coordinates accordingly<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp; }<br>
<br>
&nbsp; /** Converts the given pixel coordinates to cursor coordinates.
*/<br>
&nbsp; private double[] pixelToCursor(int x, int y) {<br>
&nbsp;&nbsp;&nbsp; MouseBehavior mb
display.getDisplayRenderer().getMouseBehavior();<br>
&nbsp;&nbsp;&nbsp; VisADRay ray = mb.findRay(x, y);<br>
&nbsp;&nbsp;&nbsp; return new double[] {ray.position[0],
ray.position[1]};<br>
&nbsp; }<br>
<br>
&nbsp; /** Converts the given cursor coordinates to domain coordinates.
*/<br>
&nbsp; private double[] cursorToDomain(double[] cursor) {<br>
&nbsp;&nbsp;&nbsp; // locate x and y mappings<br>
&nbsp;&nbsp;&nbsp; Vector maps = display.getMapVector(); // display is a
DisplayImpl<br>
&nbsp;&nbsp;&nbsp; int numMaps = maps.size();<br>
&nbsp;&nbsp;&nbsp; ScalarMap map_x = null, map_y = null;<br>
&nbsp;&nbsp;&nbsp; for (int i=0; i&lt;numMaps &amp;&amp; (map_x == null
|| map_y == null); i++) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // for 3-D, you'd want to search for map_z
in this loop as well<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ScalarMap map = (ScalarMap)
maps.elementAt(i);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if
(map.getDisplayScalar().equals(Display.XAxis)) map_x = map;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if
(map.getDisplayScalar().equals(Display.YAxis)) map_y = map;<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; if (map_x == null || map_y == null) return null;<br>
<br>
&nbsp;&nbsp;&nbsp; // adjust for scale<br>
&nbsp;&nbsp;&nbsp; double[] scale_offset = new double[2];<br>
&nbsp;&nbsp;&nbsp; double[] dummy = new double[2];<br>
&nbsp;&nbsp;&nbsp; double[] values = new double[2];<br>
&nbsp;&nbsp;&nbsp; map_x.getScale(scale_offset, dummy, dummy);<br>
&nbsp;&nbsp;&nbsp; values[0] = (cursor[0] - scale_offset[1]) /
scale_offset[0];<br>
&nbsp;&nbsp;&nbsp; map_y.getScale(scale_offset, dummy, dummy);<br>
&nbsp;&nbsp;&nbsp; values[1] = (cursor[1] - scale_offset[1]) /
scale_offset[0];<br>
&nbsp;&nbsp;&nbsp; // hopefully the conversion will be straightforward in
3-D<br>
<br>
&nbsp;&nbsp;&nbsp; return values;<br>
&nbsp; }<br>
<br>
------------------------<br>
<br>
At 10:05 PM 6/28/01 -0700, you wrote: <br>
<font size=2 color="#000080"><blockquote type=cite cite>Hi Curtis. Thanks
for yoour reply. However, i do not seem to have visad.bio.PoolLine . I do
not have a bio folder under my visad. I had downloaded visad_src-2.0.jar
recently and it looks like it has not changed since. Can you send me this
file. Also, is this part of the regular download? I wonder how come I
don't have it.</font><br>
&nbsp;<br>
<font size=2 color="#000080">Cheers.</font><br>
<br>
&lt; &lt; &lt;&nbsp; t o l g a : | | : s a k m a n&nbsp; &gt; &gt;
&gt;<br>
engineer, cfd consultant<br>
analytic &amp; computational research, inc -- acri<br>
los angeles, ca<br>
310-471-3023<br>
<a href="mailto:tolga.sakman@xxxxxxxxxxx";>tolga.sakman@xxxxxxxxxxx</a> ||
<a href="http://www.acricfd.com/"; 
eudora="autourl">www.acricfd.com</a><blockquote>
<dl>
<dd>----- Original Message ----- 
<dd>From: <a href="mailto:curtis@xxxxxxxxxxxxx";>Curtis Rueden</a> 
<dd>To: <a href="mailto:tsakman@xxxxxxxxxxx";>Tolga Sakman</a> 
<dd>Cc:
<a href="mailto:visad-list@xxxxxxxxxxxxx";>visad-list@xxxxxxxxxxxxx</a> 
<dd>Sent: Thursday, June 28, 2001 12:47 PM 
<dd>Subject: Re: Changing mouse behavior in VisAD<br>
<br>
<font size=2 color="#000080">
<dd>Hi Tolga,<blockquote type=cite cite>
<dd>where I add the DisplayListener at the first display. Now when I do
the LEFT+RIGHT mouse buttons pressed (it says CENTER but my middle mouse
button does not do this, don't know why) I get xval and yval and
everything is working fine. 
<dd>Now when I change this to e.getId() =
DisplayEvent.MOUSE_PRESSED_RIGHT, I get NaN for xval and yval.
Interestingly, RIGHT+LEFT still is caught (although I do not catch it)
and y and x values are shown on the left top corner, updating constantly,
as long as I hold RIGHT+LEFT. Now this is what I mean by unexpected
behavior. I want to be able to control that constant display, so that I
can do it with MOUSE_MOVED event.</font> 
</dl></blockquote><br>
The getDirectAxisValue() method is probably not what you want here (it
appears to be<br>
dependent on RIGHT+LEFT clicks).&nbsp; Instead, take a look at the
displayChanged() method<br>
of visad.bio.LinePool.&nbsp; It obtains the 2-D coordinates of a mouse
click upon LEFT mouse<br>
button release.&nbsp; It is a bit complicated but you should be able to
copy and adapt most<br>
of the code from LinePool to suit your purposes.&nbsp; The key line
is:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; double[] coords
cursorToDomain(pixelToCursor(x, y));<br>
<br>
Along with the corresponding cursorToDomain() and pixelToCursor()
methods.<br>
<br>
Unfortunately, VisAD does not currently have a DisplayEvent.MOUSE_MOVED
event,<br>
so it is difficult to continuously track values as the mouse moves.&nbsp;
Perhaps you could do<br>
it with a MouseMotionListener (I haven't tried it), but I have a feeling
Java3D would interfere<br>
with that and eat the events.<br>
<br>
-Curtis<br>
<br>
</blockquote></html>


  • 2001 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: