NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.
To learn about what's going on, see About the Archive Site.
Hello, we are having a problem which involves a data reference being used for a UnionSet, and then for a FlatField. When the data reference's setData() is initially passed a UnionSet, the data is displayed. Sometime later, the data reference's setData() is called again, but this time a FlatField is passed to it. The results are inconsistant. Sometimes the FlatField is displayed, and sometimes it isn't. Attached is a sample program (DataRefBug.java) which illustrates the problem. You can run it in 2 ways: > java DataRefBug - will display the UnionSet data first (a cross). Click on the "Change Data" button, and the data reference's setData() is passed a FlatField. In all our tests, the visad window goes black, and the FlatField is not shown. OR > javaDataRefBug 0 - will display the FlatField first. Click on the "Change Data" button, and the data reference's setData() is passed a UnionSet. In all our tests, this works and the UnionSet data is shown. You can continue to click the "Change Data" button to cycle between the UnionSet data and the FlatField data. Does anyone have any ideas? Why does the display correctly update when the FlatField is shown first and not when the UnionSet is shown first? Thanks, Jim. --- Jim Koutsovasilis Bureau of Meteorology, Australia jimk@xxxxxxxxxx
// DataRefBug.java // Java import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.rmi.RemoteException; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; // VisAD import visad.DataReferenceImpl; import visad.Display; import visad.FlatField; import visad.FunctionType; import visad.Gridded2DDoubleSet; import visad.RealTupleType; import visad.RealType; import visad.ScalarMap; import visad.Set; import visad.UnionSet; import visad.VisADException; import visad.java3d.DisplayImplJ3D; /** * Replicates the bug where changing a data reference's data does not * result in the data being re-drawn. */ public class DataRefBug { private DisplayImplJ3D display; private DataReferenceImpl dataRef; private FunctionType functionType; private boolean showingCross; public DataRefBug(final boolean startWithCross) throws VisADException, RemoteException { display = new DisplayImplJ3D("display"); display.getDisplayRenderer().setBoxOn(false); display.addMap(new ScalarMap(RealType.Latitude, Display.YAxis)); display.addMap(new ScalarMap(RealType.Longitude, Display.XAxis)); final RealTupleType domainType RealTupleType.LatitudeLongitudeTuple; final RealType rangeType = RealType.getRealType("height"); functionType = new FunctionType(domainType, rangeType); display.addMap(new ScalarMap(rangeType, Display.RGBA)); dataRef = new DataReferenceImpl("data_ref"); if (startWithCross) { dataRef.setData(createCross()); } else { dataRef.setData(createField()); } display.addReference(dataRef); showingCross = startWithCross; JFrame frame = new JFrame(); final JPanel panel = new JPanel(new BorderLayout()); panel.add(display.getComponent(), BorderLayout.CENTER); final JButton button = new JButton("Change Data"); button.addActionListener(new ButtonListener()); panel.add(button, BorderLayout.SOUTH); frame.getContentPane().add(panel); frame.setSize(500, 500); frame.setVisible(true); } // DataRefBug.DataRefBug() private Set createCross() throws VisADException { final RealTupleType type = RealTupleType.LatitudeLongitudeTuple; final Gridded2DDoubleSet [] sets = new Gridded2DDoubleSet[2]; final double [][] samples = new double[2][2]; samples[0][0] = 1; samples[1][0] = -1; samples[0][1] = -1; samples[1][1] = 1; sets[0] = new Gridded2DDoubleSet(type, samples, 2); samples[0][0] = -1; samples[1][0] = -1; samples[0][1] = 1; samples[1][1] = 1; sets[1] = new Gridded2DDoubleSet(type, samples, 2); return new UnionSet(sets); } // DataRefBug.createCross() private class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent event) { try { if (showingCross) { dataRef.setData(createField()); } else { dataRef.setData(createCross()); } showingCross = !showingCross; } catch (VisADException ex) { ex.printStackTrace(); } catch (RemoteException ex) { ex.printStackTrace(); } } // ButtonListener.actionPerformed() } // class DataRefBug.ButtonListener() private FlatField createField() throws VisADException, RemoteException { return FlatField.makeField1(functionType, -1, 1, 10, -1, 1, 20); } // DataRefBug.createField() public static final void main(String [] args) throws VisADException, RemoteException { boolean startWithCross = true; if (args.length > 0) { startWithCross = false; } new DataRefBug(startWithCross); } // DataRefBug.main() } // class DataRefBug
visad
archives: