Exemplo n.º 1
0
  /**
   * Robustly make a curve to a front
   *
   * @param curve the curve
   * @param flip true to flip the pips
   * @return the resulting front as a FieldImpl
   * @throws RemoteException On badness
   */
  public FieldImpl robustCurveToFront(float[][] curve, boolean flip) throws RemoteException {

    // resample curve uniformly along length
    float increment = rsegment_length / (rprofile_length * zoom);
    float[][] oldCurve = null;
    try {
      oldCurve = resample_curve(curve, increment);
    } catch (VisADError ve) { // bad curve
      return null;
    }

    int fw = filter_window;
    fw = 1;
    FieldImpl front = null;

    float[][] originalCurve = curve;

    debug = true;
    for (int tries = 0; tries < 12; tries++) {
      // lowpass filter curve
      curve = smooth_curve(oldCurve, fw);
      // resample smoothed curve
      curve = resample_curve(curve, increment);
      try {
        front = curveToFront(curve, flip);
        break;
      } catch (VisADException e) {
        oldCurve = curve;
        if (tries > 4) {
          int n = oldCurve[0].length;
          if (n > 2) {
            float[][] no = new float[2][n - 2];
            System.arraycopy(oldCurve[0], 1, no[0], 0, n - 2);
            System.arraycopy(oldCurve[1], 1, no[1], 0, n - 2);
            oldCurve = no;
          }
        }
        if (tries > 8) {
          fw = 2 * fw;
        }
        // if (debug) System.out.println("retry filter window = " + fw + " " + e);
        if (tries == 9) {
          //                    System.out.println("cannot smooth curve");
          front = null;
        }
      }
    }
    return front;
  }
Exemplo n.º 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());
     }
   }
 }
Exemplo n.º 3
0
 /**
  * attempt to invoke a Method with the given Object arguments, performing static method
  * auto-detection and automatic array compression
  */
 public static Object invokeMethod(Method m, Object[] o)
     throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
   Object obj;
   Object[] args;
   Class[] c = m.getParameterTypes();
   int num = (o == null) ? 0 : o.length;
   int len = -1;
   int a = -1;
   if (c != null) {
     len = c.length;
     for (int i = 0; i < len; i++) {
       if (c[i].isArray()) a = i;
     }
   }
   if (Modifier.isStatic(m.getModifiers())) {
     // static method
     obj = null;
     if (num > 0) {
       if (a < 0) {
         args = new Object[num];
         System.arraycopy(o, 0, args, 0, num);
       } else {
         // compress some of the arguments into array form
         args = new Object[len];
         if (a > 0) System.arraycopy(o, 0, args, 0, a);
         Object array = Array.newInstance(c[a].getComponentType(), num - len + 1);
         System.arraycopy(o, a, array, 0, num - len + 1);
         args[a] = array;
         if (a < len - 1) System.arraycopy(o, num - len + a + 1, args, a + 1, len - a - 1);
       }
     } else args = null;
   } else {
     // object method
     if (num > 0) obj = o[0];
     else {
       // invalid object method
       return null;
     }
     if (num > 1) {
       if (a < 0) {
         args = new Object[num - 1];
         System.arraycopy(o, 1, args, 0, num - 1);
       } else {
         // compress some of the arguments into array form
         args = new Object[len];
         if (a > 0) System.arraycopy(o, 1, args, 0, a);
         Object array = Array.newInstance(c[a].getComponentType(), num - len);
         System.arraycopy(o, a + 1, array, 0, num - len);
         args[a + 1] = array;
         if (a < len - 1) System.arraycopy(o, num - len + a + 1, args, a + 1, len - a - 1);
       }
     } else args = null;
   }
   return m.invoke(obj, args);
 }
Exemplo n.º 4
0
 /**
  * Utility to make a set
  *
  * @param sets List of sets
  * @return The set of sets
  * @throws VisADException On badness
  */
 public static UnionSet makeSet(List sets) throws VisADException {
   if (sets == null) {
     return null;
   }
   SampledSet[] ss = new SampledSet[sets.size()];
   System.arraycopy(sets.toArray(), 0, ss, 0, sets.size());
   if (ss.length > 0) {
     return new UnionSet(ss[0].getType(), ss, null, null, null, false);
   } else {
     return null;
   }
 }
