public void doAction() throws VisADException, RemoteException { if (!init) { init = true; return; } Gridded2DSet set = (Gridded2DSet) rubberBand.getData(); float[] low = set.getLow(); float[] high = set.getHi(); xmap.setRange(low[0], high[0]); ymap.setRange(low[1], high[1]); }
/** 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); } } }
/** * Initialize the color maps * * @throws RemoteException On badness * @throws VisADException On badness */ private void initColorMaps() throws VisADException, RemoteException { setupTypes(); if (doColors) { ScalarMap rmap = new ScalarMap(front_red, Display.Red); rmap.setRange(0.0, 1.0); ScalarMap gmap = new ScalarMap(front_green, Display.Green); gmap.setRange(0.0, 1.0); ScalarMap bmap = new ScalarMap(front_blue, Display.Blue); bmap.setRange(0.0, 1.0); ScalarMapSet maps = getScalarMapSet(); // new ScalarMapSet(); maps.add(rmap); maps.add(bmap); maps.add(gmap); setScalarMapSet(maps); } }
/** * explicitly set the range of data (RealType) values according to Unit conversion between this * ScalarMap's RealType and DisplayRealType (both must have Units and they must be convertable; if * neither this nor setRange is invoked, then the range will be computed from the initial values * of Data objects linked to the Display by autoscaling logic. * * @throws VisADException VisAD error * @throws RemoteException Java RMI error */ public void setRangeByUnits() throws VisADException, RemoteException { isManual = true; setRange(null, 0.0, 0.0, true); 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 } }
/** * 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 } }
public void displayChanged(final DisplayEvent e) throws VisADException, RemoteException { // TODO: write a method like isChannelUpdate(EVENT_ID)? or maybe just // deal with a super long if-statement and put an "OR MOUSE_RELEASED" // up here? if (e.getId() == DisplayEvent.MOUSE_RELEASED_CENTER) { float val = (float) display.getDisplayRenderer().getDirectAxisValue(domainType); setWaveNumber(val); if (displayControl != null) displayControl.handleChannelChange(val); } else if (e.getId() == DisplayEvent.MOUSE_PRESSED_LEFT) { if (e.getInputEvent().isControlDown()) { xmap.setRange(initialRangeX[0], initialRangeX[1]); ymap.setRange(initialRangeY[0], initialRangeY[1]); } } else if (e.getId() == DisplayEvent.MOUSE_RELEASED) { float val = getSelectorValue(channelSelector); if (val != waveNumber) { // TODO: setWaveNumber needs to be rethought, as it calls // setSelectorValue which is redundant in the cases of dragging // or clicking setWaveNumber(val); if (displayControl != null) displayControl.handleChannelChange(val); } } }
/** * prepare for transforming Data into scene graph depictions, including possible auto-scaling of * ScalarMaps * * @param temp Vector of DataRenderers * @param tmap Vector of ScalarMaps * @param go flag indicating whether Data transforms are requested * @param initialize flag indicating whether auto-scaling is requested * @throws VisADException a VisAD error occurred * @throws RemoteException an RMI error occurred */ public void prepareAction(Vector temp, Vector tmap, boolean go, boolean initialize) throws VisADException, RemoteException { DataShadow shadow = null; Enumeration renderers = temp.elements(); while (renderers.hasMoreElements()) { DataRenderer renderer = (DataRenderer) renderers.nextElement(); shadow = renderer.prepareAction(go, initialize, shadow); } if (shadow != null) { // apply RealType ranges and animationSampling Enumeration maps = tmap.elements(); while (maps.hasMoreElements()) { ScalarMap map = ((ScalarMap) maps.nextElement()); map.setRange(shadow); } } ScalarMap.equalizeFlow(tmap, Display.DisplayFlow1Tuple); ScalarMap.equalizeFlow(tmap, Display.DisplayFlow2Tuple); }
/** * Construct a satellite display using the specified McIDAS map file, image source. The image can * be displayed on a 3D globe or on a flat rectillinear projection. * * @param mapFile location of the McIDAS map file (path or URL) * @param imageSource location of the image source (path or URL) * @param display3D if true, use 3D display, otherwise flat rectillinear * @param remap remap the image into a domain over North America */ public SatDisplay(String mapFile, String imageSource, boolean display3D, boolean remap) { try { // Read in the map file BaseMapAdapter baseMapAdapter; if (mapFile.indexOf("://") > 0) // URL specified { baseMapAdapter = new BaseMapAdapter(new URL(mapFile)); } else // local disk file { baseMapAdapter = new BaseMapAdapter(mapFile); } // Create the display and set up the scalar maps to map // data to the display ScalarMap latMap; // latitude -> YAxis ScalarMap lonMap; // longitude -> XAxis if (display3D) { display = new DisplayImplJ3D("display"); latMap = new ScalarMap(RealType.Latitude, Display.Latitude); lonMap = new ScalarMap(RealType.Longitude, Display.Longitude); } else { display = new DisplayImplJ3D("display", new TwoDDisplayRendererJ3D()); latMap = new ScalarMap(RealType.Latitude, Display.YAxis); lonMap = new ScalarMap(RealType.Longitude, Display.XAxis); } display.addMap(latMap); display.addMap(lonMap); // set the display to a global scale latMap.setRange(-90.0, 90.0); lonMap.setRange(-180.0, 180.0); // create a reference for the map line DataReference maplinesRef = new DataReferenceImpl("MapLines"); maplinesRef.setData(baseMapAdapter.getData()); // set the attributes of the map lines (color, location) ConstantMap[] maplinesConstantMap = new ConstantMap[4]; maplinesConstantMap[0] = new ConstantMap(0., Display.Blue); maplinesConstantMap[1] = new ConstantMap(1., Display.Red); maplinesConstantMap[2] = new ConstantMap(0., Display.Green); maplinesConstantMap[3] = new ConstantMap(1.001, Display.Radius); // just above the image // read in the image AreaAdapter areaAdapter = new AreaAdapter(imageSource); FlatField image = areaAdapter.getData(); // Extract the metadata from the image FunctionType imageFunctionType = (FunctionType) image.getType(); RealTupleType imageDomainType = imageFunctionType.getDomain(); RealTupleType imageRangeType = (RealTupleType) imageFunctionType.getRange(); // remap and resample the image if (remap) { int SIZE = 256; RealTupleType latlonType = ((CoordinateSystem) imageDomainType.getCoordinateSystem()).getReference(); Linear2DSet remapDomainSet = new Linear2DSet(latlonType, -4.0, 70.0, SIZE, -150.0, 5.0, SIZE); image = (FlatField) image.resample(remapDomainSet, Data.NEAREST_NEIGHBOR, Data.NO_ERRORS); } // select which band to show... ScalarMap rgbMap = new ScalarMap((RealType) imageRangeType.getComponent(0), Display.RGB); display.addMap(rgbMap); // set the enhancement to a grey scale ColorControl colorControl = (ColorControl) rgbMap.getControl(); colorControl.initGreyWedge(); // create a data reference for the image DataReferenceImpl imageRef = new DataReferenceImpl("ImageRef"); imageRef.setData(image); // add the data references to the display display.disableAction(); drmap = new DefaultRendererJ3D(); drimage = new DefaultRendererJ3D(); drmap.toggle(false); drimage.toggle(false); display.addDisplayListener(this); display.addReferences(drmap, maplinesRef, maplinesConstantMap); display.addReferences(drimage, imageRef, null); display.enableAction(); } catch (Exception ne) { ne.printStackTrace(); System.exit(1); } }
/** set range used for linear map from Scalar to DisplayScalar values */ private synchronized void setRange(DataShadow shadow, double low, double hi, boolean unit_flag) throws VisADException, RemoteException { setRange(shadow, low, hi, unit_flag, VisADEvent.LOCAL_SOURCE); }
/** * set range used for linear map from Scalar to DisplayScalar values; this is the call for * automatic scaling */ public void setRange(DataShadow shadow) throws VisADException, RemoteException { if (!isManual) setRange(shadow, 0.0, 0.0, false, VisADEvent.LOCAL_SOURCE); }
/** * Explicitly sets the range of {@link RealType} data values that is mapped to the natural range * of {@link DisplayRealType} display values. This method is used to define a linear map from * Scalar to DisplayScalar values. If neither this nor {@link #setRangeByUnits()} is invoked, then * the range will be computed by autoscaling logic from the initial values of Data objects linked * to the Display. 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 One end of the range of applicable data. * @param hi The other end of the range of applicable data. * @throws VisADException VisAD failure. * @throws RemoteException Java RMI failure. */ public void setRange(double low, double hi) throws VisADException, RemoteException { setRange(low, hi, VisADEvent.LOCAL_SOURCE); }
private void init() throws VisADException, RemoteException { HydraDataSource source = (HydraDataSource) dataChoice.getDataSource(); // TODO revisit this, may want to move method up to base class HydraDataSource if (source instanceof SuomiNPPDataSource) { data = ((SuomiNPPDataSource) source).getMultiSpectralData(dataChoice); } if (source instanceof MultiSpectralDataSource) { data = ((MultiSpectralDataSource) source).getMultiSpectralData(dataChoice); } waveNumber = data.init_wavenumber; try { spectrum = data.getSpectrum(new int[] {1, 1}); } catch (Exception e) { LogUtil.logException("MultiSpectralDisplay.init", e); } domainSet = (Gridded1DSet) spectrum.getDomainSet(); initialRangeX = getXRange(domainSet); initialRangeY = data.getDataRange(); domainType = getDomainType(spectrum); rangeType = getRangeType(spectrum); master = new XYDisplay(DISP_NAME, domainType, rangeType); setDisplayMasterAttributes(master); // set up the x- and y-axis xmap = new ScalarMap(domainType, Display.XAxis); ymap = new ScalarMap(rangeType, Display.YAxis); xmap.setRange(initialRangeX[0], initialRangeX[1]); ymap.setRange(initialRangeY[0], initialRangeY[1]); display = master.getDisplay(); display.addMap(xmap); display.addMap(ymap); display.addDisplayListener(this); new RubberBandBox(this, xmap, ymap); if (displayControl == null) { // - add in a ref for the default spectrum, ie no DisplayControl DataReferenceImpl spectrumRef = new DataReferenceImpl(hashCode() + "_spectrumRef"); spectrumRef.setData(spectrum); addRef(spectrumRef, Color.WHITE); } if (data.hasBandNames()) { bandSelectComboBox = new JComboBox(data.getBandNames().toArray()); bandSelectComboBox.setSelectedItem(data.init_bandName); bandSelectComboBox.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String bandName = (String) bandSelectComboBox.getSelectedItem(); if (bandName == null) return; HashMap<String, Float> bandMap = data.getBandNameMap(); if (bandMap == null) return; if (!bandMap.containsKey(bandName)) return; setWaveNumber(bandMap.get(bandName)); } }); } }
/** test BarbManipulationRendererJ3D */ public static void main(String args[]) throws VisADException, RemoteException { System.out.println("BMR.main()"); // construct RealTypes for wind record components RealType lat = RealType.Latitude; RealType lon = RealType.Longitude; RealType windx = RealType.getRealType("windx", CommonUnit.meterPerSecond); RealType windy = RealType.getRealType("windy", CommonUnit.meterPerSecond); RealType red = RealType.getRealType("red"); RealType green = RealType.getRealType("green"); // EarthVectorType extends RealTupleType and says that its // components are vectors in m/s with components parallel // to Longitude (positive east) and Latitude (positive north) EarthVectorType windxy = new EarthVectorType(windx, windy); RealType wind_dir = RealType.getRealType("wind_dir", CommonUnit.degree); RealType wind_speed = RealType.getRealType("wind_speed", CommonUnit.meterPerSecond); RealTupleType windds = null; if (args.length > 0) { System.out.println("polar winds"); windds = new RealTupleType( new RealType[] {wind_dir, wind_speed}, new WindPolarCoordinateSystem(windxy), null); } // construct Java3D display and mappings that govern // how wind records are displayed DisplayImpl display = new DisplayImplJ3D("display1", new TwoDDisplayRendererJ3D()); ScalarMap lonmap = new ScalarMap(lon, Display.XAxis); display.addMap(lonmap); ScalarMap latmap = new ScalarMap(lat, Display.YAxis); display.addMap(latmap); FlowControl flow_control; if (args.length > 0) { ScalarMap winds_map = new ScalarMap(wind_speed, Display.Flow1Radial); display.addMap(winds_map); winds_map.setRange(0.0, 1.0); // do this for barb rendering ScalarMap windd_map = new ScalarMap(wind_dir, Display.Flow1Azimuth); display.addMap(windd_map); windd_map.setRange(0.0, 360.0); // do this for barb rendering flow_control = (FlowControl) windd_map.getControl(); flow_control.setFlowScale(0.15f); // this controls size of barbs } else { ScalarMap windx_map = new ScalarMap(windx, Display.Flow1X); display.addMap(windx_map); windx_map.setRange(-1.0, 1.0); // do this for barb rendering ScalarMap windy_map = new ScalarMap(windy, Display.Flow1Y); display.addMap(windy_map); windy_map.setRange(-1.0, 1.0); // do this for barb rendering flow_control = (FlowControl) windy_map.getControl(); flow_control.setFlowScale(0.15f); // this controls size of barbs } display.addMap(new ScalarMap(red, Display.Red)); display.addMap(new ScalarMap(green, Display.Green)); display.addMap(new ConstantMap(1.0, Display.Blue)); DataReferenceImpl[] refs = new DataReferenceImpl[N * N]; int k = 0; // create an array of N by N winds for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { double u = 2.0 * i / (N - 1.0) - 1.0; double v = 2.0 * j / (N - 1.0) - 1.0; // each wind record is a Tuple (lon, lat, (windx, windy), red, green) // set colors by wind components, just for grins Tuple tuple; double fx = 30.0 * u; double fy = 30.0 * v; if (args.length > 0) { double fd = Data.RADIANS_TO_DEGREES * Math.atan2(-fx, -fy); double fs = Math.sqrt(fx * fx + fy * fy); tuple = new Tuple( new Data[] { new Real(lon, 10.0 * u), new Real(lat, 10.0 * v - 40.0), new RealTuple(windds, new double[] {fd, fs}), new Real(red, u), new Real(green, v) }); } else { tuple = new Tuple( new Data[] { new Real(lon, 10.0 * u), new Real(lat, 10.0 * v - 40.0), new RealTuple(windxy, new double[] {fx, fy}), new Real(red, u), new Real(green, v) }); } // construct reference for wind record refs[k] = new DataReferenceImpl("ref_" + k); refs[k].setData(tuple); // link wind record to display via BarbManipulationRendererJ3D // so user can change barb by dragging it // drag with right mouse button and shift to change direction // drag with right mouse button and no shift to change speed BarbManipulationRendererJ3D renderer = new BarbManipulationRendererJ3D(); renderer.setKnotsConvert(true); display.addReferences(renderer, refs[k]); // link wind record to a CellImpl that will listen for changes // and print them WindGetterJ3D cell = new WindGetterJ3D(flow_control, refs[k]); cell.addReference(refs[k]); k++; } } // instead of linking the wind record "DataReferenceImpl refs" to // the WindGetterJ3Ds, you can have some user interface event (e.g., // the user clicks on "DONE") trigger code that does a getData() on // all the refs and stores the records in a file. // create JFrame (i.e., a window) for display and slider JFrame frame = new JFrame("test BarbManipulationRendererJ3D"); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); // create JPanel in JFrame JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.setAlignmentY(JPanel.TOP_ALIGNMENT); panel.setAlignmentX(JPanel.LEFT_ALIGNMENT); frame.getContentPane().add(panel); // add display to JPanel panel.add(display.getComponent()); // set size of JFrame and make it visible frame.setSize(500, 500); frame.setVisible(true); }
/** * run 'java FlowTest middle_latitude' to test with (lat, lon) run 'java FlowTest middle_latitude * x' to test with (lon, lat) adjust middle_latitude for south or north */ public static void main(String args[]) throws VisADException, RemoteException { double mid_lat = -10.0; if (args.length > 0) { try { mid_lat = Double.valueOf(args[0]).doubleValue(); } catch (NumberFormatException e) { } } boolean swap = (args.length > 1); RealType lat = RealType.Latitude; RealType lon = RealType.Longitude; RealType[] types; if (swap) { types = new RealType[] {lon, lat}; } else { types = new RealType[] {lat, lon}; } RealTupleType earth_location = new RealTupleType(types); System.out.println("earth_location = " + earth_location + " mid_lat = " + mid_lat); RealType flowx = RealType.getRealType("flowx", CommonUnit.meterPerSecond); RealType flowy = RealType.getRealType("flowy", CommonUnit.meterPerSecond); RealType red = RealType.getRealType("red"); RealType green = RealType.getRealType("green"); EarthVectorType flowxy = new EarthVectorType(flowx, flowy); TupleType range = null; range = new TupleType(new MathType[] {flowxy, red, green}); FunctionType flow_field = new FunctionType(earth_location, range); DisplayImpl display = new DisplayImplJ3D("display1", new TwoDDisplayRendererJ3D()); ScalarMap xmap = new ScalarMap(lon, Display.XAxis); display.addMap(xmap); ScalarMap ymap = new ScalarMap(lat, Display.YAxis); display.addMap(ymap); ScalarMap flowx_map = new ScalarMap(flowx, Display.Flow1X); display.addMap(flowx_map); flowx_map.setRange(-10.0, 10.0); ScalarMap flowy_map = new ScalarMap(flowy, Display.Flow1Y); display.addMap(flowy_map); flowy_map.setRange(-10.0, 10.0); FlowControl flow_control = (FlowControl) flowy_map.getControl(); flow_control.setFlowScale(0.05f); display.addMap(new ScalarMap(red, Display.Red)); display.addMap(new ScalarMap(green, Display.Green)); display.addMap(new ConstantMap(1.0, Display.Blue)); double lonlow = -10.0; double lonhi = 10.0; double latlow = mid_lat - 10.0; double lathi = mid_lat + 10.0; Linear2DSet set; if (swap) { set = new Linear2DSet(earth_location, lonlow, lonhi, N, latlow, lathi, N); } else { set = new Linear2DSet(earth_location, latlow, lathi, N, lonlow, lonhi, N); } double[][] values = new double[4][N * N]; int m = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { int k = i; int l = j; if (swap) { k = j; l = i; } double u = (N - 1.0) / 2.0 - l; double v = k - (N - 1.0) / 2.0; // double u = 2.0 * k / (N - 1.0) - 1.0; // double v = 2.0 * l / (N - 1.0); double fx = 6.0 * u; double fy = 6.0 * v; values[0][m] = fx; values[1][m] = fy; values[2][m] = u; values[3][m] = v; m++; } } FlatField field = new FlatField(flow_field, set); field.setSamples(values); DataReferenceImpl ref = new DataReferenceImpl("ref"); ref.setData(field); display.addReference(ref); // create JFrame (i.e., a window) for display and slider JFrame frame = new JFrame("test FlowTest"); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); // create JPanel in JFrame JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.setAlignmentY(JPanel.TOP_ALIGNMENT); panel.setAlignmentX(JPanel.LEFT_ALIGNMENT); frame.getContentPane().add(panel); // add display to JPanel panel.add(display.getComponent()); // set size of JFrame and make it visible frame.setSize(500, 500); frame.setVisible(true); }