Esempio n. 1
0
 public void actionPerformed(ActionEvent e) {
   String cmd = e.getActionCommand();
   if (cmd.equals("del")) {
     try {
       UnionSet set = (UnionSet) ref.getData();
       SampledSet[] sets = set.getSets();
       SampledSet[] new_sets = new SampledSet[sets.length - 1];
       System.arraycopy(sets, 0, new_sets, 0, sets.length - 1);
       ref.setData(new UnionSet(set.getType(), new_sets));
     } catch (VisADException ex) {
     } catch (RemoteException ex) {
     }
   } else if (cmd.equals("fill")) {
     UnionSet set = null;
     try {
       set = (UnionSet) ref.getData();
       System.out.println("area = " + DelaunayCustom.computeArea(set));
     } catch (VisADException ex) {
       System.out.println(ex.getMessage());
     }
     try {
       // Irregular2DSet new_set = DelaunayCustom.fill(set);
       Irregular2DSet new_set = DelaunayCustom.fillCheck(set, false);
       if (new_ref == null) {
         new_ref = new DataReferenceImpl("fill");
         ConstantMap[] cmaps =
             new ConstantMap[] {
               new ConstantMap(1.0, Display.Blue),
               new ConstantMap(1.0, Display.Red),
               new ConstantMap(0.0, Display.Green)
             };
         DataRenderer renderer =
             (display instanceof DisplayImplJ3D)
                 ? (DataRenderer) new DefaultRendererJ3D()
                 : (DataRenderer) new DefaultRendererJ2D();
         renderer.suppressExceptions(true);
         display.addReferences(renderer, new_ref, cmaps);
       }
       new_ref.setData(new_set);
     } catch (VisADException ex) {
       System.out.println(ex.getMessage());
     } catch (RemoteException ex) {
       System.out.println(ex.getMessage());
     }
   } else if (cmd.equals("lines")) {
     try {
       lines = !lines;
       GraphicsModeControl mode = display.getGraphicsModeControl();
       if (lines) {
         mode.setPolygonMode(DisplayImplJ3D.POLYGON_LINE);
       } else {
         mode.setPolygonMode(DisplayImplJ3D.POLYGON_FILL);
       }
     } catch (VisADException ex) {
       System.out.println(ex.getMessage());
     } catch (RemoteException ex) {
       System.out.println(ex.getMessage());
     }
   }
 }
 public void doAction() throws VisADException, RemoteException {
   Tuple tuple = (Tuple) ref.getData();
   float lon = (float) ((Real) tuple.getComponent(0)).getValue();
   float lat = (float) ((Real) tuple.getComponent(1)).getValue();
   RealTuple wind = (RealTuple) tuple.getComponent(2);
   float windx = (float) ((Real) wind.getComponent(0)).getValue();
   float windy = (float) ((Real) wind.getComponent(1)).getValue();
   System.out.println("wind = (" + windx + ", " + windy + ") at (" + +lat + ", " + lon + ")");
   /* a testing hack
       count--;
       if (count < 0) {
         count = 20;
         scale = 0.15f * 0.3f / scale;
         flow_control.setFlowScale(scale);
       }
   */
 }
Esempio n. 3
0
  /**
   * run 'java FlowTest middle_latitude' to test with (lat, lon) run 'java FlowTest middle_latitude
   * x' to test with (lon, lat) adjust middle_latitude for south or north
   */
  public static void main(String args[]) throws VisADException, RemoteException {
    double mid_lat = -10.0;
    if (args.length > 0) {
      try {
        mid_lat = Double.valueOf(args[0]).doubleValue();
      } catch (NumberFormatException e) {
      }
    }
    boolean swap = (args.length > 1);
    RealType lat = RealType.Latitude;
    RealType lon = RealType.Longitude;
    RealType[] types;
    if (swap) {
      types = new RealType[] {lon, lat};
    } else {
      types = new RealType[] {lat, lon};
    }
    RealTupleType earth_location = new RealTupleType(types);
    System.out.println("earth_location = " + earth_location + " mid_lat = " + mid_lat);

    RealType flowx = RealType.getRealType("flowx", CommonUnit.meterPerSecond);
    RealType flowy = RealType.getRealType("flowy", CommonUnit.meterPerSecond);
    RealType red = RealType.getRealType("red");
    RealType green = RealType.getRealType("green");
    EarthVectorType flowxy = new EarthVectorType(flowx, flowy);
    TupleType range = null;

    range = new TupleType(new MathType[] {flowxy, red, green});
    FunctionType flow_field = new FunctionType(earth_location, range);

    DisplayImpl display = new DisplayImplJ3D("display1", new TwoDDisplayRendererJ3D());
    ScalarMap xmap = new ScalarMap(lon, Display.XAxis);
    display.addMap(xmap);
    ScalarMap ymap = new ScalarMap(lat, Display.YAxis);
    display.addMap(ymap);
    ScalarMap flowx_map = new ScalarMap(flowx, Display.Flow1X);
    display.addMap(flowx_map);
    flowx_map.setRange(-10.0, 10.0);
    ScalarMap flowy_map = new ScalarMap(flowy, Display.Flow1Y);
    display.addMap(flowy_map);
    flowy_map.setRange(-10.0, 10.0);
    FlowControl flow_control = (FlowControl) flowy_map.getControl();
    flow_control.setFlowScale(0.05f);
    display.addMap(new ScalarMap(red, Display.Red));
    display.addMap(new ScalarMap(green, Display.Green));
    display.addMap(new ConstantMap(1.0, Display.Blue));

    double lonlow = -10.0;
    double lonhi = 10.0;
    double latlow = mid_lat - 10.0;
    double lathi = mid_lat + 10.0;
    Linear2DSet set;
    if (swap) {
      set = new Linear2DSet(earth_location, lonlow, lonhi, N, latlow, lathi, N);
    } else {
      set = new Linear2DSet(earth_location, latlow, lathi, N, lonlow, lonhi, N);
    }
    double[][] values = new double[4][N * N];
    int m = 0;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        int k = i;
        int l = j;
        if (swap) {
          k = j;
          l = i;
        }
        double u = (N - 1.0) / 2.0 - l;
        double v = k - (N - 1.0) / 2.0;
        // double u = 2.0 * k / (N - 1.0) - 1.0;
        // double v = 2.0 * l / (N - 1.0);
        double fx = 6.0 * u;
        double fy = 6.0 * v;
        values[0][m] = fx;
        values[1][m] = fy;
        values[2][m] = u;
        values[3][m] = v;
        m++;
      }
    }
    FlatField field = new FlatField(flow_field, set);
    field.setSamples(values);
    DataReferenceImpl ref = new DataReferenceImpl("ref");
    ref.setData(field);
    display.addReference(ref);

    // create JFrame (i.e., a window) for display and slider
    JFrame frame = new JFrame("test FlowTest");
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });

    // create JPanel in JFrame
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.setAlignmentY(JPanel.TOP_ALIGNMENT);
    panel.setAlignmentX(JPanel.LEFT_ALIGNMENT);
    frame.getContentPane().add(panel);

    // add display to JPanel
    panel.add(display.getComponent());

    // set size of JFrame and make it visible
    frame.setSize(500, 500);
    frame.setVisible(true);
  }