示例#1
0
  void setupServerData(LocalDisplay[] dpys) throws RemoteException, VisADException {
    Unit super_degree = CommonUnit.degree.scale(2.5);
    RealType lon = RealType.getRealType("lon", super_degree);

    DataReference ref = loadFile();
    if (ref == null) {
      System.err.println("must specify netCDF file name");
      System.exit(1);
      return;
    }

    FieldImpl netcdf_data = (FieldImpl) ref.getData();

    // compute ScalarMaps from type components
    FunctionType ftype = (FunctionType) netcdf_data.getType();
    RealTupleType dtype = ftype.getDomain();
    MathType rntype = ftype.getRange();
    int n = dtype.getDimension();
    dpys[0].addMap(new ScalarMap((RealType) dtype.getComponent(0), Display.XAxis));
    if (n > 1) {
      dpys[0].addMap(new ScalarMap((RealType) dtype.getComponent(1), Display.YAxis));
    }
    if (n > 2) {
      dpys[0].addMap(new ScalarMap((RealType) dtype.getComponent(2), Display.ZAxis));
    }
    if (rntype instanceof RealType) {
      dpys[0].addMap(new ScalarMap((RealType) rntype, Display.Green));
      if (n <= 2) {
        dpys[0].addMap(new ScalarMap((RealType) rntype, Display.ZAxis));
      }
    } else if (rntype instanceof RealTupleType) {
      int m = ((RealTupleType) rntype).getDimension();
      RealType rr = (RealType) ((RealTupleType) rntype).getComponent(0);
      dpys[0].addMap(new ScalarMap(rr, Display.Green));
      if (n <= 2) {
        if (m > 1) {
          rr = (RealType) ((RealTupleType) rntype).getComponent(1);
        }
        dpys[0].addMap(new ScalarMap(rr, Display.ZAxis));
      }
    }
    dpys[0].addMap(new ConstantMap(0.5, Display.Red));
    dpys[0].addMap(new ConstantMap(0.0, Display.Blue));

    dpys[0].addReference(ref, null);

    System.out.println("now saving data as 'save.nc' and re-reading");

    Plain plain = new Plain();
    try {
      plain.save("save.nc", netcdf_data, true);
      netcdf_data = (FieldImpl) plain.open("save.nc");
    } catch (IOException e) {
      System.err.println("Couldn't open \"save.nc\": " + e.getMessage());
      System.exit(1);
      return;
    }
  }
示例#2
0
 private static Set getNullDomainSet(RealTupleType type) throws VisADException {
   int n = type.getDimension();
   double[] values = new double[n];
   for (int i = 0; i < n; i++) values[i] = 0.0;
   RealTuple tuple;
   try {
     tuple = new RealTuple(type, values);
     return new SingletonSet(tuple);
   } catch (RemoteException e) {
     throw new VisADError("FileFlatField.getNullDomainSet: " + e.toString());
   }
 }
示例#3
0
文件: Parallel.java 项目: visad/visad
  /** create parallel coordinates display for data */
  public static void parallel(DisplayImpl display, FlatField data)
      throws VisADException, RemoteException {

    FunctionType ftype = (FunctionType) data.getType();
    RealType index = (RealType) ftype.getDomain().getComponent(0);
    RealTupleType range = (RealTupleType) ftype.getRange();
    int ncoords = range.getDimension();
    int nrows = data.getLength();
    Set index_set = data.getDomainSet();
    float[][] samples = data.getFloats(false);

    RealType x = RealType.getRealType("coordinate");
    RealType y = RealType.getRealType("value");
    SetType xy = new SetType(new RealTupleType(x, y));
    FunctionType ptype = new FunctionType(index, xy);
    FieldImpl pfield = new FieldImpl(ptype, index_set);
    for (int j = 0; j < nrows; j++) {
      float[][] locs = new float[2][ncoords];
      for (int i = 0; i < ncoords; i++) {
        locs[0][i] = i;
        locs[1][i] = samples[i][j];
      }
      Gridded2DSet set = new Gridded2DSet(xy, locs, ncoords);
      pfield.setSample(j, set, false);
    }

    // create a DataReference for river system
    DataReference parallel_ref = new DataReferenceImpl("parallel");
    parallel_ref.setData(pfield);

    display.addMap(new ScalarMap(x, Display.XAxis));
    display.addMap(new ScalarMap(y, Display.YAxis));

    // enable axis scales
    display.getGraphicsModeControl().setScaleEnable(true);

    // link display to parallel display
    display.addReference(parallel_ref);
  }
示例#4
0
  void setupServerData(LocalDisplay[] dpys) throws RemoteException, VisADException {
    DefaultFamily df = new DefaultFamily("loader");

    DataReference ref1 = loadFile(df, file1, "img1");
    if (ref1 == null) {
      System.err.println("\"" + file1 + "\" is not a valid file");
      System.exit(1);
      return;
    }

    DataReference ref2 = loadFile(df, file2, "img2");
    if (ref2 == null) {
      System.err.println("\"" + file2 + "\" is not a valid file");
      System.exit(1);
      return;
    }

    FlatField img1 = (FlatField) ref1.getData();
    FlatField img2 = (FlatField) ref2.getData();

    /*
        if (!img1.getType().equals(img2.getType())) {
          System.err.println("Incompatible file types:");
          System.err.println("  " + file1 + ": " + img1.getType());
          System.err.println("  " + file2 + ": " + img2.getType());
          System.exit(1);
          return;
        }
    */

    // compute ScalarMaps from type components
    FunctionType ftype = (FunctionType) img1.getType();
    RealTupleType dtype = ftype.getDomain();
    RealTupleType rtype = (RealTupleType) ftype.getRange();

    /* map domain elements to spatial axes */
    final int dLen = dtype.getDimension();
    for (int i = 0; i < dLen; i++) {
      ScalarType scalT;
      DisplayRealType dpyRT;

      switch (i) {
        case 0:
          dpyRT = Display.XAxis;
          break;
        case 1:
          dpyRT = Display.YAxis;
          break;
        case 2:
          dpyRT = Display.ZAxis;
          break;
        default:
          dpyRT = null;
          break;
      }

      if (dpyRT != null) {
        dpys[0].addMap(new ScalarMap((RealType) dtype.getComponent(i), dpyRT));
      }
    }

    /* map range elements to colors */
    final int rLen = rtype.getDimension();
    for (int i = 0; i < rLen; i++) {
      ScalarType scalT;
      DisplayRealType dpyRT;

      switch (i) {
        case 0:
          dpyRT = Display.Red;
          break;
        case 1:
          dpyRT = Display.Green;
          break;
        case 2:
          dpyRT = Display.Blue;
          break;
        default:
          dpyRT = null;
          break;
      }

      if (dpyRT != null) {
        dpys[0].addMap(new ScalarMap((RealType) rtype.getComponent(i), dpyRT));
      }
    }

    dpys[0].addReference(ref1, null);
    dpys[0].addReference(ref2, null);

    dpys[0].addActivityHandler(new SwitchGIFs(dpys[0]));
  }
  /**
   * determine whether the given MathType and collection of ScalarMaps meets the criteria to use
   * ImageRendererJ3D. Throw a VisADException if ImageRenderer cannot be used, otherwise return
   * true.
   */
  public static boolean isRendererUsable(MathType type, ScalarMap[] maps) throws VisADException {
    RealType time = null;
    RealTupleType domain = null;
    RealTupleType range = null;
    RealType x = null, y = null;
    RealType rx = null, ry = null; // WLH 19 July 2000
    RealType r = null, g = null, b = null;
    RealType rgb = null;

    // must be a function
    if (!(type instanceof FunctionType)) {
      throw new VisADException("Not a FunctionType");
    }
    FunctionType function = (FunctionType) type;
    RealTupleType functionD = function.getDomain();
    MathType functionR = function.getRange();

    // time function
    if (function.equalsExceptName(image_sequence_type)
        || function.equalsExceptName(image_sequence_type2)
        || function.equalsExceptName(image_sequence_type3)) {
      // strip off time RealType
      time = (RealType) functionD.getComponent(0);
      function = (FunctionType) functionR;
      functionD = function.getDomain();
      functionR = function.getRange();
    }

    // ((ImageLine, ImageElement) -> ImageValue)
    // ((ImageLine, ImageElement) -> (ImageValue))
    // ((ImageLine, ImageElement) -> (Red, Green, Blue))
    if (function.equalsExceptName(image_type)
        || function.equalsExceptName(image_type2)
        || function.equalsExceptName(image_type3)) {
      domain = function.getDomain();
      MathType rt = function.getRange();
      if (rt instanceof RealType) {
        range = new RealTupleType((RealType) rt);
      } else if (rt instanceof RealTupleType) {
        range = (RealTupleType) rt;
      } else {
        // illegal MathType
        throw new VisADException("Illegal RangeType");
      }
    } else {
      // illegal MathType
      throw new VisADException("Illegal MathType");
    }

    // extract x and y from domain
    x = (RealType) domain.getComponent(0);
    y = (RealType) domain.getComponent(1);

    // WLH 19 July 2000
    CoordinateSystem cs = domain.getCoordinateSystem();
    if (cs != null) {
      RealTupleType rxy = cs.getReference();
      rx = (RealType) rxy.getComponent(0);
      ry = (RealType) rxy.getComponent(1);
    }

    // extract colors from range
    int dim = range.getDimension();
    if (dim == 1) rgb = (RealType) range.getComponent(0);
    else { // dim == 3
      r = (RealType) range.getComponent(0);
      g = (RealType) range.getComponent(1);
      b = (RealType) range.getComponent(2);
    }

    // verify that collection of ScalarMaps is legal
    boolean btime = (time == null);
    boolean bx = false, by = false;
    boolean brx = false, bry = false; // WLH 19 July 2000
    boolean br = false, bg = false, bb = false;
    boolean dbr = false, dbg = false, dbb = false;
    Boolean latlon = null;
    DisplayRealType spatial = null;

    for (int i = 0; i < maps.length; i++) {
      ScalarMap m = maps[i];
      ScalarType md = m.getScalar();
      DisplayRealType mr = m.getDisplayScalar();
      boolean ddt = md.equals(time);
      boolean ddx = md.equals(x);
      boolean ddy = md.equals(y);
      boolean ddrx = md.equals(rx);
      boolean ddry = md.equals(ry);
      boolean ddr = md.equals(r);
      boolean ddg = md.equals(g);
      boolean ddb = md.equals(b);
      boolean ddrgb = md.equals(rgb);

      // animation mapping
      if (ddt) {
        if (btime) throw new VisADException("Multiple Time mappings");
        if (!mr.equals(Display.Animation)) {
          throw new VisADException("Time mapped to something other than Animation");
        }
        btime = true;
      }

      // spatial mapping
      else if (ddx || ddy || ddrx || ddry) {
        if (ddx && bx || ddy && by || ddrx && brx || ddry && bry) {
          throw new VisADException("Duplicate spatial mappings");
        }
        if (((ddx || ddy) && (brx || bry)) || ((ddrx || ddry) && (bx || by))) {
          throw new VisADException("reference and non-reference spatial mappings");
        }
        RealType q = (ddx ? x : null);
        if (ddy) q = y;
        if (ddrx) q = rx;
        if (ddry) q = ry;

        boolean ll;
        if (mr.equals(Display.XAxis) || mr.equals(Display.YAxis) || mr.equals(Display.ZAxis)) {
          ll = false;
        } else if (mr.equals(Display.Latitude)
            || mr.equals(Display.Longitude)
            || mr.equals(Display.Radius)) {
          ll = true;
        } else throw new VisADException("Illegal domain mapping");

        if (latlon == null) {
          latlon = new Boolean(ll);
          spatial = mr;
        } else if (latlon.booleanValue() != ll) {
          throw new VisADException("Multiple spatial coordinate systems");
        }
        // two mappings to the same spatial DisplayRealType are not allowed
        else if (spatial == mr) {
          throw new VisADException("Multiple mappings to the same spatial DisplayRealType");
        }

        if (ddx) bx = true;
        else if (ddy) by = true;
        else if (ddrx) brx = true;
        else if (ddry) bry = true;
      }

      // rgb mapping
      else if (ddrgb) {
        if (br || bg || bb) {
          throw new VisADException("Duplicate color mappings");
        }
        if (rgb == null || !(mr.equals(Display.RGB) || mr.equals(Display.RGBA))) {
          throw new VisADException("Illegal RGB/RGBA mapping");
        }
        dbr = dbg = dbb = true;
        br = bg = bb = true;
      }

      // color mapping
      else if (ddr || ddg || ddb) {
        if (rgb != null) throw new VisADException("Illegal RGB mapping");
        RealType q = (ddr ? r : (ddg ? g : b));
        if (mr.equals(Display.Red)) dbr = true;
        else if (mr.equals(Display.Green)) dbg = true;
        else if (mr.equals(Display.Blue)) dbb = true;
        else throw new VisADException("Illegal color mapping");

        if (ddr) br = true;
        else if (ddg) bg = true;
        else bb = true;
      }

      // illegal ScalarMap involving this MathType
      else if (ddt || ddx || ddy || ddrx || ddry || ddr || ddg || ddb || ddrgb) {
        throw new VisADException("Illegal mapping: " + m);
      }
    }

    // return true if all conditions for ImageRendererJ3D are met
    if (!(btime && ((bx && by) || (brx && bry)) && br && bg && bb && dbr && dbg && dbb)) {
      throw new VisADException("Insufficient mappings");
    }
    return true;
  }