Ejemplo n.º 1
0
  /** ensure that non-Manual components of flow_tuple have equal dataRanges symmetric about 0.0 */
  public static void equalizeFlow(Vector mapVector, DisplayTupleType flow_tuple)
      throws VisADException, RemoteException {
    double[] range = new double[2];
    double low = Double.MAX_VALUE;
    double hi = -Double.MAX_VALUE;
    boolean anyAuto = false;

    Enumeration maps = mapVector.elements();
    while (maps.hasMoreElements()) {
      ScalarMap map = ((ScalarMap) maps.nextElement());
      DisplayRealType dtype = map.getDisplayScalar();
      DisplayTupleType tuple = dtype.getTuple();
      if (flow_tuple.equals(tuple) && !map.isManual && !map.badRange()) {
        anyAuto = true;
        low = Math.min(low, map.dataRange[0]);
        hi = Math.max(hi, map.dataRange[1]);
      }
    }
    if (!anyAuto) return;
    hi = Math.max(hi, -low);
    low = -hi;
    maps = mapVector.elements();
    while (maps.hasMoreElements()) {
      ScalarMap map = ((ScalarMap) maps.nextElement());
      DisplayRealType dtype = map.getDisplayScalar();
      DisplayTupleType tuple = dtype.getTuple();
      if (flow_tuple.equals(tuple) && !map.isManual && !map.badRange()) {
        map.setRange(null, low, hi, false);
      }
    }
  }
