Example #1
0
  /**
   * Creates the Control for the associated DisplayScalar. This method invokes the method {@link
   * ScalarMapListener#controlChanged(ScalarMapControlEvent)} on all registered {@link
   * ScalarMapListener}s with this instance as the event source and {@link
   * ScalarMapEvent#CONTROL_ADDED} or {@link ScalarMapEvent#CONTROL_REPLACED} as the event ID --
   * depending on whether this is the first control or not. The event control is the previous
   * control if the event ID is {@link ScalarMapEvent#CONTROL_REPLACED}. If the event ID is {@link
   * ScalarMapEvent#CONTROL_ADDED}, then the event control is the created control or <code>null
   * </code> -- depending on whether or not the control was successfully created.
   *
   * @throws RemoteException Java RMI failure
   * @throws VisADException VisAD failure
   */
  synchronized void setControl() throws VisADException, RemoteException {
    int evtID;
    Control evtCtl;
    if (control != null) {
      evtID = ScalarMapEvent.CONTROL_REPLACED;
      evtCtl = control;
    } else {
      evtID = ScalarMapEvent.CONTROL_ADDED;
      evtCtl = null;
    }

    if (display == null) {
      throw new DisplayException("ScalarMap.setControl: not part of " + "any Display");
    }
    control = display.getDisplayRenderer().makeControl(this);
    if (control != null) {
      display.addControl(control);

      if (evtCtl == null) {
        evtCtl = control;
      }
    }

    if (control != null || evtCtl != null) {
      notifyCtlListeners(new ScalarMapControlEvent(this, evtID, evtCtl));
    }
  }
Example #2
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());
     }
   }
 }
Example #3
0
  // type 'java Parallel' to run this application
  public static void main(String args[]) throws VisADException, RemoteException, IOException {

    RealType index = RealType.getRealType("index");
    RealType[] coords = new RealType[NCOORDS];
    for (int i = 0; i < NCOORDS; i++) {
      coords[i] = RealType.getRealType("coord" + i);
    }
    RealTupleType range = new RealTupleType(coords);
    FunctionType ftype = new FunctionType(index, range);
    Integer1DSet index_set = new Integer1DSet(NROWS);

    float[][] samples = new float[NCOORDS][NROWS];
    for (int i = 0; i < NCOORDS; i++) {
      for (int j = 0; j < NROWS; j++) {
        samples[i][j] = (float) Math.random();
      }
    }

    FlatField data = new FlatField(ftype, index_set);
    data.setSamples(samples, false);

    // create a 2-D Display using Java3D
    DisplayImpl display = new DisplayImplJ3D("display", new TwoDDisplayRendererJ3D());

    parallel(display, data);

    // create JFrame (i.e., a window) for display and slider
    JFrame frame = new JFrame("Parallel Coordinates VisAD Application");
    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);
  }
  /**
   * Set <CODE>Vector</CODE> of <CODE>String</CODE>s describing the cursor location from the cursor
   * location; this is invoked when the cursor location changes or the cursor display status changes
   */
  public void setCursorStringVector() {
    synchronized (cursorStringVector) {
      cursorStringVector.removeAllElements();
      float[][] cursor = new float[3][1];
      double[] cur = getCursor();
      cursor[0][0] = (float) cur[0];
      cursor[1][0] = (float) cur[1];
      cursor[2][0] = (float) cur[2];
      Enumeration maps = display.getMapVector().elements();
      while (maps.hasMoreElements()) {
        try {
          ScalarMap map = (ScalarMap) maps.nextElement();
          DisplayRealType dreal = map.getDisplayScalar();
          DisplayTupleType tuple = dreal.getTuple();
          int index = dreal.getTupleIndex();
          if (tuple != null
              && (tuple.equals(Display.DisplaySpatialCartesianTuple)
                  || (tuple.getCoordinateSystem() != null
                      && tuple
                          .getCoordinateSystem()
                          .getReference()
                          .equals(Display.DisplaySpatialCartesianTuple)))) {
            float[] fval = new float[1];
            if (tuple.equals(Display.DisplaySpatialCartesianTuple)) {
              fval[0] = cursor[index][0];
            } else {
              float[][] new_cursor = tuple.getCoordinateSystem().fromReference(cursor);
              fval[0] = new_cursor[index][0];
            }
            float[] dval = map.inverseScaleValues(fval);
            RealType real = (RealType) map.getScalar();

            // WLH 31 Aug 2000
            Real r = new Real(real, dval[0]);
            Unit overrideUnit = map.getOverrideUnit();
            Unit rtunit = real.getDefaultUnit();
            // units not part of Time string
            // DRM 2003-08-19: don't check for equality since toString
            // may be different
            if (overrideUnit != null
                && // !overrideUnit.equals(rtunit) &&
                (!Unit.canConvert(rtunit, CommonUnit.secondsSinceTheEpoch)
                    || rtunit.getAbsoluteUnit().equals(rtunit))) {
              dval[0] = (float) overrideUnit.toThis((double) dval[0], rtunit);
              r = new Real(real, dval[0], overrideUnit);
            }
            String valueString = r.toValueString();

            // WLH 27 Oct 2000
            String s = map.getScalarName() + " = " + valueString;
            // String s = real.getName() + " = " + valueString;

            cursorStringVector.addElement(s);
          } // end if (tuple != null && ...)
        } catch (VisADException e) {
        }
      } // end while(maps.hasMoreElements())
    } // end synchronized (cursorStringVector)
    render_trigger();
  }