Exemplo n.º 5
0
  /**
   * @param grid The grid.
   * @param gridWinds The grid-relative winds.
   * @param cs The coordinate system transformation of the grid.
   * @param index The index of the grid-relative wind component.
   * @param latI The index of latitude in the reference coordinate system.
   * @param lonI The index of longitude in the reference coordinate system.
   * @param us The array in which to add the computed U-component of the wind.
   * @param us The array in which to add the computed V-component of the wind.
   * @param vs
   * @throws IndexOutOfBoundsException if <code>gridWinds</code>, <code>us
   *                                   </code>, or <code>vs</code> is too small.
   * @throws VisADException if a VisAD failure occurs.
   */
  private static void addComponent(
      SampledSet grid,
      float[][] gridWinds,
      CoordinateSystem cs,
      int index,
      int latI,
      int lonI,
      float[] us,
      float[] vs)
      throws VisADException {

    int[][] neighbors = grid.getNeighbors(index);
    LatLonPointImpl refPt = new LatLonPointImpl();
    LatLonPointImpl neiPt = new LatLonPointImpl();
    Bearing bearing = new Bearing();
    float[] uv1 = new float[2];
    float[] uv2 = new float[2];
    boolean hasCS = cs != null;
    float[][] domainSamples = grid.getSamples(false);
    float[][] crefCoords = (hasCS) ? cs.toReference(Set.copyFloats(domainSamples)) : domainSamples;
    // If the grid is lat/lon or has an IdentityCoordinateSystem
    // don't do the rotation
    // TODO:  handle rotated lat/lon grids
    if (!hasCS
        || (crefCoords == domainSamples)
        || (Arrays.equals(crefCoords[latI], domainSamples[latI])
            && Arrays.equals(crefCoords[lonI], domainSamples[lonI]))) {
      // us = gridWinds[0];
      // vs = gridWinds[1];
      System.arraycopy(gridWinds[0], 0, us, 0, us.length);
      System.arraycopy(gridWinds[1], 0, vs, 0, vs.length);
    } else {

      for (int i = 0; i < neighbors.length; i++) {

        float[][] refCoords = grid.indexToValue(new int[] {i});
        if (hasCS) {
          refCoords = cs.toReference(refCoords);
        }

        float[][] neiCoords = grid.indexToValue(neighbors[i]);
        if (hasCS) {
          neiCoords = cs.toReference(neiCoords);
        }

        refPt.set(refCoords[latI][0], refCoords[lonI][0]);

        compute(
            refPt,
            neiPt,
            neiCoords[latI][0],
            neiCoords[lonI][0],
            -180,
            gridWinds[index][i],
            bearing,
            uv1);

        float d1 = (float) bearing.getDistance();

        compute(
            refPt,
            neiPt,
            neiCoords[latI][1],
            neiCoords[lonI][1],
            0,
            gridWinds[index][i],
            bearing,
            uv2);

        float d2 = (float) bearing.getDistance();
        boolean bad1 = Double.isNaN(d1);
        boolean bad2 = Double.isNaN(d2);

        if (bad1 && bad2) {
          us[i] = Float.NaN;
          vs[i] = Float.NaN;
        } else {
          if (bad1) {
            us[i] += uv2[0];
            vs[i] += uv2[1];
          } else if (bad2) {
            us[i] += uv1[0];
            vs[i] += uv1[1];
          } else {
            float tot = d1 + d2;
            float c1 = d2 / tot;
            float c2 = d1 / tot;

            us[i] += c1 * uv1[0] + c2 * uv2[0];
            vs[i] += c1 * uv1[1] + c2 * uv2[1];
          }
        }
      }
    }
  }
