示例#1
0
  /**
   * Set <CODE>Vector</CODE> of <CODE>String</CODE>s describing the cursor location from the cursor
   * location; this is invoked when the cursor location changes or the cursor display status changes
   */
  public void setCursorStringVector() {
    synchronized (cursorStringVector) {
      cursorStringVector.removeAllElements();
      float[][] cursor = new float[3][1];
      double[] cur = getCursor();
      cursor[0][0] = (float) cur[0];
      cursor[1][0] = (float) cur[1];
      cursor[2][0] = (float) cur[2];
      Enumeration maps = display.getMapVector().elements();
      while (maps.hasMoreElements()) {
        try {
          ScalarMap map = (ScalarMap) maps.nextElement();
          DisplayRealType dreal = map.getDisplayScalar();
          DisplayTupleType tuple = dreal.getTuple();
          int index = dreal.getTupleIndex();
          if (tuple != null
              && (tuple.equals(Display.DisplaySpatialCartesianTuple)
                  || (tuple.getCoordinateSystem() != null
                      && tuple
                          .getCoordinateSystem()
                          .getReference()
                          .equals(Display.DisplaySpatialCartesianTuple)))) {
            float[] fval = new float[1];
            if (tuple.equals(Display.DisplaySpatialCartesianTuple)) {
              fval[0] = cursor[index][0];
            } else {
              float[][] new_cursor = tuple.getCoordinateSystem().fromReference(cursor);
              fval[0] = new_cursor[index][0];
            }
            float[] dval = map.inverseScaleValues(fval);
            RealType real = (RealType) map.getScalar();

            // WLH 31 Aug 2000
            Real r = new Real(real, dval[0]);
            Unit overrideUnit = map.getOverrideUnit();
            Unit rtunit = real.getDefaultUnit();
            // units not part of Time string
            // DRM 2003-08-19: don't check for equality since toString
            // may be different
            if (overrideUnit != null
                && // !overrideUnit.equals(rtunit) &&
                (!Unit.canConvert(rtunit, CommonUnit.secondsSinceTheEpoch)
                    || rtunit.getAbsoluteUnit().equals(rtunit))) {
              dval[0] = (float) overrideUnit.toThis((double) dval[0], rtunit);
              r = new Real(real, dval[0], overrideUnit);
            }
            String valueString = r.toValueString();

            // WLH 27 Oct 2000
            String s = map.getScalarName() + " = " + valueString;
            // String s = real.getName() + " = " + valueString;

            cursorStringVector.addElement(s);
          } // end if (tuple != null && ...)
        } catch (VisADException e) {
        }
      } // end while(maps.hasMoreElements())
    } // end synchronized (cursorStringVector)
    render_trigger();
  }
示例#2
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);
      }
    }
  }
示例#3
0
 /**
  * Set color of axis scales; color must be float[3] with red,
  * green and blue components; DisplayScalar must be XAxis,
  * YAxis or ZAxis.  Preferred method is to use <CODE>AxisScale.setColor<CODE>
  * methods.
  * @param  color  array of R,G,B values of color.
  * @throws  VisADException  non-spatial DisplayScalar or wrong length
  *                          of color array
  * @see #getAxisScale()
  * @see visad.AxisScale#setColor(Color color)
  * @see visad.AxisScale#setColor(float[] color)
  */
 public void setScaleColor(float[] color) throws VisADException {
   if (!DisplayScalar.equals(Display.XAxis)
       && !DisplayScalar.equals(Display.YAxis)
       && !DisplayScalar.equals(Display.ZAxis)) {
     throw new DisplayException(
         "ScalarMap.setScaleColor: DisplayScalar " + "must be XAxis, YAxis or ZAxis");
   }
   if (color == null || color.length != 3) {
     throw new DisplayException("ScalarMap.setScaleColor: color is " + "null or wrong length");
   }
   // DRM 10-Oct 2000
   axisScale.setColor(color);
 }
 /** check for flow mappings; does not allow flow mapping through CoordinateSystem */
 private String findFlow(
     ShadowTupleType shadow,
     DisplayImpl display,
     DisplayTupleType[] tuples,
     int[] flowToComponent) {
   ShadowRealType[] components = shadow.getRealComponents();
   for (int i = 0; i < components.length; i++) {
     int num_flow_per_real = 0;
     Enumeration maps = components[i].getSelectedMapVector().elements();
     while (maps.hasMoreElements()) {
       ScalarMap map = (ScalarMap) maps.nextElement();
       DisplayRealType dreal = map.getDisplayScalar();
       DisplayTupleType tuple = dreal.getTuple();
       if (Display.DisplayFlow1Tuple.equals(tuple) || Display.DisplayFlow2Tuple.equals(tuple)) {
         if (tuples[0] != null) {
           if (!tuples[0].equals(tuple)) {
             return multipleFlowTuples;
           }
         } else {
           tuples[0] = tuple;
         }
         num_flow_per_real++;
         if (num_flow_per_real > 1) {
           return multipleFlowMapping;
         }
         int index = dreal.getTupleIndex();
         flowToComponent[index] = i;
         directMap[index] = map;
       } else if (Display.DisplayFlow1SphericalTuple.equals(tuple)
           || Display.DisplayFlow2SphericalTuple.equals(tuple)) {
         if (tuples[0] != null) {
           if (!tuples[0].equals(tuple)) {
             return multipleFlowTuples;
           }
         } else {
           tuples[0] = tuple;
           coord = tuple.getCoordinateSystem();
         }
         num_flow_per_real++;
         if (num_flow_per_real > 1) {
           return multipleFlowMapping;
         }
         int index = dreal.getTupleIndex();
         flowToComponent[index] = i;
         directMap[index] = map;
       }
     } // while (maps.hasMoreElements())
   }
   return null;
 }
