Re: specifying the z value on display

Hi Jacky,

Below is a simple extension of visad.ss.FancySSCell that prints range values
to the console window whenever the cursor is being displayed.  It shouldn't
be hard to modify this code to display the range values in a JLabel or other
such GUI component.  To make extensions of visad.ss.FancySSCell easier in
the future, I added a utility method to the visad.ss.SpreadSheet class,
which you'll need to run this code.  For now, find the latest version of
visad.ss.SpreadSheet at:
   http://palm.ssec.wisc.edu/SpreadSheet.java
Place the new SpreadSheet.java in your visad/ss directory before attempting
to compile the code below.

You should be able to follow this pattern to extend FancySSCell in any way
you desire, producing any number of different custom spreadsheet cell
behaviors (such as the white background discussed in a previous email).

-Curtis

At 22:58 3/15/01, Jacky Saint wrote:
> Hi all,
>     I'm having problems trying to use VisAD SpreadSheet to display the range 
> that's mapped on to X and Y axis. I have the following mapping 
> (longitude,latitude)->(temperature). When two buttons are pressed on the 
> mouse a display comes up showing location of the longitude and latitude. 
> What I would like to do is to display the data for temperature also. The 
> SpreadSheet does this only when temperature is mapped to the Zaxis. As I am 
> working in 2D, I only would like to map temperature to the IsoContour.
> I have tried searching this forum for clues as how I may do this and found 
> some hints, but as I am not a very good programmer I would appreciate any 
> help.
> 
> I found the following bit of information in this forum, but I have problems 
> trying to use this in relation to the VisAD SpreadSheet.
> 
> 
> 
> To: John J Brecht <john.brecht@xxxxxxx>
> Subject: Re: Transform of ViewPlatform, and Re: range value at cursor
> From: "From: Bill Hibbard <hibbard@xxxxxxxxxxxxxxxxx>" <billh@xxxxxxxxxxxxx>
> Date: Mon, 3 Jan 2000 18:28:29 -0600 (CST)
> cc: VisAD List <visad-list@xxxxxxxxxxxxx>
> In-Reply-To: <38711948.84C084D8@xxxxxxx>
> 
> 
> >What would be the most straightforward way to get the range value at a
> >cursor location?
> 
> Say for example the data is a FlatField with MathType ((x, y0 -> range)
> and ScalarMaps are map_x: x -> XAxis and map_y: y -> YAxis.  Then:
> 
>   double[] scale_offset = new double[2];
>   double[] dum_1 = new double[2];
>   double[] dum_2 = new double[2];
>   float[] cur = display.getDisplayRenderer().getCursor();
>   map_x.getScale(scale_offset, dum_1, dum_2);
>   double value_x = (cur[0] - scale_offset[1])/scale_offset[0];
>   map_y.getScale(scale_offset, dum_1, dum_2);
>   double value_y = (cur[1] - scale_offset[1])/scale_offset[0];
>   RealTuple tuple
>     new RealTuple(new Real[] {new Real(x, value_x),
>                               new Real(y, value_y)});
>   double range_value = ((Real) flat_field.evaluate(tuple)).getValue();
> 
> 
> 
> 
> Thank you,
> Jacky
> p.s. I would like to thank Tom Whittaker for finding the Map of Europe


-----------------------
//
// CursorSSCell.java
//

import java.awt.Frame;
import java.rmi.RemoteException;
import java.util.Vector;
import visad.*;
import visad.formula.FormulaManager;
import visad.ss.*;

public class CursorSSCell extends FancySSCell {

  public CursorSSCell(String name, FormulaManager fman, RemoteServer rs,
    boolean slave, String save, Frame parent) throws VisADException,
    RemoteException
  {
    super(name, fman, rs, slave, save, parent);

    addDisplayListener(new DisplayListener() {
      public void displayChanged(DisplayEvent e) {
        // get cursor value
        double[] scale_offset = new double[2];
        double[] dum_1 = new double[2];
        double[] dum_2 = new double[2];
        DisplayRenderer renderer = VDisplay.getDisplayRenderer();
        double[] cur = renderer.getCursor();
        Vector cursorStringVector = renderer.getCursorStringVector();
        if (cursorStringVector == null || cursorStringVector.size() == 0 ||
          cur == null || cur.length == 0 || cur[0] != cur[0])
        {
          return;
        }

        // locate x and y mappings
        ScalarMap[] maps = getMaps();
        ScalarMap map_x = null, map_y = null;
        for (int i=0; i<maps.length && (map_x==null || map_y==null); i++) {
          if (maps[i].getDisplayScalar().equals(Display.XAxis)) {
            map_x = maps[i];
          }
          else if (maps[i].getDisplayScalar().equals(Display.YAxis)) {
            map_y = maps[i];
          }
        }
        if (map_x == null || map_y == null) return;

        // get scale
        map_x.getScale(scale_offset, dum_1, dum_2);
        double value_x = (cur[0] - scale_offset[1]) / scale_offset[0];
        map_y.getScale(scale_offset, dum_1, dum_2);
        double value_y = (cur[1] - scale_offset[1]) / scale_offset[0];
        RealTuple tuple = null;
        try {
          tuple = new RealTuple(new Real[] {
            new Real((RealType) map_x.getScalar(), value_x),
            new Real((RealType) map_y.getScalar(), value_y)});
        }
        catch (VisADException exc) { exc.printStackTrace(); }
        catch (RemoteException exc) { exc.printStackTrace(); }

        // check each data object in the cell
        Data[] data = getData();
        for (int i=0; i<data.length; i++) {
          if (data[i] instanceof FlatField) {
            // get range values
            FlatField ff = (FlatField) data[i];
            double[] range_values = null;
            try {
              Data d = ff.evaluate(tuple);
              if (d instanceof Real) {
                Real r = (Real) d;
                range_values = new double[1];
                range_values[0] = r.getValue();
              }
              else if (d instanceof RealTuple) {
                RealTuple rt = (RealTuple) d;
                int dim = rt.getDimension();
                range_values = new double[dim];
                for (int j=0; j<dim; j++) {
                  Real r = (Real) rt.getComponent(j);
                  range_values[j] = r.getValue();
                }
              }
            }
            catch (VisADException exc) { exc.printStackTrace(); }
            catch (RemoteException exc) { exc.printStackTrace(); }

            // display range values somehow; e.g.:
            System.out.print("data #" + i + ": " +
              "(" + value_x + ", " + value_y + "): ");
            if (range_values == null) System.out.println("null");
            else {
              if (range_values.length == 1) {
                System.out.println(range_values[0]);
              }
              else {
                System.out.print("(" + range_values[0]);
                for (int j=1; j<range_values.length; j++) {
                  System.out.print(", " + range_values[j]);
                }
                System.out.println(")");
              }
            }
          }
        }
      }
    });
  }

  public static void main(String[] args) {
    SpreadSheet.setSSCellClass(CursorSSCell.class);
    SpreadSheet.main(args);
  }

}
-----------------------


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