Ejemplo 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;
  }
Ejemplo 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());
     }
   }
 }
Ejemplo n.º 3
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;
    }
  }