Пример #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
  /** 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);
  }
Пример #3
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]));
  }