Ejemplo n.º 2
0
  public float[] makeVector(
      boolean south,
      float x,
      float y,
      float z,
      float scale,
      float pt_size,
      float f0,
      float f1,
      float[] vx,
      float[] vy,
      float[] vz,
      int[] numv,
      float[] tx,
      float[] ty,
      float[] tz,
      int[] numt) {

    float wsp25, slant, barb, d, c195, s195;
    float x0, y0;
    float x1, y1, x2, y2, x3, y3;
    int nbarb50, nbarb10, nbarb5;

    float[] mbarb = new float[4];
    mbarb[0] = x;
    mbarb[1] = y;

    if (getKnotsConvert()) {
      // convert meters per second to knots
      f0 *= (3600.0 / 1853.248);
      f1 *= (3600.0 / 1853.248);
    }

    float wnd_spd = (float) Math.sqrt(f0 * f0 + f1 * f1);
    int lenv = vx.length;
    int lent = tx.length;
    int nv = numv[0];
    int nt = numt[0];

    // determine the initial (minimum) length of the flag pole
    if (wnd_spd >= 2.5) {

      wsp25 = (float) Math.max(wnd_spd + 2.5, 5.0);
      slant = 0.15f * scale;
      barb = 0.4f * scale;
      // WLH 6 Aug 99 - barbs point the other way (duh)
      x0 = -f0 / wnd_spd;
      y0 = -f1 / wnd_spd;

      // plot the flag pole
      // lengthen to 'd = 3.0f * barb'
      // was 'd = barb' in original BOM code
      d = 3.0f * barb;
      x1 = (x + x0 * d);
      y1 = (y + y0 * d);

      /*
            // commented out in original BOM code
            vx[nv] = x;
            vy[nv] = y;
            vz[nv] = z;
            nv++;
            vx[nv] = x1;
            vy[nv] = y1;
            vz[nv] = z;
            nv++;
            // g.drawLine(x,y,x1,y1);
      */

      // determine number of wind barbs needed for 10 and 50 kt winds
      nbarb50 = (int) (wsp25 / 50.f);
      nbarb10 = (int) ((wsp25 - (nbarb50 * 50.f)) / 10.f);
      nbarb5 = (int) ((wsp25 - (nbarb50 * 50.f) - (nbarb10 * 10.f)) / 5.f);

      // 2.5 to 7.5 kt winds are plotted with the barb part way done the pole
      if (nbarb5 == 1) {
        barb = barb * 0.4f;
        slant = slant * 0.4f;
        x1 = (x + x0 * d);
        y1 = (y + y0 * d);

        if (south) {
          x2 = (x + x0 * (d + slant) - y0 * barb);
          y2 = (y + y0 * (d + slant) + x0 * barb);
        } else {
          x2 = (x + x0 * (d + slant) + y0 * barb);
          y2 = (y + y0 * (d + slant) - x0 * barb);
        }

        vx[nv] = x1;
        vy[nv] = y1;
        vz[nv] = z;
        nv++;
        vx[nv] = x2;
        vy[nv] = y2;
        vz[nv] = z;
        nv++;
        // System.out.println("barb5 " + x1 + " " + y1 + "" + x2 + " " + y2);
        // g.drawLine(x1, y1, x2, y2);
      }

      // add a little more pole
      if (wsp25 >= 5.0f && wsp25 < 10.0f) {
        d = d + 0.125f * scale;
        x1 = (x + x0 * d);
        y1 = (y + y0 * d);
        /* WLH 24 April 99
                vx[nv] = x;
                vy[nv] = y;
                vz[nv] = z;
                nv++;
                vx[nv] = x1;
                vy[nv] = y1;
                vz[nv] = z;
                nv++;
        */
        // System.out.println("wsp25 " + x + " " + y + "" + x1 + " " + y1);
        // g.drawLine(x, y, x1, y1);
      }

      // now plot any 10 kt wind barbs
      barb = 0.4f * scale;
      slant = 0.15f * scale;
      for (int j = 0; j < nbarb10; j++) {
        d = d + 0.125f * scale;
        x1 = (x + x0 * d);
        y1 = (y + y0 * d);
        if (south) {
          x2 = (x + x0 * (d + slant) - y0 * barb);
          y2 = (y + y0 * (d + slant) + x0 * barb);
        } else {
          x2 = (x + x0 * (d + slant) + y0 * barb);
          y2 = (y + y0 * (d + slant) - x0 * barb);
        }

        vx[nv] = x1;
        vy[nv] = y1;
        vz[nv] = z;
        nv++;
        vx[nv] = x2;
        vy[nv] = y2;
        vz[nv] = z;
        nv++;
        // System.out.println("barb10 " + j + " " + x1 + " " + y1 + "" + x2 + " " + y2);
        // g.drawLine(x1,y1,x2,y2);
      }
      /* WLH 24 April 99
            vx[nv] = x;
            vy[nv] = y;
            vz[nv] = z;
            nv++;
            vx[nv] = x1;
            vy[nv] = y1;
            vz[nv] = z;
            nv++;
      */
      // System.out.println("line " + x + " " + y + "" + x1 + " " + y1);
      // g.drawLine(x,y,x1,y1);

      // lengthen the pole to accomodate the 50 knot barbs
      if (nbarb50 > 0) {
        d = d + 0.125f * scale;
        x1 = (x + x0 * d);
        y1 = (y + y0 * d);
        /* WLH 24 April 99
                vx[nv] = x;
                vy[nv] = y;
                vz[nv] = z;
                nv++;
                vx[nv] = x1;
                vy[nv] = y1;
                vz[nv] = z;
                nv++;
        */
        // System.out.println("line50 " + x + " " + y + "" + x1 + " " + y1);
        // g.drawLine(x,y,x1,y1);
      }

      // plot the 50 kt wind barbs
      /* WLH 5 Nov 99
            s195 = (float) Math.sin(195 * Data.DEGREES_TO_RADIANS);
            c195 = (float) Math.cos(195 * Data.DEGREES_TO_RADIANS);
      */
      for (int j = 0; j < nbarb50; j++) {
        x1 = (x + x0 * d);
        y1 = (y + y0 * d);
        d = d + 0.3f * scale;
        x3 = (x + x0 * d);
        y3 = (y + y0 * d);
        /* WLH 5 Nov 99
                if (south) {
                  x2 = (x3+barb*(x0*s195+y0*c195));
                  y2 = (y3-barb*(x0*c195-y0*s195));
                }
                else {
                  x2 = (x3-barb*(x0*s195+y0*c195));
                  y2 = (y3+barb*(x0*c195-y0*s195));
                }
        */
        if (south) {
          x2 = (x + x0 * (d + slant) - y0 * barb);
          y2 = (y + y0 * (d + slant) + x0 * barb);
        } else {
          x2 = (x + x0 * (d + slant) + y0 * barb);
          y2 = (y + y0 * (d + slant) - x0 * barb);
        }

        float[] xp = {x1, x2, x3};
        float[] yp = {y1, y2, y3};

        tx[nt] = x1;
        ty[nt] = y1;
        tz[nt] = z;
        nt++;
        tx[nt] = x2;
        ty[nt] = y2;
        tz[nt] = z;
        nt++;
        tx[nt] = x3;
        ty[nt] = y3;
        tz[nt] = z;
        nt++;
        /*
        System.out.println("barb50 " + x1 + " " + y1 + "" + x2 + " " + y2 +
                         "  " + x3 + " " + y3);
        */
        // g.fillPolygon(xp,yp,3);
        // start location for the next barb
        x1 = x3;
        y1 = y3;
      }

      // grf 17 Nov 2003 change this to shorten the pole and print the speed
      if (noNumbers) {
        // WLH 24 April 99 - now plot the pole
        vx[nv] = x;
        vy[nv] = y;
        vz[nv] = z;
        nv++;
        vx[nv] = x1;
        vy[nv] = y1;
        vz[nv] = z;
        nv++;

        mbarb[2] = x1;
        mbarb[3] = y1;
      } else { // add numerical value to wind barbs
        // guess some factors to shorten the start of the pole
        float start_pole = 0.4f * scale;
        x1 = (x + x0 * start_pole);
        y1 = (y + y0 * start_pole);
        x2 = (x + x0 * d);
        y2 = (y + y0 * d);

        // draw the shaft
        vx[nv] = x1;
        vy[nv] = y1;
        vz[nv] = z;
        nv++;
        vx[nv] = x2;
        vy[nv] = y2;
        vz[nv] = z;
        nv++;

        mbarb[2] = x2;
        mbarb[3] = y2;

        // draw the speed to 1 dec place by default
        // Experimental factors in front of scale - get same as Swell
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(numDecPlaces);
        String speedString = nf.format((double) wnd_spd);
        // grf 2 Jun 2004 set z value the same as the barb
        double[] start = {x, y - 0.20 * scale, z};
        double[] base = {0.375 * scale, 0.0, 0.0};
        double up[] = {0.0, 0.375 * scale, 0.0};
        VisADLineArray array = PlotText.render_label(speedString, start, base, up, true);
        int nl = array.vertexCount;
        int k = 0;
        for (int i = 0; i < nl; i++) {
          vx[nv] = array.coordinates[k++];
          vy[nv] = array.coordinates[k++];
          vz[nv] = array.coordinates[k++];

          nv++;
        }
      }
    } else { // if (wnd_spd < 2.5)

      // wind < 2.5 kts.  Plot a circle
      float rad = (0.7f * pt_size);

      // draw 8 segment circle, center = (x, y), radius = rad
      // 1st segment
      vx[nv] = x - rad;
      vy[nv] = y;
      vz[nv] = z;
      nv++;
      vx[nv] = x - 0.7f * rad;
      vy[nv] = y + 0.7f * rad;
      vz[nv] = z;
      nv++;
      // 2nd segment
      vx[nv] = x - 0.7f * rad;
      vy[nv] = y + 0.7f * rad;
      vz[nv] = z;
      nv++;
      vx[nv] = x;
      vy[nv] = y + rad;
      vz[nv] = z;
      nv++;
      // 3rd segment
      vx[nv] = x;
      vy[nv] = y + rad;
      vz[nv] = z;
      nv++;
      vx[nv] = x + 0.7f * rad;
      vy[nv] = y + 0.7f * rad;
      vz[nv] = z;
      nv++;
      // 4th segment
      vx[nv] = x + 0.7f * rad;
      vy[nv] = y + 0.7f * rad;
      vz[nv] = z;
      nv++;
      vx[nv] = x + rad;
      vy[nv] = y;
      vz[nv] = z;
      nv++;
      // 5th segment
      vx[nv] = x + rad;
      vy[nv] = y;
      vz[nv] = z;
      nv++;
      vx[nv] = x + 0.7f * rad;
      vy[nv] = y - 0.7f * rad;
      vz[nv] = z;
      nv++;
      // 6th segment
      vx[nv] = x + 0.7f * rad;
      vy[nv] = y - 0.7f * rad;
      vz[nv] = z;
      nv++;
      vx[nv] = x;
      vy[nv] = y - rad;
      vz[nv] = z;
      nv++;
      // 7th segment
      vx[nv] = x;
      vy[nv] = y - rad;
      vz[nv] = z;
      nv++;
      vx[nv] = x - 0.7f * rad;
      vy[nv] = y - 0.7f * rad;
      vz[nv] = z;
      nv++;
      // 8th segment
      vx[nv] = x - 0.7f * rad;
      vy[nv] = y - 0.7f * rad;
      vz[nv] = z;
      nv++;
      vx[nv] = x - rad;
      vy[nv] = y;
      vz[nv] = z;
      nv++;
      // System.out.println("circle " + x + " " + y + "" + rad);
      // g.drawOval(x-rad,y-rad,2*rad,2*rad);

      mbarb[2] = x;
      mbarb[3] = y;
    }

    numv[0] = nv;
    numt[0] = nt;
    return mbarb;
  }