Example #5
0
 /**
  * Set the DisplayImpl this ScalarMap is linked to
  *
  * @param d display to link to
  * @throws VisADException map is already linked to a DisplayImpl or other VisAD error
  */
 synchronized void setDisplay(DisplayImpl d) throws VisADException {
   if (d.equals(display)) return;
   if (display != null) {
     throw new DisplayException(
         "ScalarMap.setDisplay: ScalarMap cannot belong" + " to two Displays");
   }
   display = d;
   if (scale_flag) makeScale();
   // System.out.println("setDisplay " + Scalar + " -> " + DisplayScalar);
   // WLH 27 Nov 2000
   if (!(this instanceof ConstantMap)) {
     ProjectionControl pcontrol = display.getProjectionControl();
     try {
       setAspectCartesian(pcontrol.getAspectCartesian());
     } catch (RemoteException e) {
     }
   }
 }
 /**
  * Set the <I>wait flag</I> to the specified value. (When the <I>wait flag</I> is enabled, the
  * user is informed that the application is busy, typically by displaying a <B><TT>Please wait . .
  * .</TT></B> message at the bottom of the <CODE>Display</CODE>.) DisplayEvent.WAIT_ON and
  * DisplayEvent.WAIT_OFF events are fired based on value of b.
  *
  * @param b Boolean value to which <I>wait flag</I> is set.
  */
 public void setWaitFlag(boolean b) {
   waitFlag = b;
   try {
     DisplayEvent e =
         new DisplayEvent(display, (b == true) ? DisplayEvent.WAIT_ON : DisplayEvent.WAIT_OFF);
     display.notifyListeners(e);
   } catch (VisADException e) {
   } catch (RemoteException e) {
   }
 }
Example #7
0
 public void displayChanged(DisplayEvent e) throws RemoteException, VisADException {
   if (e.getId() == DisplayEvent.FRAME_DONE) {
     DisplayImpl display = (DisplayImpl) e.getDisplay();
     DisplayRenderer dr = display.getDisplayRenderer();
     MouseBehavior mb = dr.getMouseBehavior();
     double[] position1 = null;
     double[] position2 = null;
     if (display instanceof DisplayImplJ3D) {
       position1 = new double[] {1.0, 1.0, 1.0};
       position2 = new double[] {-1.0, -1.0, -1.0};
     } else {
       position1 = new double[] {1.0, 1.0};
       position2 = new double[] {-1.0, -1.0};
     }
     int[] screen1 = mb.getScreenCoords(position1);
     int[] screen2 = mb.getScreenCoords(position2);
     // System.out.println("screen1 = (" + screen1[0] + ", " + screen1[1] +")");
     // System.out.println("screen2 = (" + screen2[0] + ", " + screen2[1] +")");
   }
 }