示例#5
0
 /**
  * Return <CODE>true</CODE> if <CODE>type</CODE> is legal for this <CODE>DisplayRenderer</CODE>;
  * for example, 2-D <CODE>DisplayRenderer</CODE>s use this to disallow mappings to <I>ZAxis</I>
  * and <I>Latitude</I>.
  *
  * @param type The mapping type to check.
  * @return <CODE>true</CODE> if <CODE>type</CODE> is legal.
  */
 public boolean legalDisplayScalar(DisplayRealType type) {
   // First check to see if it is a member of the default list
   for (int i = 0; i < Display.DisplayRealArray.length; i++) {
     if (Display.DisplayRealArray[i].equals(type)) return true;
   }
   // if we get here, it's not one of the defaults.  See if it has
   // a CS that transforms to a default that we know how to handle
   if (type.getTuple() != null && type.getTuple().getCoordinateSystem() != null) {
     RealTupleType ref = type.getTuple().getCoordinateSystem().getReference();
     if (ref.equals(Display.DisplaySpatialCartesianTuple)
         || ref.equals(Display.DisplayRGBTuple)
         || ref.equals(Display.DisplayFlow1Tuple)
         || ref.equals(Display.DisplayFlow2Tuple)) return true;
   }
   return false;
 }
示例#6
0
  /**
   * set aspect ratio of XAxis, YAxis & ZAxis in ScalarMaps rather than matrix (i.e., don't distort
   * text fonts); won't work for spherical, polar, cylindrical coordinates
   *
   * @param aspect ratios; 3 elements for Java3D, 2 for Java2D
   * @throws VisADException a VisAD error occurred
   * @throws RemoteException an RMI error occurred
   */
  void setAspectCartesian(double[] aspect) throws VisADException, RemoteException {
    double asp = Double.NaN;
    if (DisplayScalar.equals(Display.XAxis)) asp = aspect[0];
    if (DisplayScalar.equals(Display.YAxis)) asp = aspect[1];
    if (DisplayScalar.equals(Display.ZAxis)) asp = aspect[2];
    if (asp == asp) {
      isScaled = DisplayScalar.getRange(displayRange);
      displayRange[0] *= asp;
      displayRange[1] *= asp;
      computeScaleAndOffset();

      makeScale();
      // needs work in AxisScale ****
    }
    // note XAxis, YAxis and ZAxis have no unit, so cannot be setRangeByUnits()
  }
示例#7
0
  /**
   * Returns the hash code for this ScalarMap. If <code>scalarMap1.equals(
   * scalarMap2)</code> is true, then <code>scalarMap1.hashCode() ==
   * scalarMap2.hashCode()</code>.
   *
   * @return The hash code for this ScalarMap.
   */
  public int hashCode() {
    ScalarType s = getScalar();
    DisplayRealType ds = getDisplayScalar();

    int hash = 0;
    if (s != null) {
      if (ds != null) {
        hash = s.hashCode() ^ ds.hashCode();
      } else {
        hash = s.hashCode();
      }
    } else if (ds != null) {
      hash = ds.hashCode();
    }

    return hash;
  }
