/** * set the default sampling; this is an unavoidable violation of MathType immutability - a * RealTupleType must be an argument (directly or through a SetType) to the constructor of its * default Set; this method throws an Exception if getDefaultSet has previously been invoked */ public synchronized void setDefaultSet(Set sampling) throws VisADException { if (sampling.getDimension() != getDimension()) { throw new SetException("RealTupleType.setDefaultSet: dimensions don't match"); } if (DefaultSetEverAccessed) { throw new TypeException("RealTupleType: DefaultSet already accessed" + " so cannot change"); } DefaultSet = sampling; /* WLH 4 Feb 98 copied from constructor */ if (DefaultSet != null && !Unit.canConvertArray(DefaultSet.getSetUnits(), DefaultUnits)) { throw new UnitException( "RealTupleType: default Set Units must be " + "convertable with default Units"); } if (DefaultCoordinateSystem != null && DefaultSet != null) { CoordinateSystem cs = DefaultSet.getCoordinateSystem(); if (cs != null && !cs.getReference().equals(DefaultCoordinateSystem.getReference())) { throw new CoordinateSystemException( "RealTupleType: Default coordinate system " + DefaultCoordinateSystem.getReference() + " must match" + " default set CoordinateSystem " + (cs == null ? null : cs.getReference())); } if (!Unit.canConvertArray( DefaultCoordinateSystem.getCoordinateSystemUnits(), DefaultSet.getSetUnits())) { throw new UnitException( "RealTupleType: CoordinateSystem Units must be " + "convertable with default Set Units"); } } }
/** * Set display Unit to override default Unit of Scalar; MUST be called before any data are * displayed * * @param unit unit that data will be displayed with * @throws VisADException <CODE>unit</CODE> is not convertable with the default unit or scalar is * not a RealType. */ public void setOverrideUnit(Unit unit) throws VisADException { if (!(Scalar instanceof RealType)) { throw new UnitException("Scalar is not RealType"); } Unit rtunit = ((RealType) Scalar).getDefaultUnit(); if (!Unit.canConvert(unit, rtunit)) { throw new UnitException("unit not convertable with RealType default"); } if (unit != null) { overrideUnit = unit; override_offset = overrideUnit.toThis(0.0, rtunit); override_scale = overrideUnit.toThis(1.0, rtunit) - override_offset; } }
/** * return an array of data (RealType) values by inverse linear scaling (if applicable) the * display_values array (DisplayRealType values); this is useful for direct manipulation and * cursor labels * * @param values display values * @param newArray false to transform in place * @return data values */ public float[] inverseScaleValues(float[] values, boolean newArray) { if (values == null) return null; float[] new_values = (newArray) ? new float[values.length] : values; if (isScaled) { for (int i = 0; i < values.length; i++) { if (values[i] == values[i]) { new_values[i] = (float) ((values[i] - offset) / scale); } else { new_values[i] = Float.NaN; } } } else { if (newArray) { for (int i = 0; i < values.length; i++) { new_values[i] = values[i]; } } } // WLH 31 Aug 2000 if (overrideUnit != null) { // float[] old_values = new_values; try { new_values = overrideUnit.toThat( new_values, ((RealType) Scalar).getDefaultUnit(), false); // already copied above } catch (UnitException e) { } /* System.out.println("inverse values = " + values[0] + " " + old_values[0] + " " + new_values[0]); */ } return new_values; }
/** * return an array of display (DisplayRealType) values by linear scaling (if applicable) the * data_values array (RealType values); results are scaled by the given scale factor * * @param values to scale as bytes * @return array of display values */ public byte[] scaleValues(byte[] values, int factor) throws VisADException { if (values == null) return null; byte[] new_values = null; if (badRange()) { new_values = new byte[values.length]; } else { if (overrideUnit != null && !overrideUnit.equals(((RealType) Scalar).getDefaultUnit())) { throw new VisADException("scaleValues(byte[]): non-default units not supported"); } if (isScaled) { new_values = new byte[values.length]; for (int i = 0; i < values.length; i++) { float v = (float) values[i]; if (v < 0) v += 256; v = (float) (factor * (offset + scale * v)); if (v < 0) v = 0; else if (v > 255) v = 255; new_values[i] = (byte) v; } } else { new_values = values; } } return new_values; }
/** * return an array of display (DisplayRealType) values by linear scaling (if applicable) the * data_values array (RealType values) * * @param values to scale as floats * @param newArray false to scale in place * @return array of display values */ public float[] scaleValues(float[] values, boolean newArray) { /* WLH 23 June 99 if (values == null || badRange()) return null; */ if (values == null) return null; float[] new_values = null; if (badRange()) { new_values = (newArray) ? new float[values.length] : values; for (int i = 0; i < values.length; i++) new_values[i] = Float.NaN; } else { // float[] old_values = values; // WLH 31 Aug 2000 // if (overrideUnit != null) { // DRM 11 Jun 2003 if (overrideUnit != null && !overrideUnit.equals(((RealType) Scalar).getDefaultUnit())) { try { values = overrideUnit.toThis(values, ((RealType) Scalar).getDefaultUnit(), newArray); } catch (UnitException e) { } } if (isScaled) { new_values = (newArray) ? new float[values.length] : values; for (int i = 0; i < values.length; i++) { if (values[i] == values[i]) { new_values[i] = (float) (offset + scale * values[i]); } else { new_values[i] = Float.NaN; } } } else { new_values = values; } /* if (overrideUnit != null) { System.out.println("values = " + old_values[0] + " " + values[0] + " " + new_values[0]); } */ } /* SRE 27 Oct 99 System.out.println( "ScalarMap.scaleValues(double[]): values[0] = " + values[0] + "; new_values[0] = " + new_values[0]); */ return new_values; }
/** * array of component types; default CoordinateSystem for values of this type (including Function * domains) and may be null; default Set used when this type is a FunctionType domain and may be * null */ public RealTupleType(RealType[] types, CoordinateSystem coord_sys, Set set) throws VisADException { super(types); if (coord_sys != null && types.length != coord_sys.getDimension()) { throw new CoordinateSystemException("RealTupleType: bad CoordinateSystem dimension"); } DefaultCoordinateSystem = coord_sys; DefaultSet = set; DefaultSetEverAccessed = false; setDefaultUnits(types); if (DefaultCoordinateSystem != null && !Unit.canConvertArray( DefaultCoordinateSystem.getCoordinateSystemUnits(), DefaultUnits)) { throw new UnitException( "RealTupleType: CoordinateSystem Units must be " + "convertable with default Units"); } if (DefaultSet != null && !Unit.canConvertArray(DefaultSet.getSetUnits(), DefaultUnits)) { throw new UnitException( "RealTupleType: default Set Units must be " + "convertable with default Units"); } if (DefaultCoordinateSystem != null && DefaultSet != null) { CoordinateSystem cs = DefaultSet.getCoordinateSystem(); if (cs != null && !cs.getReference().equals(DefaultCoordinateSystem.getReference())) { throw new CoordinateSystemException( "RealTupleType: Default coordinate system " + (coord_sys == null ? null : coord_sys.getReference()) + " must match" + " default set CoordinateSystem " + (cs == null ? null : cs.getReference())); } if (!Unit.canConvertArray( DefaultCoordinateSystem.getCoordinateSystemUnits(), DefaultSet.getSetUnits())) { throw new UnitException( "RealTupleType: CoordinateSystem Units must be " + "convertable with default Set Units"); } } }
/** trusted constructor for initializers */ RealTupleType(RealType[] types, CoordinateSystem coord_sys, boolean b) { super(types, b); DefaultCoordinateSystem = coord_sys; DefaultSet = null; DefaultSetEverAccessed = false; setDefaultUnits(types); if (DefaultCoordinateSystem != null && !Unit.canConvertArray( DefaultCoordinateSystem.getCoordinateSystemUnits(), DefaultUnits)) { throw new VisADError( "RealTupleType (trusted): CoordinateSystem Units " + "must be convertable with default Units"); } }
/** 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); } } }
public synchronized void drag_direct(VisADRay ray, boolean first, int mouseModifiers) { if (barbValues == null || ref == null || shadow == null) return; if (first) { stop = false; } else { if (stop) return; } // modify direction if mshift != 0 // modify speed if mctrl != 0 // modify speed and direction if neither int mshift = mouseModifiers & InputEvent.SHIFT_MASK; int mctrl = mouseModifiers & InputEvent.CTRL_MASK; float o_x = (float) ray.position[0]; float o_y = (float) ray.position[1]; float o_z = (float) ray.position[2]; float d_x = (float) ray.vector[0]; float d_y = (float) ray.vector[1]; float d_z = (float) ray.vector[2]; if (pickCrawlToCursor) { if (first) { offset_count = OFFSET_COUNT_INIT; } else { if (offset_count > 0) offset_count--; } if (offset_count > 0) { float mult = ((float) offset_count) / ((float) OFFSET_COUNT_INIT); o_x += mult * offsetx; o_y += mult * offsety; o_z += mult * offsetz; } } if (first || refirst) { point_x = barbValues[2]; point_y = barbValues[3]; point_z = 0.0f; line_x = 0.0f; line_y = 0.0f; line_z = 1.0f; // lineAxis == 2 in DataRenderer.drag_direct } // end if (first || refirst) float[] x = new float[3]; // x marks the spot // DirectManifoldDimension = 2 // intersect ray with plane float dot = (point_x - o_x) * line_x + (point_y - o_y) * line_y + (point_z - o_z) * line_z; float dot2 = d_x * line_x + d_y * line_y + d_z * line_z; if (dot2 == 0.0) return; dot = dot / dot2; // x is intersection x[0] = o_x + dot * d_x; x[1] = o_y + dot * d_y; x[2] = o_z + dot * d_z; /* System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]); */ try { Tuple data = (Tuple) link.getData(); int n = ((TupleType) data.getType()).getNumberOfRealComponents(); Real[] reals = new Real[n]; int k = 0; int m = data.getDimension(); for (int i = 0; i < m; i++) { Data component = data.getComponent(i); if (component instanceof Real) { reals[k++] = (Real) component; } else if (component instanceof RealTuple) { for (int j = 0; j < ((RealTuple) component).getDimension(); j++) { reals[k++] = (Real) ((RealTuple) component).getComponent(j); } } } if (first || refirst) { // get first Data flow vector for (int i = 0; i < 3; i++) { int j = flowToComponent[i]; data_flow[i] = (j >= 0) ? (float) reals[j].getValue() : 0.0f; } if (coord != null) { float[][] ds = {{data_flow[0]}, {data_flow[1]}, {data_flow[2]}}; ds = coord.toReference(ds); data_flow[0] = ds[0][0]; data_flow[1] = ds[1][0]; data_flow[2] = ds[2][0]; } data_speed = (float) Math.sqrt( data_flow[0] * data_flow[0] + data_flow[1] * data_flow[1] + data_flow[2] * data_flow[2]); float barb0 = barbValues[2] - barbValues[0]; float barb1 = barbValues[3] - barbValues[1]; /* System.out.println("data_flow = " + data_flow[0] + " " + data_flow[1] + " " + data_flow[2]); System.out.println("barbValues = " + barbValues[0] + " " + barbValues[1] + " " + barbValues[2] + " " + barbValues[3]); System.out.println("data_speed = " + data_speed); */ } // end if (first || refirst) // convert x to a flow vector, and from spatial to earth if (getRealVectorTypes(which_barb) instanceof EarthVectorType) { // don't worry about vector magnitude - // data_speed & display_speed take care of that float eps = 0.0001f; // estimate derivative with a little vector float[][] spatial_locs = { {barbValues[0], barbValues[0] + eps * (x[0] - barbValues[0])}, {barbValues[1], barbValues[1] + eps * (x[1] - barbValues[1])}, {0.0f, 0.0f} }; /* System.out.println("spatial_locs = " + spatial_locs[0][0] + " " + spatial_locs[0][1] + " " + spatial_locs[1][0] + " " + spatial_locs[1][1]); */ float[][] earth_locs = spatialToEarth(spatial_locs); // WLH - 18 Aug 99 if (earth_locs == null) return; /* System.out.println("earth_locs = " + earth_locs[0][0] + " " + earth_locs[0][1] + " " + earth_locs[1][0] + " " + earth_locs[1][1]); */ x[2] = 0.0f; x[0] = (earth_locs[1][1] - earth_locs[1][0]) * ((float) Math.cos(Data.DEGREES_TO_RADIANS * earth_locs[0][0])); x[1] = earth_locs[0][1] - earth_locs[0][0]; /* System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]); */ } else { // if (!(getRealVectorTypes(which_barb) instanceof EarthVectorType)) // convert x to vector x[0] -= barbValues[0]; x[1] -= barbValues[1]; // adjust for spatial map scalings but don't worry about vector // magnitude - data_speed & display_speed take care of that // also, spatial is Cartesian double[] ranges = getRanges(); for (int i = 0; i < 3; i++) { x[i] /= ranges[i]; } /* System.out.println("ranges = " + ranges[0] + " " + ranges[1] + " " + ranges[2]); System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]); */ } // WLH 6 August 99 x[0] = -x[0]; x[1] = -x[1]; x[2] = -x[2]; /* may need to do this for performance float[] xx = {x[0], x[1], x[2]}; addPoint(xx); */ float x_speed = (float) Math.sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]); /* WLH 16 April 2002 - from Ken if (x_speed < 0.000001f) x_speed = 0.000001f; */ if (x_speed < 0.01f) x_speed = 0.01f; if (first || refirst) { display_speed = x_speed; } refirst = false; if (mshift != 0) { // only modify data_flow direction float ratio = data_speed / x_speed; x[0] *= ratio; x[1] *= ratio; x[2] *= ratio; /* System.out.println("direction, ratio = " + ratio + " " + data_speed + " " + x_speed); System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]); */ } else if (mctrl != 0) { // only modify data_flow speed float ratio = x_speed / display_speed; if (data_speed < EPS) { data_flow[0] = 2.0f * EPS; refirst = true; } x[0] = ratio * data_flow[0]; x[1] = ratio * data_flow[1]; x[2] = ratio * data_flow[2]; /* System.out.println("speed, ratio = " + ratio + " " + x_speed + " " + display_speed); System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]); */ } else { // modify data_flow speed and direction float ratio = data_speed / display_speed; /* System.out.println("data_speed = " + data_speed + " display_speed = " + display_speed + " ratio = " + ratio + " EPS = " + EPS); System.out.println("x = " + x[0] + " " + x[1] +" " + x[2] + " x_speed = " + x_speed); data_speed = 21.213203 display_speed = 0.01 ratio = 2121.3203 EPS = 0.2 x = 1.6170928E-4 1.6021729E-4 -0.0 x_speed = 0.01 wind = (0.3430372, 0.33987218) at (-35.0, 5.0) */ if (data_speed < EPS) { data_flow[0] = 2.0f * EPS; x[0] = data_flow[0]; x[1] = data_flow[1]; x[2] = data_flow[2]; refirst = true; } else { x[0] *= ratio; x[1] *= ratio; x[2] *= ratio; } } if (coord != null) { float[][] xs = {{x[0]}, {x[1]}, {x[2]}}; xs = coord.fromReference(xs); x[0] = xs[0][0]; x[1] = xs[1][0]; x[2] = xs[2][0]; } // now replace flow values Vector vect = new Vector(); for (int i = 0; i < 3; i++) { int j = flowToComponent[i]; if (j >= 0) { RealType rtype = (RealType) reals[j].getType(); reals[j] = new Real(rtype, (double) x[i], rtype.getDefaultUnit(), null); // WLH 31 Aug 2000 Real r = reals[j]; Unit overrideUnit = null; if (directMap[i] != null) { overrideUnit = directMap[i].getOverrideUnit(); } Unit rtunit = rtype.getDefaultUnit(); // units not part of Time string if (overrideUnit != null && !overrideUnit.equals(rtunit) && !RealType.Time.equals(rtype)) { double d = (float) overrideUnit.toThis((double) x[0], rtunit); r = new Real(rtype, d, overrideUnit); String valueString = r.toValueString(); vect.addElement(rtype.getName() + " = " + valueString); } else { // create location string vect.addElement(rtype.getName() + " = " + x[i]); } } } getDisplayRenderer().setCursorStringVector(vect); Data newData = null; // now build new RealTuple or Flat Tuple if (data instanceof RealTuple) { newData = new RealTuple( ((RealTupleType) data.getType()), reals, ((RealTuple) data).getCoordinateSystem()); } else { Data[] new_components = new Data[m]; k = 0; for (int i = 0; i < m; i++) { Data component = data.getComponent(i); if (component instanceof Real) { new_components[i] = reals[k++]; } else if (component instanceof RealTuple) { Real[] sub_reals = new Real[((RealTuple) component).getDimension()]; for (int j = 0; j < ((RealTuple) component).getDimension(); j++) { sub_reals[j] = reals[k++]; } new_components[i] = new RealTuple( ((RealTupleType) component.getType()), sub_reals, ((RealTuple) component).getCoordinateSystem()); } } newData = new Tuple(new_components, false); } ref.setData(newData); } catch (VisADException e) { // do nothing System.out.println("drag_direct " + e); e.printStackTrace(); } catch (RemoteException e) { // do nothing System.out.println("drag_direct " + e); e.printStackTrace(); } }
/** * get default Units of RealType components; copy DefaultUnits array to ensure that it cannot be * altered */ public Unit[] getDefaultUnits() { return Unit.copyUnitsArray(DefaultUnits); }