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
  /**
   * 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;
    }
  }