示例#8
0
 ScalarMap(ScalarType scalar, DisplayRealType display_scalar, boolean needNonNullScalar)
     throws VisADException {
   if (scalar == null && needNonNullScalar) {
     throw new DisplayException("ScalarMap: scalar is null");
   }
   if (display_scalar == null) {
     throw new DisplayException("ScalarMap: display_scalar is null");
   }
   if (display_scalar.equals(Display.List)) {
     throw new DisplayException("ScalarMap: display_scalar may not be List");
   }
   boolean text = display_scalar.getText();
   if (scalar != null) {
     /* WLH 15 June 2000
           if (text && !(scalar instanceof TextType)) {
             throw new DisplayException("ScalarMap: RealType scalar cannot be " +
                                        "used with TextType display_scalar");
           }
     */
     if (!text && !(scalar instanceof RealType)) {
       throw new DisplayException(
           "ScalarMap: TextType scalar cannot be " + "used with RealType display_scalar");
     }
   }
   control = null;
   Scalar = scalar;
   DisplayScalar = display_scalar;
   display = null;
   ScalarIndex = -1;
   DisplayScalarIndex = -1;
   isScaled = DisplayScalar.getRange(displayRange);
   isManual = false;
   dataRange[0] = Double.NaN;
   dataRange[1] = Double.NaN;
   defaultUnitRange[0] = dataRange[0];
   defaultUnitRange[1] = dataRange[1];
   OldTick = Long.MIN_VALUE;
   NewTick = Long.MIN_VALUE + 1;
   tickFlag = false;
   if (Scalar != null) scalarName = Scalar.getName();
   if (DisplayScalar.equals(Display.XAxis)
       || DisplayScalar.equals(Display.YAxis)
       || DisplayScalar.equals(Display.ZAxis)) {
     axisScale = new AxisScale(this);
   }
 }
示例#9
0
 /**
  * explicitly set the range of data (RealType) values; used for linear map from Scalar to
  * DisplayScalar values; if neither this nor setRangeByUnits is invoked, then the range will be
  * computed from the initial values of Data objects linked to the Display by autoscaling logic; if
  * the range of data values is (0.0, 1.0), for example, this method may be invoked with low = 1.0
  * and hi = 0.0 to invert the display scale .
  *
  * @param low lower range value (see notes above)
  * @param hi upper range value (see notes above)
  * @param remoteId id of remote scale
  * @throws VisADException VisAD error
  * @throws RemoteException Java RMI error
  */
 public void setRange(double low, double hi, int remoteId) throws VisADException, RemoteException {
   if (DisplayScalar.equals(Display.Animation)) {
     System.err.println("Warning: setRange on " + "ScalarMap to Display.Animation has no effect.");
     return;
   }
   isManual = true;
   setRange(null, low, hi, false, remoteId);
   if (scale == scale && offset == offset) {
     incTick(); // did work, so wake up Display
   } else {
     isManual = false; // didn't work, so don't lock out auto-scaling
   }
 }
示例#10
0
 public boolean badRange() {
   // WLH 15 Feb 2002
   boolean bad = (isScaled && (scale != scale || offset != offset));
   if (DisplayScalar.equals(Display.Animation)) {
     if (control != null) {
       Set set = ((AnimationControl) control).getSet();
       bad |= (set == null);
     } else {
       bad = true;
     }
   }
   return bad;
   // return (isScaled && (scale != scale || offset != offset));
 }
示例#11
0
 // WLH 22 August 2001
 public boolean doInitialize() {
   if (DisplayScalar.equals(Display.IsoContour)) {
     if (control != null) {
       float[] lowhibase = new float[3];
       boolean[] dashes = new boolean[1];
       float[] levs = ((ContourControl) control).getLevels(lowhibase, dashes);
       return (levs == null);
     } else {
       return false;
     }
   } else {
     return isScaled && !isManual;
   }
 }