Example #8
0
 /** invoke incTick on every application call to setRange */
 public long incTick() {
   // WLH 19 Feb 2001 - move to after increment NewTick
   // if (display != null) display.controlChanged();
   NewTick += 1;
   if (NewTick == Long.MAX_VALUE) NewTick = Long.MIN_VALUE + 1;
   /*
   System.out.println(Scalar + " -> " + DisplayScalar +
                      "  incTick = " + NewTick);
   */
   if (display != null) display.controlChanged();
   return NewTick;
 }
Example #9
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);
  }
Example #10
0
 /**
  * Initialize the lat/lon scalar maps
  *
  * @throws RemoteException On badness
  * @throws VisADException On badness
  */
 public void initLatLonMap() throws VisADException, RemoteException {
   if (latMap != null) {
     return;
   }
   if (getDisplayMaster() == null) {
     return;
   }
   boolean callScale = (latMap == null);
   DisplayImpl display = (DisplayImpl) getDisplayMaster().getDisplay();
   // find spatial maps for Latitude and Longitude
   latMap = null;
   lonMap = null;
   Vector scalar_map_vector = display.getMapVector();
   Enumeration en = scalar_map_vector.elements();
   while (en.hasMoreElements()) {
     ScalarMap map = (ScalarMap) en.nextElement();
     DisplayRealType real = map.getDisplayScalar();
     DisplayTupleType tuple = real.getTuple();
     if ((tuple != null)
         && (tuple.equals(Display.DisplaySpatialCartesianTuple)
             || ((tuple.getCoordinateSystem() != null)
                 && tuple
                     .getCoordinateSystem()
                     .getReference()
                     .equals(Display.DisplaySpatialCartesianTuple)))) { // Spatial
       if (RealType.Latitude.equals(map.getScalar())) {
         latMap = map;
       } else if (RealType.Longitude.equals(map.getScalar())) {
         lonMap = map;
       }
     }
   }
   if (callScale) {
     setScale(baseScale);
   }
 }
Example #11
0
  /**
   * Specify <CODE>DisplayImpl</CODE> to be rendered.
   *
   * @param d <CODE>Display</CODE> to render.
   * @exception VisADException If a <CODE>DisplayImpl</CODE> has already been specified.
   */
  public void setDisplay(DisplayImpl d) throws VisADException {
    if (display != null) {
      throw new DisplayException("DisplayRenderer.setDisplay: " + "display already set");
    }
    display = d;

    // reinitialize rendererControl
    if (rendererControl == null) {
      rendererControl = new RendererControl(display);
      initControl(rendererControl);
    } else {
      RendererControl rc = new RendererControl(display);
      rc.syncControl(rendererControl);
      rendererControl = rc;
    }
    rendererControl.addControlListener(this);
    display.addControl(rendererControl);
  }
Example #12
0
 /**
  * Create the scale that is displayed. This is called automatically when <CODE>setRange(lo, hi)
  * </CODE> and <CODE>setDisplay</CODE> are called. It makes a call to <CODE>AxisScale.makeScale()
  * </CODE> where the actual hard work is done.
  *
  * @throws VisADException VisAD error.
  */
 public void makeScale() throws VisADException {
   if (axisScale != null) {
     DisplayRenderer displayRenderer = null;
     if (display == null) return;
     displayRenderer = display.getDisplayRenderer();
     if (displayRenderer == null) return;
     boolean scaleMade = axisScale.makeScale();
     if (scaleMade) {
       // displayRenderer.setScale(axis, axis_ordinal, array, scale_color);
       if (scale_on) {
         displayRenderer.setScale(axisScale);
       } else {
         displayRenderer.clearScale(axisScale);
       }
       scale_flag = false;
     }
   }
 }
