コード例 #1
0
ファイル: SphereWindow.java プロジェクト: jbudynk/starjava
  public PlotState getPlotState() {
    PlotState state = super.getPlotState();

    /* Modify ranges.  This is required because of confusion about what
     * axes mean between GraphicsWindow and SphereWindow. */
    if (state.getValid()) {
      double[][] bounds = state.getRanges();
      int naux = state.getShaders().length;
      Range[] viewRanges = getViewRanges();
      Range[] dataRanges = getDataRanges();
      boolean[] logFlags = state.getLogFlags();
      boolean[] flipFlags = state.getFlipFlags();
      int mainNdim = getMainRangeCount();
      for (int i = 0; i < naux; i++) {
        logFlags[mainNdim + i] = logFlags[3 + i];
        flipFlags[mainNdim + i] = flipFlags[3 + i];
        Range range = new Range(dataRanges[mainNdim + i]);
        range.limit(viewRanges[mainNdim + i]);
        bounds[mainNdim + i] = range.getFiniteBounds(logFlags[mainNdim + i]);
      }
    }
    return state;
  }
コード例 #2
0
ファイル: PlotStateFactory.java プロジェクト: and146/SPLAT
  /**
   * Updates a plot state generated by this factory with information generated from a first pass
   * through the data.
   *
   * @param state plot state to update
   * @param bounds data bounds calculated by a pass through the data
   */
  protected void configureFromBounds(PlotState state, DataBounds bounds) throws TaskException {
    PlotData plotData = state.getPlotData();
    int ndim = bounds.getRanges().length;
    int mainNdim = mainDimNames_.length;

    /* Update plot state range limits as required. */
    for (int idim = 0; idim < ndim; idim++) {
      boolean logFlag = state.getLogFlags()[idim];
      double[] stateRange = state.getRanges()[idim];
      double[] calcRange = bounds.getRanges()[idim].getFiniteBounds(logFlag);
      boolean loCalc = Double.isNaN(stateRange[0]);
      boolean hiCalc = Double.isNaN(stateRange[1]);
      String dimName = idim < mainNdim ? mainDimNames_[idim] : "Aux";
      if (loCalc) {
        if (!hiCalc && stateRange[1] <= calcRange[0]) {
          String msg =
              "Supplied "
                  + dimName
                  + " upper bound ("
                  + stateRange[1]
                  + ") is less than data lower bound ("
                  + calcRange[0]
                  + ")";
          throw new ExecutionException(msg);
        }
        stateRange[0] = calcRange[0];
      }
      if (hiCalc) {
        if (!loCalc && stateRange[0] >= calcRange[1]) {
          String msg =
              "Supplied "
                  + dimName
                  + " lower bound ("
                  + stateRange[0]
                  + ") is greater than data upper bound ("
                  + calcRange[1]
                  + ")";
          throw new ExecutionException(msg);
        }
        stateRange[1] = calcRange[1];
      }
      assert stateRange[0] <= stateRange[1];

      /* If lower and upper bounds are equal, nudge them down and up
       * respectively by an arbitrary amount. */
      if (stateRange[0] == stateRange[1]) {
        double val = stateRange[0];
        if (val == Math.floor(val)) {
          stateRange[0]--;
          stateRange[1]++;
        } else {
          stateRange[0] = Math.floor(val);
          stateRange[1] = Math.ceil(val);
        }
      }

      /* Otherwise, introduce padding for calculated bounds
       * for non-auxiliary axes only. */
      else {
        if (idim < mainNdim) {
          if (logFlag) {
            double pad = Math.pow(stateRange[1] / stateRange[0], PAD_RATIO);
            if (loCalc) {
              stateRange[0] /= pad;
            }
            if (hiCalc) {
              stateRange[1] *= pad;
            }
          } else {
            double pad = (stateRange[1] - stateRange[0]) * PAD_RATIO;
            if (loCalc) {
              stateRange[0] -= pad;
            }
            if (hiCalc) {
              stateRange[1] += pad;
            }
          }
        }
      }
      assert state.getRanges()[idim][0] < state.getRanges()[idim][1];
    }

    /* Update style configurations as required. */
    int nset = plotData.getSetCount();
    final Style[] styles = new Style[nset];
    int nAdjust = 0;
    for (int is = 0; is < nset; is++) {
      Style style = plotData.getSetStyle(is);
      if (requiresAdjustFromData(style)) {
        styles[is] = adjustFromData(style, is, bounds);
        nAdjust++;
      } else {
        styles[is] = style;
      }
    }
    if (nAdjust > 0) {
      state.setPlotData(
          new WrapperPlotData(plotData) {
            public Style getSetStyle(int is) {
              return styles[is];
            }
          });
    }
  }