示例#12
0
 /**
  * Initialize the lat/lon scalar maps
  *
  * @throws RemoteException On badness
  * @throws VisADException On badness
  */
 public void initLatLonMap() throws VisADException, RemoteException {
   if (latMap != null) {
     return;
   }
   if (getDisplayMaster() == null) {
     return;
   }
   boolean callScale = (latMap == null);
   DisplayImpl display = (DisplayImpl) getDisplayMaster().getDisplay();
   // find spatial maps for Latitude and Longitude
   latMap = null;
   lonMap = null;
   Vector scalar_map_vector = display.getMapVector();
   Enumeration en = scalar_map_vector.elements();
   while (en.hasMoreElements()) {
     ScalarMap map = (ScalarMap) en.nextElement();
     DisplayRealType real = map.getDisplayScalar();
     DisplayTupleType tuple = real.getTuple();
     if ((tuple != null)
         && (tuple.equals(Display.DisplaySpatialCartesianTuple)
             || ((tuple.getCoordinateSystem() != null)
                 && tuple
                     .getCoordinateSystem()
                     .getReference()
                     .equals(Display.DisplaySpatialCartesianTuple)))) { // Spatial
       if (RealType.Latitude.equals(map.getScalar())) {
         latMap = map;
       } else if (RealType.Longitude.equals(map.getScalar())) {
         lonMap = map;
       }
     }
   }
   if (callScale) {
     setScale(baseScale);
   }
 }
示例#13
0
  /** set range used for linear map from Scalar to DisplayScalar values */
  private synchronized void setRange(
      DataShadow shadow, double low, double hi, boolean unit_flag, int remoteId)
      throws VisADException, RemoteException {
    int i = ScalarIndex;
    if (shadow != null) {
      // WLH - 23 Sept 99
      if (DisplayScalar.equals(Display.Latitude) || DisplayScalar.equals(Display.Longitude)) {
        Unit data_unit = (Scalar instanceof RealType) ? ((RealType) Scalar).getDefaultUnit() : null;
        Unit display_unit = DisplayScalar.getDefaultUnit();
        if (data_unit != null && display_unit != null && Unit.canConvert(data_unit, display_unit)) {
          dataRange[0] = data_unit.toThis(displayRange[0], display_unit);
          dataRange[1] = data_unit.toThis(displayRange[1], display_unit);
        } else {
          if (i < 0 || i >= shadow.ranges[0].length) return;
          dataRange[0] = shadow.ranges[0][i];
          dataRange[1] = shadow.ranges[1][i];
        }
      } else {
        if (i < 0 || i >= shadow.ranges[0].length) return;
        dataRange[0] = shadow.ranges[0][i];
        dataRange[1] = shadow.ranges[1][i];
      }
    } else if (unit_flag) {
      Unit data_unit = (Scalar instanceof RealType) ? ((RealType) Scalar).getDefaultUnit() : null;
      Unit display_unit = DisplayScalar.getDefaultUnit();
      if (data_unit == null || display_unit == null) {
        throw new UnitException("ScalarMap.setRangeByUnits: null Unit");
      }
      dataRange[0] = data_unit.toThis(displayRange[0], display_unit);
      dataRange[1] = data_unit.toThis(displayRange[1], display_unit);
      /*
      System.out.println("data_unit = " + data_unit + " display_unit = " + display_unit);
      System.out.println("dataRange = " + dataRange[0] + " " + dataRange[1] +
      " displayRange = " + displayRange[0] + " " + displayRange[1]);
      */
    } else {
      dataRange[0] = low;
      dataRange[1] = hi;
      // WLH 31 Aug 2000
      // manual range is in overrideUnit. so convert to Scalar default Unit
      if (overrideUnit != null) {
        dataRange[0] = (dataRange[0] - override_offset) / override_scale;
        dataRange[1] = (dataRange[1] - override_offset) / override_scale;
      }
    }
    /*
    if (shadow != null || remoteId != VisADEvent.LOCAL_SOURCE) {
      System.out.println(Scalar + " -> " + DisplayScalar + " range: " + dataRange[0] +
                         " to " + dataRange[1] + " " + display.getName());
    }
    */
    // at this point dataRange is range for Scalar default Unit
    //   even if (overrideUnit != null)
    // DRM 17 Feb 2006 - so set the defaultUnitRange to be these values.
    defaultUnitRange[0] = dataRange[0];
    defaultUnitRange[1] = dataRange[1];
    if (defaultUnitRange[0] == defaultUnitRange[1]) {
      double half = defaultUnitRange[0] / 2000.0;
      if (half < 0.5) half = 0.5;
      defaultUnitRange[0] -= half;
      defaultUnitRange[1] += half;
    }

    if (isScaled) {
      computeScaleAndOffset();
    } else { // if (!isScaled)
      if (dataRange[0] == Double.MAX_VALUE || dataRange[1] == -Double.MAX_VALUE) {
        dataRange[0] = Double.NaN;
        dataRange[1] = Double.NaN;
      }

      // WLH 31 Aug 2000
      if (overrideUnit != null) {
        // now convert dataRange to overrideUnit
        dataRange[0] = defaultUnitRange[0] * override_scale + override_offset;
        dataRange[1] = defaultUnitRange[1] * override_scale + override_offset;
      }
    }
    /*
    System.out.println(Scalar + " -> " + DisplayScalar + " range: " + dataRange[0] +
                       " to " + dataRange[1] + " scale: " + scale + " " + offset);
    */
    if (DisplayScalar.equals(Display.Animation) && shadow != null) {
      if (control != null && ((AnimationControl) control).getComputeSet()) {
        Set set = shadow.animationSampling;
        /* DRM: 04 Jan 2003
        if (set == null) {
          return;
        }
        */
        ((AnimationControl) control).setSet(set, true);
      }
    } else if (DisplayScalar.equals(Display.IsoContour)) {
      if (control != null) {

        // WLH 10 July 2002
        // don't set if application has called control.setLevels()
        float[] lowhibase = new float[3];
        boolean[] dashes = new boolean[1];

        boolean public_set = ((ContourControl) control).getPublicSet();
        if (!public_set) {
          boolean[] bvalues = new boolean[2];
          float[] values = new float[5];
          ((ContourControl) control).getMainContours(bvalues, values);
          if (shadow == null) {
            // don't set surface value for auto-scale
            values[0] = (float) dataRange[0]; // surfaceValue
          }
          // CTR: 29 Jul 1999: interval should never be zero
          float f = (float) (dataRange[1] - dataRange[0]) / 10.0f;
          if (f != 0.0f) values[1] = f; // contourInterval
          values[2] = (float) dataRange[0]; // lowLimit
          values[3] = (float) dataRange[1]; // hiLimit
          values[4] = (float) dataRange[0]; // base
          ((ContourControl) control).setMainContours(bvalues, values, true, true);
        }
      }
    } else if (DisplayScalar.equals(Display.XAxis)
        || DisplayScalar.equals(Display.YAxis)
        || DisplayScalar.equals(Display.ZAxis)) {
      if (dataRange[0] != Double.MAX_VALUE
          && dataRange[1] != -Double.MAX_VALUE
          && dataRange[0] == dataRange[0]
          && dataRange[1] == dataRange[1]
          && dataRange[0] != dataRange[1]
          && scale == scale
          && offset == offset) {
        if (display != null) {
          makeScale();
        } else {
          scale_flag = true;
        }
        back_scale_flag = true;
      }
    }

    if (dataRange[0] == dataRange[0] && dataRange[1] == dataRange[1] && ListenerVector != null) {
      ScalarMapEvent evt;
      evt =
          new ScalarMapEvent(
              this, (shadow == null ? ScalarMapEvent.MANUAL : ScalarMapEvent.AUTO_SCALE), remoteId);
      Vector listeners_clone = null;
      synchronized (ListenerVector) {
        listeners_clone = (Vector) ListenerVector.clone();
      }
      Enumeration listeners = listeners_clone.elements();
      while (listeners.hasMoreElements()) {
        ScalarMapListener listener = (ScalarMapListener) listeners.nextElement();
        listener.mapChanged(evt);
      }
    }
  }
示例#14
0
 /**
  * Returns a string representation of the ScalarMap with the specified prefix prepended.
  *
  * @param pre prefix to prepend to the representation
  * @return a string that "textually represents" this ScalarMap with <CODE>pre</CODE> prepended.
  */
 public String toString(String pre) {
   return pre + "ScalarMap: " + Scalar.toString() + " -> " + DisplayScalar.toString() + "\n";
 }