Example #13
0
  public static void main(String[] args) throws Exception {

    DisplayImpl display = new DisplayImplJ2D("display");
    display.getDisplayRenderer().setBoxOn(false);
    double[] matrix = display.getProjectionControl().getMatrix();
    matrix[0] = 1.25;
    matrix[3] = -1.25;
    display.getProjectionControl().setMatrix(matrix);
    display.addMap(new ScalarMap(RealType.YAxis, Display.YAxis));
    display.addMap(new ScalarMap(RealType.XAxis, Display.XAxis));
    float[][] values = new float[3][220];
    int l = 0;
    for (int x = 0; x < 11; x++) {
      for (int y = 0; y < 20; y++) {
        values[0][l] = -1.f + y / 10.f;
        values[1][l] = 1.f - x / 4.f;
        values[2][l] = l++;
      }
    }
    Gridded3DSet set = new Gridded3DSet(RealTupleType.SpatialCartesian3DTuple, values, l);
    ScalarMap shapeMap = new ScalarMap(RealType.ZAxis, Display.Shape);
    display.addMap(shapeMap);
    ShapeControl sc = (ShapeControl) shapeMap.getControl();
    sc.setShapeSet(new Integer1DSet(l));
    sc.setShapes(WeatherSymbols.getAllMetSymbols());
    sc.setScale(0.1f);
    DataReference ref = new DataReferenceImpl("ref");
    ref.setData(set);
    display.addReference(ref);
    JFrame frame = new JFrame("Weather Symbol Plot Test");
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
    frame.getContentPane().add(display.getComponent());
    frame.pack();
    frame.setSize(500, 500);
    frame.setVisible(true);
  }
Example #14
0
  /**
   * Returns the dimensionality of the display.
   *
   * @return The dimensionality of the display (either 2 or 3).
   */
  public int getDimensionality() {

    return display.getDisplayRenderer().getMode2D() ? 2 : 3;
  }