Exemplo n.º 6
0
  /**
   * Set the front state
   *
   * @param fsegment length of first segment in graphics coord
   * @param rsegment length of repeating segment in graphics coord
   * @param fshapes shapes of the front
   * @param fred first reds
   * @param fgreen first greens
   * @param fblue first blues
   * @param rshapes repeating shapes
   * @param rred repeating reds
   * @param rgreen repeating greens
   * @param rblue repeating blues
   * @throws RemoteException On badness
   * @throws VisADException On badness
   */
  private void setFrontState(
      float fsegment,
      float rsegment,
      float[][][] fshapes,
      float[] fred,
      float[] fgreen,
      float[] fblue,
      float[][][] rshapes,
      float[] rred,
      float[] rgreen,
      float[] rblue)
      throws VisADException, RemoteException {
    fsegment_length = fsegment;
    rsegment_length = rsegment;
    nrshapes = rshapes.length;
    for (int i = 0; i < nrshapes; i++) {
      if ((rshapes[i] == null)
          || (rshapes[i].length != 2)
          || (rshapes[i][0] == null)
          || (rshapes[i][1] == null)
          || (rshapes[i][0].length != rshapes[i][1].length)) {
        throw new VisADException("bad rshapes[" + i + "]");
      }
    }
    if ((rred == null)
        || (rred.length != nrshapes)
        || (rgreen == null)
        || (rgreen.length != nrshapes)
        || (rblue == null)
        || (rblue.length != nrshapes)) {
      throw new VisADException("bad rcolors");
    }
    repeat_tris = new int[nrshapes][][];
    for (int i = 0; i < nrshapes; i++) {
      repeat_tris[i] = DelaunayCustom.fill(rshapes[i]);
    }
    repeat_shapes = new float[nrshapes][2][];
    int rlen = 0;
    for (int i = 0; i < nrshapes; i++) {
      int n = rshapes[i][0].length;
      rlen += n;
      repeat_shapes[i][0] = new float[n];
      repeat_shapes[i][1] = new float[n];
      System.arraycopy(rshapes[i][0], 0, repeat_shapes[i][0], 0, n);
      System.arraycopy(rshapes[i][1], 0, repeat_shapes[i][1], 0, n);
    }
    rprofile_length = rlen;
    repeat_red = new float[nrshapes];
    repeat_green = new float[nrshapes];
    repeat_blue = new float[nrshapes];
    System.arraycopy(rred, 0, repeat_red, 0, nrshapes);
    System.arraycopy(rgreen, 0, repeat_green, 0, nrshapes);
    System.arraycopy(rblue, 0, repeat_blue, 0, nrshapes);

    if (fshapes == null) {
      // if no different first shapes, just use repeat shapes
      nfshapes = nrshapes;
      first_tris = repeat_tris;
      first_shapes = repeat_shapes;
      first_red = repeat_red;
      first_green = repeat_green;
      first_blue = repeat_blue;
    } else {
      nfshapes = fshapes.length;
      for (int i = 0; i < nfshapes; i++) {
        if ((fshapes[i] == null)
            || (fshapes[i].length != 2)
            || (fshapes[i][0] == null)
            || (fshapes[i][1] == null)
            || (fshapes[i][0].length != fshapes[i][1].length)) {
          throw new VisADException("bad fshapes[" + i + "]");
        }
      }
      if ((fred == null)
          || (fred.length != nfshapes)
          || (fgreen == null)
          || (fgreen.length != nfshapes)
          || (fblue == null)
          || (fblue.length != nfshapes)) {
        throw new VisADException("bad fcolors");
      }
      first_tris = new int[nfshapes][][];
      for (int i = 0; i < nfshapes; i++) {
        first_tris[i] = DelaunayCustom.fill(fshapes[i]);
      }
      first_shapes = new float[nfshapes][2][];
      int flen = 0;
      for (int i = 0; i < nfshapes; i++) {
        int n = fshapes[i][0].length;
        flen += n;
        first_shapes[i][0] = new float[n];
        first_shapes[i][1] = new float[n];
        System.arraycopy(fshapes[i][0], 0, first_shapes[i][0], 0, n);
        System.arraycopy(fshapes[i][1], 0, first_shapes[i][1], 0, n);
      }
      fprofile_length = flen;
      first_red = new float[nfshapes];
      first_green = new float[nfshapes];
      first_blue = new float[nfshapes];
      System.arraycopy(fred, 0, first_red, 0, nfshapes);
      System.arraycopy(fgreen, 0, first_green, 0, nfshapes);
      System.arraycopy(fblue, 0, first_blue, 0, nfshapes);
    }
    if (rprofile_length < 5) {
      rprofile_length = 5;
    }
    if (fprofile_length < 5) {
      fprofile_length = 5;
    }
  }