/** * Set the track to be displayed. * * @param track must have the form (lat,lon, alt) -> param * @exception VisADException couldn't create the necessary VisAD object * @exception RemoteException couldn't create the remote object */ public void setTrack(FieldImpl track) throws VisADException, RemoteException { // get the RealType of the range from the FlatField RealType[] types = ((TupleType) GridUtil.getParamType(track)).getRealComponents(); RealType ffldType = types[0]; RealType rgbRealType = getRGBRealType(); if ((rgbRealType == null) || !ffldType.equals(rgbRealType)) { super.setRGBRealType(ffldType); } if (types.length > 1) { RealType newSelectType = (types.length > 1) ? types[1] : getRGBRealType(); RealType selectRealType = getSelectRealType(); if ((selectRealType == null) || !newSelectType.equals(selectRealType)) { setSelectRealType(newSelectType); } } this.track = track; setData(this.track); }
void setupServerData(LocalDisplay[] dpys) throws RemoteException, VisADException { RealType[] types = {RealType.Latitude, RealType.Longitude}; RealTupleType earth_location = new RealTupleType(types); RealType vis_radiance = RealType.getRealType("vis_radiance"); RealType ir_radiance = RealType.getRealType("ir_radiance"); RealType[] types2 = {vis_radiance, ir_radiance}; RealTupleType radiance = new RealTupleType(types2); FunctionType image_tuple = new FunctionType(earth_location, radiance); int size = 64; FlatField imaget1 = FlatField.makeField(image_tuple, size, false); dpys[0].addMap(new ScalarMap(RealType.Latitude, Display.YAxis)); dpys[0].addMap(new ScalarMap(RealType.Longitude, Display.XAxis)); dpys[0].addMap(new ScalarMap(ir_radiance, Display.Green)); dpys[0].addMap(new ScalarMap(vis_radiance, Display.RGB)); dpys[0].addMap(new ScalarMap(ir_radiance, Display.ZAxis)); dpys[0].addMap(new ConstantMap(0.5, Display.Blue)); dpys[0].addMap(new ConstantMap(0.5, Display.Red)); ScalarMap map1contour; map1contour = new ScalarMap(vis_radiance, Display.IsoContour); dpys[0].addMap(map1contour); if (uneven) { ContourControl control = (ContourControl) map1contour.getControl(); float[] levs = {10.0f, 12.0f, 14.0f, 16.0f, 24.0f, 32.0f, 40.0f}; control.setLevels(levs, 15.0f, true); control.enableLabels(true); } DataReferenceImpl ref_imaget1 = new DataReferenceImpl("ref_imaget1"); ref_imaget1.setData(imaget1); dpys[0].addReference(ref_imaget1, null); }
public DisplayableData getImageDisplay() { if (imageDisplay == null) { try { uniqueRangeType = RealType.getRealType(rangeType.getName() + "_" + cnt++); imageDisplay = new HydraRGBDisplayable("image", uniqueRangeType, null, true, displayControl); } catch (Exception e) { LogUtil.logException("MultiSpectralDisplay.getImageDisplay", e); } } return imageDisplay; }
// type 'java Parallel' to run this application public static void main(String args[]) throws VisADException, RemoteException, IOException { RealType index = RealType.getRealType("index"); RealType[] coords = new RealType[NCOORDS]; for (int i = 0; i < NCOORDS; i++) { coords[i] = RealType.getRealType("coord" + i); } RealTupleType range = new RealTupleType(coords); FunctionType ftype = new FunctionType(index, range); Integer1DSet index_set = new Integer1DSet(NROWS); float[][] samples = new float[NCOORDS][NROWS]; for (int i = 0; i < NCOORDS; i++) { for (int j = 0; j < NROWS; j++) { samples[i][j] = (float) Math.random(); } } FlatField data = new FlatField(ftype, index_set); data.setSamples(samples, false); // create a 2-D Display using Java3D DisplayImpl display = new DisplayImplJ3D("display", new TwoDDisplayRendererJ3D()); parallel(display, data); // create JFrame (i.e., a window) for display and slider JFrame frame = new JFrame("Parallel Coordinates VisAD Application"); 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); }
void setupServerData(LocalDisplay[] dpys) throws RemoteException, VisADException { RealType[] time = {RealType.Time}; RealType[] types = {RealType.Latitude, RealType.Longitude}; RealTupleType earth_location = new RealTupleType(types); RealType vis_radiance = RealType.getRealType("vis_radiance"); RealType ir_radiance = RealType.getRealType("ir_radiance"); RealType[] types2 = {vis_radiance, ir_radiance}; RealTupleType radiance = new RealTupleType(types2); FunctionType image_tuple = new FunctionType(earth_location, radiance); RealType[] types4 = {ir_radiance, vis_radiance}; RealTupleType ecnaidar = new RealTupleType(types4); FunctionType image_bumble = new FunctionType(earth_location, ecnaidar); RealTupleType time_type = new RealTupleType(time); FunctionType time_images = new FunctionType(time_type, image_tuple); int size = 64; FlatField imaget1 = FlatField.makeField(image_tuple, size, false); FlatField wasp = FlatField.makeField(image_bumble, size, false); int ntimes1 = 4; double start = new DateTime(1999, 122, 57060).getValue(); Set time_set = new Linear1DSet(time_type, start, start + 3600.0 * (ntimes1 - 1.0), ntimes1); FieldImpl image_sequence = new FieldImpl(time_images, time_set); FlatField temp = imaget1; Real[] reals30 = { new Real(vis_radiance, (float) size / 4.0f), new Real(ir_radiance, (float) size / 8.0f) }; RealTuple val = new RealTuple(reals30); for (int i = 0; i < ntimes1; i++) { image_sequence.setSample(i, temp); temp = (FlatField) temp.add(val); } dpys[0].addMap(new ScalarMap(RealType.Latitude, Display.YAxis)); dpys[0].addMap(new ScalarMap(RealType.Longitude, Display.XAxis)); dpys[0].addMap(new ScalarMap(vis_radiance, Display.Red)); dpys[0].addMap(new ScalarMap(ir_radiance, Display.Green)); dpys[0].addMap(new ConstantMap(0.5, Display.Blue)); dpys[0].addMap(new ScalarMap(RealType.Time, Display.ZAxis)); GraphicsModeControl mode = dpys[0].getGraphicsModeControl(); mode.setScaleEnable(true); DataReference ref_image_sequence = new DataReferenceImpl("ref_big_tuple"); ref_image_sequence.setData(image_sequence); dpys[0].addReference(ref_image_sequence, null); }
/** * Constructs from a name, an existing RealType, a coordinate system transformation, and a default * domain set. The name of the quantity will be that of the RealType. * * @param realType The existing RealType. * @param coordSys The coordinate system transformation. * @param domain The default domain set. * @throws TypeException if an instance cannot be created. * @throws VisADException if a core VisAD failure occurs. */ protected ScalarQuantity(RealType realType, CoordinateSystem coordSys, visad.Set domain) throws TypeException, VisADException { super(realType.getName(), new RealTupleType(realType, coordSys, domain)); this.realType = realType; }
/** * set up the types * * @throws VisADException On badness */ private void setupTypes() throws VisADException { if (curve_type == null) { RealTupleType latlon = RealTupleType.LatitudeLongitudeTuple; curve_type = new SetType(latlon); // (front_index -> // ((Latitude, Longitude) -> (front_red, front_green, front_blue))) count++; front_index = RealType.getRealType("front_index" + count); front_red = RealType.getRealType("front_red" + count); front_green = RealType.getRealType("front_green" + count); front_blue = RealType.getRealType("front_blue" + count); RealTupleType rgb = new RealTupleType(front_red, front_green, front_blue); front_inner = new FunctionType(latlon, rgb); front_type = new FunctionType(front_index, front_inner); fronts_type = new FunctionType(RealType.Time, front_type); } }
void setupServerData(LocalDisplay[] dpys) throws RemoteException, VisADException { Unit super_degree = CommonUnit.degree.scale(2.5); RealType lon = RealType.getRealType("lon", super_degree); DataReference ref = loadFile(); if (ref == null) { System.err.println("must specify netCDF file name"); System.exit(1); return; } FieldImpl netcdf_data = (FieldImpl) ref.getData(); // compute ScalarMaps from type components FunctionType ftype = (FunctionType) netcdf_data.getType(); RealTupleType dtype = ftype.getDomain(); MathType rntype = ftype.getRange(); int n = dtype.getDimension(); dpys[0].addMap(new ScalarMap((RealType) dtype.getComponent(0), Display.XAxis)); if (n > 1) { dpys[0].addMap(new ScalarMap((RealType) dtype.getComponent(1), Display.YAxis)); } if (n > 2) { dpys[0].addMap(new ScalarMap((RealType) dtype.getComponent(2), Display.ZAxis)); } if (rntype instanceof RealType) { dpys[0].addMap(new ScalarMap((RealType) rntype, Display.Green)); if (n <= 2) { dpys[0].addMap(new ScalarMap((RealType) rntype, Display.ZAxis)); } } else if (rntype instanceof RealTupleType) { int m = ((RealTupleType) rntype).getDimension(); RealType rr = (RealType) ((RealTupleType) rntype).getComponent(0); dpys[0].addMap(new ScalarMap(rr, Display.Green)); if (n <= 2) { if (m > 1) { rr = (RealType) ((RealTupleType) rntype).getComponent(1); } dpys[0].addMap(new ScalarMap(rr, Display.ZAxis)); } } dpys[0].addMap(new ConstantMap(0.5, Display.Red)); dpys[0].addMap(new ConstantMap(0.0, Display.Blue)); dpys[0].addReference(ref, null); System.out.println("now saving data as 'save.nc' and re-reading"); Plain plain = new Plain(); try { plain.save("save.nc", netcdf_data, true); netcdf_data = (FieldImpl) plain.open("save.nc"); } catch (IOException e) { System.err.println("Couldn't open \"save.nc\": " + e.getMessage()); System.exit(1); return; } }
/** * Sets the RealType of the contoured parameter. * * @param realType The RealType of the contoured parameter. May not be <code>null</code>. * @throws VisADException VisAD failure. * @throws RemoteException Java RMI failure. */ protected void setContourRealType(RealType realType) throws RemoteException, VisADException { if (!realType.equals(contourRealType)) { RealType oldValue = contourRealType; contourRealType = realType; setContourMaps(); firePropertyChange(CONTOUR_REAL_TYPE, oldValue, contourRealType); } }
public FlatField getImageDataFrom(final float channel) { FlatField imageData = null; try { MultiDimensionSubset select = null; Hashtable table = dataChoice.getProperties(); Enumeration keys = table.keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); if (key instanceof MultiDimensionSubset) { select = (MultiDimensionSubset) table.get(key); } } HashMap subset = select.getSubset(); imageData = data.getImage(channel, subset); uniqueRangeType = RealType.getRealType(rangeType.getName() + "_" + cnt++); imageData = changeRangeType(imageData, uniqueRangeType); } catch (Exception e) { LogUtil.logException("MultiSpectralDisplay.getImageDataFrom", e); } return imageData; }
void setupServerData(LocalDisplay[] dpys) throws RemoteException, VisADException { RealType x = RealType.getRealType("x"); RealType y = RealType.getRealType("y"); Unit super_degree = CommonUnit.degree.scale(2.5); RealType lon = RealType.getRealType("lon", super_degree); RealType radius = RealType.getRealType("radius"); RealTupleType cartesian = new RealTupleType(x, y); PolarCoordinateSystem polar_coord_sys = new PolarCoordinateSystem(cartesian); RealTupleType polar = new RealTupleType(lon, radius, polar_coord_sys, null); RealType vis_radiance = RealType.getRealType("vis_radiance"); RealType ir_radiance = RealType.getRealType("ir_radiance"); RealType[] types2 = {vis_radiance, ir_radiance}; RealTupleType radiance = new RealTupleType(types2); FunctionType image_polar = new FunctionType(polar, radiance); Unit[] units = {super_degree, null}; Linear2DSet domain_set = new Linear2DSet(polar, 0.0, 60.0, 61, 0.0, 60.0, 61, polar_coord_sys, units, null); FlatField imaget1 = new FlatField(image_polar, domain_set); FlatField.fillField(imaget1, 1.0, 30.0); dpys[0].addMap(new ScalarMap(x, Display.XAxis)); dpys[0].addMap(new ScalarMap(y, Display.YAxis)); dpys[0].addMap(new ScalarMap(vis_radiance, Display.Green)); dpys[0].addMap(new ConstantMap(0.5, Display.Red)); dpys[0].addMap(new ConstantMap(0.0, Display.Blue)); DataReferenceImpl ref_imaget1 = new DataReferenceImpl("ref_imaget1"); ref_imaget1.setData(imaget1); dpys[0].addReference(ref_imaget1, null); }
/** create parallel coordinates display for data */ public static void parallel(DisplayImpl display, FlatField data) throws VisADException, RemoteException { FunctionType ftype = (FunctionType) data.getType(); RealType index = (RealType) ftype.getDomain().getComponent(0); RealTupleType range = (RealTupleType) ftype.getRange(); int ncoords = range.getDimension(); int nrows = data.getLength(); Set index_set = data.getDomainSet(); float[][] samples = data.getFloats(false); RealType x = RealType.getRealType("coordinate"); RealType y = RealType.getRealType("value"); SetType xy = new SetType(new RealTupleType(x, y)); FunctionType ptype = new FunctionType(index, xy); FieldImpl pfield = new FieldImpl(ptype, index_set); for (int j = 0; j < nrows; j++) { float[][] locs = new float[2][ncoords]; for (int i = 0; i < ncoords; i++) { locs[0][i] = i; locs[1][i] = samples[i][j]; } Gridded2DSet set = new Gridded2DSet(xy, locs, ncoords); pfield.setSample(j, set, false); } // create a DataReference for river system DataReference parallel_ref = new DataReferenceImpl("parallel"); parallel_ref.setData(pfield); display.addMap(new ScalarMap(x, Display.XAxis)); display.addMap(new ScalarMap(y, Display.YAxis)); // enable axis scales display.getGraphicsModeControl().setScaleEnable(true); // link display to parallel display display.addReference(parallel_ref); }
static { Real mLfc = null; try { mLfc = (Real) RealType.getRealType( "LevelOfFreeConvection", AirPressure.getRealType().getDefaultUnit()) .missingData(); } catch (Exception e) { System.err.print("Couldn't initialize class: "); e.printStackTrace(); System.exit(1); } missingLfc = mLfc; }
/** * Obtains the RealType associated with this class. * * @return The RealType associated with this class. * @throws VisADException Couldn't perform necessary VisAD operation. */ public static RealType getRealType() throws VisADException { if (realType == null) { synchronized (MolecularWeightOfDryAir.class) { if (realType == null) { try { realType = RealType.getRealType( "MolecularWeightOfDryAir", SI.kilogram.divide(SI.mole), (Set) null); } /* * Can't happen because the above unit expression is valid. */ catch (UnitException e) { } } } } return realType; }
/** * I have no idea what this does. * * @param grid sampling grid * @param index some sort of index * @return a new flat field with something different * @throws RemoteException Java RMI error * @throws VisADException VisAD error */ private static FlatField hatFieldOld(Set grid, int index) throws VisADException, RemoteException { CoordinateSystem cs = grid.getCoordinateSystem(); boolean hasCS = (cs != null); RealTupleType rtt = (hasCS) ? cs.getReference() : ((SetType) grid.getType()).getDomain(); int latI = rtt.getIndex(RealType.Latitude); if (latI == -1) { throw new IllegalArgumentException(grid.toString()); } int lonI = rtt.getIndex(RealType.Longitude); if (lonI == -1) { throw new IllegalArgumentException(grid.toString()); } if (grid.getManifoldDimension() < 2) { throw new IllegalArgumentException(grid.toString()); } int[][] neighbors = grid.getNeighbors(index); LatLonPointImpl refPt = new LatLonPointImpl(); LatLonPointImpl neiPt = new LatLonPointImpl(); Bearing bearing = new Bearing(); float[] hat1 = new float[2]; float[] hat2 = new float[2]; float[][] hat = new float[2][grid.getLength()]; for (int i = 0; i < neighbors.length; i++) { float[][] refCoords = grid.indexToValue(new int[] {i}); if (hasCS) { refCoords = cs.toReference(refCoords); } float[][] neiCoords = grid.indexToValue(neighbors[i]); if (hasCS) { neiCoords = cs.toReference(neiCoords); } refPt.set(refCoords[latI][0], refCoords[lonI][0]); compute(refPt, neiPt, neiCoords[latI][0], neiCoords[lonI][0], -180, bearing, hat1); float d1 = (float) bearing.getDistance(); compute(refPt, neiPt, neiCoords[latI][1], neiCoords[lonI][1], 0, bearing, hat2); float d2 = (float) bearing.getDistance(); boolean bad1 = Double.isNaN(d1); boolean bad2 = Double.isNaN(d2); if (bad1 && bad2) { hat[0][i] = Float.NaN; hat[1][i] = Float.NaN; } else { if (bad1) { hat[0][i] = hat2[0]; hat[1][i] = hat2[1]; } else if (bad2) { hat[0][i] = hat1[0]; hat[1][i] = hat1[1]; } else { float tot = d1 + d2; float c1 = d2 / tot; float c2 = d1 / tot; float xhat = c1 * hat1[0] + c2 * hat2[0]; float yhat = c1 * hat1[1] + c2 * hat2[1]; float mag = (float) Math.sqrt(xhat * xhat + yhat * yhat); hat[0][i] = xhat / mag; hat[1][i] = yhat / mag; } } } FlatField hatField = new FlatField( new FunctionType( ((SetType) grid.getType()).getDomain(), new RealTupleType( RealType.getRealType("xHat", CommonUnit.dimensionless), RealType.getRealType("yHat", CommonUnit.dimensionless))), grid); hatField.setSamples(hat, false); return hatField; }
/** * The returned {@link visad.FlatField} will have NaN-s for those unit vector components that * could not be computed. * * @param grid The spatial grid. * @param index The index of the manifold dimension along which to compute the unit vector. * @return A field of components of the unit vector for the given manifold dimension. * @throws NullPointerException if the grid is <code>null</code>. * @throws IllegalArgumentException if the manifold dimension of the grid is less than 2 or if the * grid doesn't contain {@link visad.RealType#Latitude} and {@link visad.RealType#Longitude}. * @throws VisADException if a VisAD failure occurs. * @throws RemoteException if a Java RMI failure occurs. */ private static FlatField hatFieldNew(Set grid, int index) throws VisADException, RemoteException { CoordinateSystem cs = grid.getCoordinateSystem(); boolean hasCS = cs != null; RealTupleType rtt = (hasCS) ? cs.getReference() : ((SetType) grid.getType()).getDomain(); int latI = rtt.getIndex(RealType.Latitude); if (latI == -1) { throw new IllegalArgumentException(rtt.toString()); } int lonI = rtt.getIndex(RealType.Longitude); if (lonI == -1) { throw new IllegalArgumentException(rtt.toString()); } if (grid.getManifoldDimension() < 2) { throw new IllegalArgumentException(grid.toString()); } int[][] neighbors = grid.getNeighbors(index); LatLonPointImpl refPt = new LatLonPointImpl(); LatLonPointImpl neiPt = new LatLonPointImpl(); Bearing bearing = new Bearing(); float[] hat1 = new float[2]; float[] hat2 = new float[2]; float[][] hat = new float[2][grid.getLength()]; float[][] refCoords = null; float[][] neiCoords = null; float[][] domainSamples = grid.getSamples(false); refCoords = (hasCS) ? cs.toReference(Set.copyFloats(domainSamples)) : domainSamples; // If the grid is lat/lon or has an IdentityCoordinateSystem // don't do the rotation // TODO: handle rotated lat/lon grids if (!hasCS || (refCoords == domainSamples) || (Arrays.equals(refCoords[latI], domainSamples[latI]) && Arrays.equals(refCoords[lonI], domainSamples[lonI]))) { if (index == 0) { Arrays.fill(hat[0], 1); Arrays.fill(hat[1], 0); } else { Arrays.fill(hat[0], 0); Arrays.fill(hat[1], 1); } } else { float latBefore, lonBefore, latAfter, lonAfter; // int backOffset = (index==0) ? -180 : 0; // int foreOffset = (index==0) ? 0 : -180; int backOffset = -180; int foreOffset = 0; for (int i = 0; i < neighbors.length; i++) { refPt.set(refCoords[latI][i], refCoords[lonI][i]); if ((neighbors[i][0] < 0) || (neighbors[i][0] >= neighbors.length)) { latBefore = Float.NaN; lonBefore = Float.NaN; } else { latBefore = refCoords[latI][neighbors[i][0]]; lonBefore = refCoords[lonI][neighbors[i][0]]; } if ((neighbors[i][1] < 0) || (neighbors[i][1] >= neighbors.length)) { latAfter = Float.NaN; lonAfter = Float.NaN; } else { latAfter = refCoords[latI][neighbors[i][1]]; lonAfter = refCoords[lonI][neighbors[i][1]]; } compute(refPt, neiPt, latBefore, lonBefore, backOffset, bearing, hat1); float d1 = (float) bearing.getDistance(); compute(refPt, neiPt, latAfter, lonAfter, foreOffset, bearing, hat2); float d2 = (float) bearing.getDistance(); boolean bad1 = Double.isNaN(d1); boolean bad2 = Double.isNaN(d2); if (bad1 && bad2) { hat[0][i] = Float.NaN; hat[1][i] = Float.NaN; } else { if (bad1) { hat[0][i] = hat2[0]; hat[1][i] = hat2[1]; } else if (bad2) { hat[0][i] = hat1[0]; hat[1][i] = hat1[1]; } else { float tot = d1 + d2; float c1 = d2 / tot; float c2 = d1 / tot; float xhat = c1 * hat1[0] + c2 * hat2[0]; float yhat = c1 * hat1[1] + c2 * hat2[1]; float mag = (float) Math.sqrt(xhat * xhat + yhat * yhat); hat[0][i] = xhat / mag; hat[1][i] = yhat / mag; } } } } FlatField hatField = new FlatField( new FunctionType( ((SetType) grid.getType()).getDomain(), new RealTupleType( RealType.getRealType("xHat", CommonUnit.dimensionless), RealType.getRealType("yHat", CommonUnit.dimensionless))), grid); hatField.setSamples(hat, false); return hatField; }
/** * Returns the {@link visad.RealType} for the <em>Y</em> component of a grid-relative wind. The * <em>Y</em> component is in the direction of increasing second dimension of the grid. The name * of the component will be <em>Y</em><code>_Wind_Component</code>, where <em>Y</em> is the name * of the second dimension of the grid, and the default unit will be {@link #DEFAULT_SPEED_UNIT}. * * @param grid The grid. * @return The {@link visad.RealType} of the Y wind component. * @throws VisADException if a VisAD failure occurs. */ public static RealType yWindType(SampledSet grid) throws VisADException { return RealType.getRealType(yComponentName(grid), DEFAULT_SPEED_UNIT); }
/** * 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); }
/** * Returns the single value of this quantity corresponding to a numeric amount in the default * unit. The error estimate will be <code>null</code>. * * @param amount The numeric value. * @return The single value of this quantity corresponding to the input. * @throws VisADException VisAD failure. * @see #newReal(double amount, Unit unit) */ public final Real newReal(double amount) throws VisADException { return newReal(amount, realType.getDefaultUnit()); }
/** * Constructs from a name, default unit, default representational set, and an attribute mask. * * @param name The name of the scalar quantity. * @param unit The default unit of the scalar quantity. * @param set The default representational set of the quantity. It shall be an instance of <code> * visad.DoubleSet</code>, <code>visad.FloatSet</code>, <code>visad.Integer1DSet</code>, or * <code>null</code>. If <code>null</code>, then the default is <code>visad.FloatSet</code>. * @param attrMask The attribute mask: <code>0</code> or <code>INTERVAL</code>. * @throws VisADException VisAD failure. * @see #ScalarQuantity(RealType realType) */ protected ScalarQuantity(String name, Unit unit, visad.Set set, int attrMask) throws VisADException { this(RealType.getRealType(name, unit, set, attrMask)); }
/** used by preParse */ private static String preParseOnce(String s, FormulaManager fm) { // convert to lower case String l = s.toLowerCase(); // scan entire string int len = l.length(); boolean letter = false; String ns = ""; for (int i = 0; i < len; i++) { if (!letter && i < len - 1 && l.substring(i, i + 2).equals("d(")) { // convert d(x)/d(y) notation to standard derive(x, y) notation i += 2; int s1 = i; for (int paren = 1; paren > 0; i++) { // check for correct syntax if (i >= len) return s; char c = l.charAt(i); if (c == '(') paren++; if (c == ')') paren--; } int e1 = i - 1; // check for correct syntax if (i > len - 3 || !l.substring(i, i + 3).equals("/d(")) return s; i += 3; int s2 = i; for (int paren = 1; paren > 0; i++) { // check for correct syntax if (i >= len) return s; char c = l.charAt(i); if (c == '(') paren++; if (c == ')') paren--; } int e2 = i - 1; ns = ns + "derive(" + s.substring(s1, e1) + "," + s.substring(s2, e2) + ")"; i--; } else if (!letter && i < len - 4 && l.substring(i, i + 5).equals("link(")) { // evaluate link(code) notation and replace with link variable i += 5; int s1 = i; try { while (l.charAt(i) != '(') i++; } catch (ArrayIndexOutOfBoundsException exc) { // incorrect syntax return s; } i++; int e1 = i - 1; int s2 = i; for (int paren = 2; paren > 1; i++) { // check for correct syntax if (i >= len) return s; char c = l.charAt(i); if (c == '(') paren++; if (c == ')') paren--; } int e2 = i - 1; // check for correct syntax if (i >= len || l.charAt(i) != ')') return s; String prestr = s.substring(s1, e1) + "("; String str = prestr; // parse method's arguments; determine if they are Data or RealType String sub = s.substring(s2, e2); StringTokenizer st = new StringTokenizer(sub, ",", false); boolean first = true; Vector v = new Vector(); while (st.hasMoreTokens()) { String token = st.nextToken(); if (first) first = false; else str = str + ","; RealType rt = RealType.getRealTypeByName(token); String sv = (rt == null ? "visad.Data" : "visad.RealType"); v.add(sv); str = str + sv; } str = str + ")"; // obtain Method object Method[] meths = FormulaUtil.stringsToMethods(new String[] {str}); if (meths[0] == null) { // attempt to identify any matching methods by compressing // some or all of the arguments into array form int vlen = v.size(); Vector vstrs = new Vector(); for (int iv = 0; iv < vlen; iv++) { String si = (String) v.elementAt(iv); int lv = iv; String sl; while (lv < vlen) { sl = (String) v.elementAt(lv++); if (!sl.equals(si)) { break; } str = prestr; first = true; for (int j = 0; j < vlen; j++) { if (first) first = false; else str = str + ","; String sj = (String) v.elementAt(j); str = str + sj; if (iv == j) { str = str + "[]"; j = lv - 1; } } str = str + ")"; vstrs.add(str); } } String[] strlist = new String[vstrs.size()]; vstrs.toArray(strlist); meths = FormulaUtil.stringsToMethods(strlist); int found = -1; for (int j = 0; j < meths.length && found < 0; j++) { if (meths[j] != null) found = j; } if (found >= 0) meths[0] = meths[found]; else { // could not find a matching method return s; } } // store method object in a link variable String link = "link" + (++linkNum); try { fm.setThing(link, new VMethod(meths[0])); } // catch any errors setting the link variable catch (FormulaException exc) { return s; } catch (VisADException exc) { return s; } catch (RemoteException exc) { return s; } ns = ns + "linkx(" + link + "," + s.substring(s2, e2) + ")"; } else if (!letter) { int j = i; char c = l.charAt(j++); while (j < len && ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9'))) { c = l.charAt(j++); } // check for end-of-string if (j == len) return ns + s.substring(i, len); if (c == '[') { // convert x[y] notation to standard getSample(x, y) notation int k = j; for (int paren = 1; paren > 0; k++) { // check for correct syntax if (k >= len) return s; c = l.charAt(k); if (c == '[') paren++; if (c == ']') paren--; } ns = ns + "getSample(" + s.substring(i, j - 1) + "," + s.substring(j, k - 1) + ")"; i = k - 1; } else ns = ns + s.charAt(i); } else { // append character to new string ns = ns + s.charAt(i); } char c = (i < len) ? l.charAt(i) : '\0'; letter = (c >= 'a' && c <= 'z'); } return ns; }
/** 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); }
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(); } }
void setupServerData(LocalDisplay[] dpys) throws RemoteException, VisADException { RealType ir_radiance = RealType.getRealType("ir_radiance"); RealType count = RealType.getRealType("count"); FunctionType ir_histogram = new FunctionType(ir_radiance, count); RealType vis_radiance = RealType.getRealType("vis_radiance"); int size = 64; FlatField histogram1 = FlatField.makeField(ir_histogram, size, false); Real direct = new Real(ir_radiance, 2.0); Real[] reals3; reals3 = new Real[] {new Real(count, 1.0), new Real(ir_radiance, 2.0), new Real(vis_radiance, 1.0)}; RealTuple direct_tuple = new RealTuple(reals3); dpys[0].addMap(new ScalarMap(vis_radiance, Display.ZAxis)); dpys[0].addMap(new ScalarMap(ir_radiance, Display.XAxis)); dpys[0].addMap(new ScalarMap(count, Display.YAxis)); dpys[0].addMap(new ScalarMap(count, Display.Green)); GraphicsModeControl mode = dpys[0].getGraphicsModeControl(); mode.setPointSize(5.0f); mode.setPointMode(false); mode.setScaleEnable(true); DisplayRendererJ3D dr = (DisplayRendererJ3D) dpys[0].getDisplayRenderer(); dr.setClip(0, true, 1.0f, 0.0f, 0.0f, -1.0f); dr.setClip(1, true, -1.0f, 0.0f, 0.0f, -1.0f); dr.setClip(2, true, 0.0f, 1.0f, 0.0f, -1.0f); dr.setClip(3, true, 0.0f, -1.0f, 0.0f, -1.0f); dr.setClip(4, true, 0.0f, 0.0f, 1.0f, -1.0f); dr.setClip(5, true, 0.0f, 0.0f, -1.0f, -1.0f); DataReferenceImpl ref_direct = new DataReferenceImpl("ref_direct"); ref_direct.setData(direct); DataReference[] refs1 = new DataReferenceImpl[] {ref_direct}; dpys[0].addReferences(new DirectManipulationRendererJ3D(), refs1, null); DataReferenceImpl ref_direct_tuple; ref_direct_tuple = new DataReferenceImpl("ref_direct_tuple"); ref_direct_tuple.setData(direct_tuple); DataReference[] refs2 = new DataReference[] {ref_direct_tuple}; dpys[0].addReferences(new DirectManipulationRendererJ3D(), refs2, null); DataReferenceImpl ref_histogram1; ref_histogram1 = new DataReferenceImpl("ref_histogram1"); ref_histogram1.setData(histogram1); DataReference[] refs3 = new DataReference[] {ref_histogram1}; dpys[0].addReferences(new DirectManipulationRendererJ3D(), refs3, null); new Delay(500); dpys[1].addMap(new ScalarMap(ir_radiance, Display.XAxis)); dpys[1].addMap(new ScalarMap(count, Display.YAxis)); dpys[1].addMap(new ScalarMap(count, Display.Green)); GraphicsModeControl mode2 = dpys[1].getGraphicsModeControl(); mode2.setPointSize(5.0f); mode2.setPointMode(false); dpys[1].addReferences(new DirectManipulationRendererJ2D(), refs1, null); dpys[1].addReferences(new DirectManipulationRendererJ2D(), refs2, null); dpys[1].addReferences(new DirectManipulationRendererJ2D(), refs3, null); dpys[0].addDisplayListener(this); dpys[1].addDisplayListener(this); }
void setupServerData(LocalDisplay[] dpys) throws RemoteException, VisADException { RealType xr = RealType.getRealType("xr"); RealType yr = RealType.getRealType("yr"); RealType zr = RealType.getRealType("zr"); RealType wr = RealType.getRealType("wr"); RealType[] types3d = {xr, yr, zr}; RealTupleType earth_location3d = new RealTupleType(types3d); FunctionType grid_tuple = new FunctionType(earth_location3d, wr); // int NX = 32; // int NY = 32; // int NZ = 32; int NX = 35; int NY = 35; int NZ = 35; Integer3DSet set = new Integer3DSet(NX, NY, NZ); FlatField grid3d = new FlatField(grid_tuple, set); float[][] values = new float[1][NX * NY * NZ]; int k = 0; for (int iz = 0; iz < NZ; iz++) { // double z = Math.PI * (-1.0 + 2.0 * iz / (NZ - 1.0)); double z = Math.PI * (-1.0 + 2.0 * iz * iz / ((NZ - 1.0) * (NZ - 1.0))); for (int iy = 0; iy < NY; iy++) { double y = -1.0 + 2.0 * iy / (NY - 1.0); for (int ix = 0; ix < NX; ix++) { double x = -1.0 + 2.0 * ix / (NX - 1.0); double r = x - 0.5 * Math.cos(z); double s = y - 0.5 * Math.sin(z); double dist = Math.sqrt(r * r + s * s); values[0][k] = (float) ((dist < 0.1) ? 10.0 : 1.0 / dist); k++; } } } grid3d.setSamples(values); dpys[0].addMap(new ScalarMap(xr, Display.XAxis)); dpys[0].addMap(new ScalarMap(yr, Display.YAxis)); dpys[0].addMap(new ScalarMap(zr, Display.ZAxis)); ScalarMap xrange = new ScalarMap(xr, Display.SelectRange); ScalarMap yrange = new ScalarMap(yr, Display.SelectRange); ScalarMap zrange = new ScalarMap(zr, Display.SelectRange); dpys[0].addMap(xrange); dpys[0].addMap(yrange); dpys[0].addMap(zrange); GraphicsModeControl mode = dpys[0].getGraphicsModeControl(); mode.setScaleEnable(true); if (nice) mode.setTransparencyMode(DisplayImplJ3D.NICEST); mode.setTexture3DMode(texture3DMode); // new RealType duh = RealType.getRealType("duh"); int NT = 32; Linear2DSet set2 = new Linear2DSet(0.0, (double) NX, NT, 0.0, (double) NY, NT); RealType[] types2d = {xr, yr}; RealTupleType domain2 = new RealTupleType(types2d); FunctionType ftype2 = new FunctionType(domain2, duh); float[][] v2 = new float[1][NT * NT]; for (int i = 0; i < NT * NT; i++) { v2[0][i] = (i * i) % (NT / 2 + 3); } // float[][] v2 = {{1.0f,2.0f,3.0f,4.0f}}; FlatField field2 = new FlatField(ftype2, set2); field2.setSamples(v2); dpys[0].addMap(new ScalarMap(duh, Display.RGB)); ScalarMap map1color = new ScalarMap(wr, Display.RGBA); dpys[0].addMap(map1color); ColorAlphaControl control = (ColorAlphaControl) map1color.getControl(); control.setTable(buildTable(control.getTable())); DataReferenceImpl ref_grid3d = new DataReferenceImpl("ref_grid3d"); ref_grid3d.setData(grid3d); DataReferenceImpl ref2 = new DataReferenceImpl("ref2"); ref2.setData(field2); ConstantMap[] cmaps = {new ConstantMap(0.0, Display.TextureEnable)}; dpys[0].addReference(ref2, cmaps); dpys[0].addReference(ref_grid3d, null); }
/** * Find pre-determined contouring values for this parameter by name from the paramdefaults.xml * file, or compute reasonable values of contouring values from the data itself. min no contour * line below this value; base a contour line must have this value (even if not seen), other * values are this value +/- some multiple of the interval; max no contour with greater value than * this; interval if negative, means show dashed lines below base value. * * @param paramName variable name from the data source * @param rangeType one of them ViaAD RealType thingys for the data * @param displayUnit the unit the data will appear on screen * @param range The range * @param contourInfo Default contour info * @return a ContourInfo object with appropriate contouring values */ public ContourInfo findContourInfo( String paramName, RealType rangeType, Unit displayUnit, Range range, ContourInfo contourInfo) { // make an empty ContourInfo object if (contourInfo == null) { contourInfo = new ContourInfo(Double.NaN, Double.NaN, Double.NaN, Double.NaN); } // Find pre-determined contour values for this parameter name ContourInfo dflt = getParamDefaultsEditor().getParamContourInfo(paramName); if (dflt != null) { // Set pre-determined values into local data "contourInfo" // System.out.println(" DC: findContourInfo got params contouring values "+ dflt.toString() // ); contourInfo.setIfDefined(dflt); } if (contourInfo.isDefined()) { return contourInfo; } float min = 0.0f; float max = 1100.0f; float clBase = Float.NaN; float clInterval = Float.NaN; float clMin = Float.NaN; float clMax = Float.NaN; try { // convert data's max/min values from native units to display units // as seen by user in plots; use VisAD methods if (Unit.canConvert(rangeType.getDefaultUnit(), displayUnit)) { Real dispVal = new Real(rangeType, range.min); min = (float) dispVal.getValue(displayUnit); dispVal = new Real(rangeType, range.max); max = (float) dispVal.getValue(displayUnit); } else { min = (float) range.min; max = (float) range.max; } // use data max and min values in display units to find appropriate // workable values for contour interval, base, min, and max. double span = Math.abs(max - min); // GEMPAK alogrithm for 5 to 10 contours in a field from grcval.f int scale = (int) (Math.log(span) / Math.log(10)); if (span < 1) { scale = scale - 1; } double cscale = Math.pow(10, scale); double crange = span / cscale; int nrange = (int) crange; double rint = (nrange + 1) * .1 * cscale; if (Double.isInfinite(rint)) { rint = span; } if ((span <= 300.0) && (span > 5.0)) { /* typical case */ clInterval = (float) rint; clMin = clBase = clInterval * ((int) (min / clInterval)); clMax = clInterval * (1 + (int) (max / clInterval)); } else if (span <= 5.0) { // for max-min less than 5 clInterval = (float) rint; clMin = clBase = min; clMax = max; } else { // for really big ranges, span > 300 make ints clInterval = (float) ((int) rint); clMin = clBase = (float) ((int) min); clMax = (float) ((int) max); } clMax = clMax + clInterval; clMin = clMin - clInterval; } catch (Exception exp) { logException("Set contour levels for " + paramName, exp); } // this should never be true; must be a leftover if (clInterval == 0.0f) { // System.out.println(" DC: findContourInfo got default contour interval of 20.0"); clInterval = 20.0f; } // IF any contouring values were not supplied by the parameter-name-based // information; then load in the computed values made here. if (!contourInfo.getIntervalDefined() && (contourInfo.getLevelsString() == null)) { contourInfo.setInterval(clInterval); } if (!contourInfo.getBaseDefined()) { contourInfo.setBase(clBase); } if (!contourInfo.getMinDefined()) { contourInfo.setMin(clMin); } if (!contourInfo.getMaxDefined()) { contourInfo.setMax(clMax); } return contourInfo; }
/** Make the <code>DataChoices</code> for this <code>DataSource</code>. */ public void doMakeDataChoices() { if (sources == null) { return; } String stationModelName = (String) getProperty(PROP_STATIONMODELNAME); Hashtable properties = Misc.newHashtable(DataChoice.PROP_ICON, "/auxdata/ui/icons/Placemark16.gif"); if (stationModelName != null) { properties.put(PROP_STATIONMODELNAME, stationModelName); } if (!getDefaultLevels().isEmpty()) { properties.put(DataSelection.PROP_DEFAULT_LEVELS, getDefaultLevels()); } DataChoice uberChoice = null; /* Might want to do this someday uberChoice = new DirectDataChoice(this, sources, getName(), getDataName(), getPointCategories(), properties); */ if (sources.size() > 1) { uberChoice = new CompositeDataChoice( this, sources, getName(), getDataName(), getPointCategories(), properties); addDataChoice(uberChoice); } for (int i = 0; i < sources.size(); i++) { String dataChoiceDesc = getDescription(); String dataChoiceName = getDataName(); if (uberChoice != null) { dataChoiceDesc = IOUtil.getFileTail(sources.get(i).toString()); dataChoiceName = IOUtil.getFileTail(sources.get(i).toString()); } DataChoice choice = new DirectDataChoice( this, new Integer(i), dataChoiceDesc, dataChoiceName, getPointCategories(), properties); /* We'd like to create sub choices for each parameter but we don't really know the parameters until we read the data and that can be expensive DirectDataChoice subChoice = new DirectDataChoice(this, (String) sources.get(i), getDescription(), getDataName(), getPointCategories(), properties); choice.addDataChoice(subChoice);*/ if (uberChoice != null) { ((CompositeDataChoice) uberChoice).addDataChoice(choice); } else { addDataChoice(choice); } // Only add the grid data choices for the first source if (i > 0) { continue; } try { FieldImpl sample = (makeGridFields ? getSample(choice) : null); if (sample != null) { for (int dataChoiceType = 0; dataChoiceType < 2; dataChoiceType++) { Hashtable seenFields = new Hashtable(); if (ucar.unidata.data.grid.GridUtil.isTimeSequence(sample)) { sample = (FieldImpl) sample.getSample(0); } PointOb ob = (PointOb) sample.getSample(0); Tuple tuple = (Tuple) ob.getData(); TupleType tupleType = (TupleType) tuple.getType(); MathType[] types = tupleType.getComponents(); CompositeDataChoice compositeDataChoice = null; for (int typeIdx = 0; typeIdx < types.length; typeIdx++) { if (!(types[typeIdx] instanceof RealType)) { continue; } RealType type = (RealType) types[typeIdx]; if (!canCreateGrid(type)) { continue; } // List gridCategories = // DataCategory.parseCategories("OA Fields;GRID-2D-TIME;"); List gridCategories = DataCategory.parseCategories("GRID-2D-TIME;", false); if (compositeDataChoice == null) { compositeDataChoice = new CompositeDataChoice( this, "", "Grid Fields from Objective Analysis", "Gridded Fields " + ((dataChoiceType == 0) ? "" : "(with first guess)"), Misc.newList(DataCategory.NONE_CATEGORY), null); addDataChoice(compositeDataChoice); } String name = ucar.visad.Util.cleanTypeName(type.toString()); if (seenFields.get(name) != null) { continue; } seenFields.put(name, name); List idList = Misc.newList(new Integer(i), type); if (dataChoiceType == 1) { idList.add(new Boolean(true)); } DataChoice gridChoice = new DirectDataChoice(this, idList, name, name, gridCategories, (Hashtable) null); compositeDataChoice.addDataChoice(gridChoice); } } } } catch (Exception exc) { throw new WrapperException("Making grid parameters", exc); } // if(true) break; } }