Example #15
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);
  }
  /** test BarbManipulationRendererJ3D */
  public static void main(String args[]) throws VisADException, RemoteException {

    System.out.println("BMR.main()");

    // construct RealTypes for wind record components
    RealType lat = RealType.Latitude;
    RealType lon = RealType.Longitude;
    RealType windx = RealType.getRealType("windx", CommonUnit.meterPerSecond);
    RealType windy = RealType.getRealType("windy", CommonUnit.meterPerSecond);
    RealType red = RealType.getRealType("red");
    RealType green = RealType.getRealType("green");

    // EarthVectorType extends RealTupleType and says that its
    // components are vectors in m/s with components parallel
    // to Longitude (positive east) and Latitude (positive north)
    EarthVectorType windxy = new EarthVectorType(windx, windy);

    RealType wind_dir = RealType.getRealType("wind_dir", CommonUnit.degree);
    RealType wind_speed = RealType.getRealType("wind_speed", CommonUnit.meterPerSecond);
    RealTupleType windds = null;
    if (args.length > 0) {
      System.out.println("polar winds");
      windds =
          new RealTupleType(
              new RealType[] {wind_dir, wind_speed}, new WindPolarCoordinateSystem(windxy), null);
    }

    // construct Java3D display and mappings that govern
    // how wind records are displayed
    DisplayImpl display = new DisplayImplJ3D("display1", new TwoDDisplayRendererJ3D());
    ScalarMap lonmap = new ScalarMap(lon, Display.XAxis);
    display.addMap(lonmap);
    ScalarMap latmap = new ScalarMap(lat, Display.YAxis);
    display.addMap(latmap);

    FlowControl flow_control;
    if (args.length > 0) {
      ScalarMap winds_map = new ScalarMap(wind_speed, Display.Flow1Radial);
      display.addMap(winds_map);
      winds_map.setRange(0.0, 1.0); // do this for barb rendering
      ScalarMap windd_map = new ScalarMap(wind_dir, Display.Flow1Azimuth);
      display.addMap(windd_map);
      windd_map.setRange(0.0, 360.0); // do this for barb rendering
      flow_control = (FlowControl) windd_map.getControl();
      flow_control.setFlowScale(0.15f); // this controls size of barbs
    } else {
      ScalarMap windx_map = new ScalarMap(windx, Display.Flow1X);
      display.addMap(windx_map);
      windx_map.setRange(-1.0, 1.0); // do this for barb rendering
      ScalarMap windy_map = new ScalarMap(windy, Display.Flow1Y);
      display.addMap(windy_map);
      windy_map.setRange(-1.0, 1.0); // do this for barb rendering
      flow_control = (FlowControl) windy_map.getControl();
      flow_control.setFlowScale(0.15f); // this controls size of barbs
    }

    display.addMap(new ScalarMap(red, Display.Red));
    display.addMap(new ScalarMap(green, Display.Green));
    display.addMap(new ConstantMap(1.0, Display.Blue));

    DataReferenceImpl[] refs = new DataReferenceImpl[N * N];
    int k = 0;
    // create an array of N by N winds
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        double u = 2.0 * i / (N - 1.0) - 1.0;
        double v = 2.0 * j / (N - 1.0) - 1.0;

        // each wind record is a Tuple (lon, lat, (windx, windy), red, green)
        // set colors by wind components, just for grins
        Tuple tuple;
        double fx = 30.0 * u;
        double fy = 30.0 * v;
        if (args.length > 0) {
          double fd = Data.RADIANS_TO_DEGREES * Math.atan2(-fx, -fy);
          double fs = Math.sqrt(fx * fx + fy * fy);
          tuple =
              new Tuple(
                  new Data[] {
                    new Real(lon, 10.0 * u),
                    new Real(lat, 10.0 * v - 40.0),
                    new RealTuple(windds, new double[] {fd, fs}),
                    new Real(red, u),
                    new Real(green, v)
                  });
        } else {
          tuple =
              new Tuple(
                  new Data[] {
                    new Real(lon, 10.0 * u),
                    new Real(lat, 10.0 * v - 40.0),
                    new RealTuple(windxy, new double[] {fx, fy}),
                    new Real(red, u),
                    new Real(green, v)
                  });
        }

        // construct reference for wind record
        refs[k] = new DataReferenceImpl("ref_" + k);
        refs[k].setData(tuple);

        // link wind record to display via BarbManipulationRendererJ3D
        // so user can change barb by dragging it
        // drag with right mouse button and shift to change direction
        // drag with right mouse button and no shift to change speed
        BarbManipulationRendererJ3D renderer = new BarbManipulationRendererJ3D();
        renderer.setKnotsConvert(true);
        display.addReferences(renderer, refs[k]);

        // link wind record to a CellImpl that will listen for changes
        // and print them
        WindGetterJ3D cell = new WindGetterJ3D(flow_control, refs[k]);
        cell.addReference(refs[k]);

        k++;
      }
    }

    // instead of linking the wind record "DataReferenceImpl refs" to
    // the WindGetterJ3Ds, you can have some user interface event (e.g.,
    // the user clicks on "DONE") trigger code that does a getData() on
    // all the refs and stores the records in a file.

    // create JFrame (i.e., a window) for display and slider
    JFrame frame = new JFrame("test BarbManipulationRendererJ3D");
    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);
  }
Example #17
0
 /**
  * Returns the AWT component.
  *
  * @return The AWT component.
  */
 public Component getComponent() {
   return display.getComponent();
 }