NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.
To learn about what's going on, see About the Archive Site.
<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> /** Listens for left mouse clicks in the display. */<br> public void displayChanged(DisplayEvent e) {<br> int id = e.getId();<br> int x = e.getX();<br> int y = e.getY();<br> if (id == DisplayEvent.MOUSE_RELEASED_LEFT) {<br> // get domain coordinates of mouse click<br> double[] coords cursorToDomain(pixelToCursor(x, y));<br> <br> // deal with coordinates accordingly<br> }<br> }<br> <br> /** Converts the given pixel coordinates to cursor coordinates. */<br> private double[] pixelToCursor(int x, int y) {<br> MouseBehavior mb display.getDisplayRenderer().getMouseBehavior();<br> VisADRay ray = mb.findRay(x, y);<br> return new double[] {ray.position[0], ray.position[1]};<br> }<br> <br> /** Converts the given cursor coordinates to domain coordinates. */<br> private double[] cursorToDomain(double[] cursor) {<br> // locate x and y mappings<br> Vector maps = display.getMapVector(); // display is a DisplayImpl<br> int numMaps = maps.size();<br> ScalarMap map_x = null, map_y = null;<br> for (int i=0; i<numMaps && (map_x == null || map_y == null); i++) {<br> // for 3-D, you'd want to search for map_z in this loop as well<br> ScalarMap map = (ScalarMap) maps.elementAt(i);<br> if (map.getDisplayScalar().equals(Display.XAxis)) map_x = map;<br> else if (map.getDisplayScalar().equals(Display.YAxis)) map_y = map;<br> }<br> if (map_x == null || map_y == null) return null;<br> <br> // adjust for scale<br> double[] scale_offset = new double[2];<br> double[] dummy = new double[2];<br> double[] values = new double[2];<br> map_x.getScale(scale_offset, dummy, dummy);<br> values[0] = (cursor[0] - scale_offset[1]) / scale_offset[0];<br> map_y.getScale(scale_offset, dummy, dummy);<br> values[1] = (cursor[1] - scale_offset[1]) / scale_offset[0];<br> // hopefully the conversion will be straightforward in 3-D<br> <br> return values;<br> }<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> <br> <font size=2 color="#000080">Cheers.</font><br> <br> < < < t o l g a : | | : s a k m a n > > ><br> engineer, cfd consultant<br> analytic & 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). Instead, take a look at the displayChanged() method<br> of visad.bio.LinePool. It obtains the 2-D coordinates of a mouse click upon LEFT mouse<br> button release. 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. The key line is:<br> <br> 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. 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>
visad
archives: