/** 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); } } }
/** * 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(); }
/** 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; }
/** * 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); } }
/** * Compares this ScalarMap with another ScalarMap. The ScalarType-s are first compared; if they * compare equal, then the DisplayRealType-s are compared. * * @param that The other ScalarMap. * @return A value that is negative, zero, or positive depending on whether this ScalarMap is * considered less than, equal to, or greater than the other ScalarMap, respectively. */ protected int compareTo(ScalarMap that) { int comp = getScalar().compareTo(that.getScalar()); if (comp == 0) comp = getDisplayScalar().compareTo(that.getDisplayScalar()); return comp; }
public static boolean isByRefUsable(DataDisplayLink link, ShadowType shadow) throws VisADException, RemoteException { ShadowFunctionOrSetType shadowType = (ShadowFunctionOrSetType) shadow.getAdaptedShadowType(); CoordinateSystem dataCoordinateSystem = null; FlatField fltField = null; int num_images = 1; FieldImpl field = (FieldImpl) link.getData(); if (!(field instanceof FlatField)) { num_images = field.getDomainSet().getLength(); if (1 == num_images) { // If there is a single image in the animation dont do anything, simply // return true return true; } shadowType = (ShadowFunctionOrSetType) shadowType.getRange(); fltField = (FlatField) field.getSample(0); dataCoordinateSystem = fltField.getDomainCoordinateSystem(); } else { dataCoordinateSystem = ((FlatField) field).getDomainCoordinateSystem(); return true; } // cs might be cached if (dataCoordinateSystem instanceof CachingCoordinateSystem) { dataCoordinateSystem = ((CachingCoordinateSystem) dataCoordinateSystem).getCachedCoordinateSystem(); } ShadowRealType[] DomainComponents = shadowType.getDomainComponents(); ShadowRealTupleType Domain = shadowType.getDomain(); ShadowRealTupleType domain_reference = Domain.getReference(); ShadowRealType[] DC = DomainComponents; if (domain_reference != null && domain_reference.getMappedDisplayScalar()) { DC = shadowType.getDomainReferenceComponents(); } DisplayTupleType spatial_tuple = null; for (int i = 0; i < DC.length; i++) { java.util.Enumeration maps = DC[i].getSelectedMapVector().elements(); ScalarMap map = (ScalarMap) maps.nextElement(); DisplayRealType real = map.getDisplayScalar(); spatial_tuple = real.getTuple(); } CoordinateSystem coord = spatial_tuple.getCoordinateSystem(); if (coord instanceof CachingCoordinateSystem) { coord = ((CachingCoordinateSystem) coord).getCachedCoordinateSystem(); } boolean useLinearTexture = false; if (coord instanceof InverseLinearScaledCS) { InverseLinearScaledCS invCS = (InverseLinearScaledCS) coord; useLinearTexture = (invCS.getInvertedCoordinateSystem()).equals(dataCoordinateSystem); } /** * if useLinearTexture is true at this point, it's true for the first image of a sequence with * numimages > 1. We'll have to assume that byRef will apply until below is resolved. */ /** * more consideration/work needed here. CoordinateSystems might be equal even if they aren't the * same transform (i,j) -> (lon,lat) if (!useLinearTexture) { //If DisplayCoordinateSystem != * DataCoordinateSystem if (num_images > 1) { //Its an animation int lengths[] = * ((visad.GriddedSet) fltField.getDomainSet()).getLengths(); int data_width = lengths[0]; int * data_height = lengths[1]; for (int i = 1; i < num_images; i++) {//Playing safe: go down the * full sequence to find if the full set is Geostaionary or NOT FlatField ff = (FlatField) * field.getSample(i); //Quicker Approach would be to just compare only the first two images in * the sequence. But that may not be safe. CoordinateSystem dcs = * ff.getDomainCoordinateSystem(); // dcs might be cached if (dcs instanceof * CachingCoordinateSystem) { dcs = ((CachingCoordinateSystem) dcs).getCachedCoordinateSystem(); * } int[] lens = ((visad.GriddedSet) ff.getDomainSet()).getLengths(); if (lens[0] != data_width * || lens[1] != data_height || ( (dcs != null) && (dataCoordinateSystem != null) && * !dcs.equals(dataCoordinateSystem))) { useLinearTexture = false; break; } } } } */ return useLinearTexture; }
/** * determine whether the given MathType and collection of ScalarMaps meets the criteria to use * ImageRendererJ3D. Throw a VisADException if ImageRenderer cannot be used, otherwise return * true. */ public static boolean isRendererUsable(MathType type, ScalarMap[] maps) throws VisADException { RealType time = null; RealTupleType domain = null; RealTupleType range = null; RealType x = null, y = null; RealType rx = null, ry = null; // WLH 19 July 2000 RealType r = null, g = null, b = null; RealType rgb = null; // must be a function if (!(type instanceof FunctionType)) { throw new VisADException("Not a FunctionType"); } FunctionType function = (FunctionType) type; RealTupleType functionD = function.getDomain(); MathType functionR = function.getRange(); // time function if (function.equalsExceptName(image_sequence_type) || function.equalsExceptName(image_sequence_type2) || function.equalsExceptName(image_sequence_type3)) { // strip off time RealType time = (RealType) functionD.getComponent(0); function = (FunctionType) functionR; functionD = function.getDomain(); functionR = function.getRange(); } // ((ImageLine, ImageElement) -> ImageValue) // ((ImageLine, ImageElement) -> (ImageValue)) // ((ImageLine, ImageElement) -> (Red, Green, Blue)) if (function.equalsExceptName(image_type) || function.equalsExceptName(image_type2) || function.equalsExceptName(image_type3)) { domain = function.getDomain(); MathType rt = function.getRange(); if (rt instanceof RealType) { range = new RealTupleType((RealType) rt); } else if (rt instanceof RealTupleType) { range = (RealTupleType) rt; } else { // illegal MathType throw new VisADException("Illegal RangeType"); } } else { // illegal MathType throw new VisADException("Illegal MathType"); } // extract x and y from domain x = (RealType) domain.getComponent(0); y = (RealType) domain.getComponent(1); // WLH 19 July 2000 CoordinateSystem cs = domain.getCoordinateSystem(); if (cs != null) { RealTupleType rxy = cs.getReference(); rx = (RealType) rxy.getComponent(0); ry = (RealType) rxy.getComponent(1); } // extract colors from range int dim = range.getDimension(); if (dim == 1) rgb = (RealType) range.getComponent(0); else { // dim == 3 r = (RealType) range.getComponent(0); g = (RealType) range.getComponent(1); b = (RealType) range.getComponent(2); } // verify that collection of ScalarMaps is legal boolean btime = (time == null); boolean bx = false, by = false; boolean brx = false, bry = false; // WLH 19 July 2000 boolean br = false, bg = false, bb = false; boolean dbr = false, dbg = false, dbb = false; Boolean latlon = null; DisplayRealType spatial = null; for (int i = 0; i < maps.length; i++) { ScalarMap m = maps[i]; ScalarType md = m.getScalar(); DisplayRealType mr = m.getDisplayScalar(); boolean ddt = md.equals(time); boolean ddx = md.equals(x); boolean ddy = md.equals(y); boolean ddrx = md.equals(rx); boolean ddry = md.equals(ry); boolean ddr = md.equals(r); boolean ddg = md.equals(g); boolean ddb = md.equals(b); boolean ddrgb = md.equals(rgb); // animation mapping if (ddt) { if (btime) throw new VisADException("Multiple Time mappings"); if (!mr.equals(Display.Animation)) { throw new VisADException("Time mapped to something other than Animation"); } btime = true; } // spatial mapping else if (ddx || ddy || ddrx || ddry) { if (ddx && bx || ddy && by || ddrx && brx || ddry && bry) { throw new VisADException("Duplicate spatial mappings"); } if (((ddx || ddy) && (brx || bry)) || ((ddrx || ddry) && (bx || by))) { throw new VisADException("reference and non-reference spatial mappings"); } RealType q = (ddx ? x : null); if (ddy) q = y; if (ddrx) q = rx; if (ddry) q = ry; boolean ll; if (mr.equals(Display.XAxis) || mr.equals(Display.YAxis) || mr.equals(Display.ZAxis)) { ll = false; } else if (mr.equals(Display.Latitude) || mr.equals(Display.Longitude) || mr.equals(Display.Radius)) { ll = true; } else throw new VisADException("Illegal domain mapping"); if (latlon == null) { latlon = new Boolean(ll); spatial = mr; } else if (latlon.booleanValue() != ll) { throw new VisADException("Multiple spatial coordinate systems"); } // two mappings to the same spatial DisplayRealType are not allowed else if (spatial == mr) { throw new VisADException("Multiple mappings to the same spatial DisplayRealType"); } if (ddx) bx = true; else if (ddy) by = true; else if (ddrx) brx = true; else if (ddry) bry = true; } // rgb mapping else if (ddrgb) { if (br || bg || bb) { throw new VisADException("Duplicate color mappings"); } if (rgb == null || !(mr.equals(Display.RGB) || mr.equals(Display.RGBA))) { throw new VisADException("Illegal RGB/RGBA mapping"); } dbr = dbg = dbb = true; br = bg = bb = true; } // color mapping else if (ddr || ddg || ddb) { if (rgb != null) throw new VisADException("Illegal RGB mapping"); RealType q = (ddr ? r : (ddg ? g : b)); if (mr.equals(Display.Red)) dbr = true; else if (mr.equals(Display.Green)) dbg = true; else if (mr.equals(Display.Blue)) dbb = true; else throw new VisADException("Illegal color mapping"); if (ddr) br = true; else if (ddg) bg = true; else bb = true; } // illegal ScalarMap involving this MathType else if (ddt || ddx || ddy || ddrx || ddry || ddr || ddg || ddb || ddrgb) { throw new VisADException("Illegal mapping: " + m); } } // return true if all conditions for ImageRendererJ3D are met if (!(btime && ((bx && by) || (brx && bry)) && br && bg && bb && dbr && dbg && dbb)) { throw new VisADException("Insufficient mappings"); } return true; }