Hello Bill and the VisAD list,
i'm having a problem "resetting" a display and associating it with a new
data set. What i'd like to do is choose a set of data to render to a
DisplayImplJ3D from a menu (the menus are all set up). When the user
chooses the set of data from the menu, the application should go and read
and load the new data from another data file and renderer it (using the
same display and controls). Here is the code i have, but it's missing
some key ingredient to relink the display and contour widget with the new
data. i tried to isolate the code necessary to reassociate the new data
with the old display, but it doesn't seem to work:
private UserInterface ui = null;/* contains display and contour widget */
private RealTupleType headLocation3D;
private RealType density;
private FunctionType gridFunction;
private float[][] data;
private Integer3DSet integer3DSet;
private FlatField field;
private DisplayImplJ3D display;
/**
* constructor, called from this.main() method
*/
public ARrenderer() { }
public ARrenderer(String[] args)
throws RemoteException, VisADException {
ui = new UserInterface(this);
display = ui.getDisplay();
RealType[] types3D = {RealType.XAxis, RealType.YAxis,RealType.ZAxis};
headLocation3D = new RealTupleType(types3D );
density = new RealType("density", null, null);
gridFunction = new FunctionType(headLocation3D, density);
createField("headLevel2floats.ascii", 8 , 8, 8);
ui.initialize();
}
/**
* @param fileName -the file to read the new data from
* @param rows -the number of rows in the volume data
* @param columns -the number of columns in the volume data
* @param layers -the number of layers in the volume data
*/
public void createField(String fileName,
int rows, int columns, int layers) throws
RemoteException,VisADException {
integer3DSet = new Integer3DSet(headLocation3D, rows, columns,layers);
field = new FlatField(gridFunction, integer3DSet);
field.setSamples(initializeData(fileName, rows, columns, layers));
initializeMaps(display); /* must come before dataRef */
DataReferenceImpl grid3DdataRef = new DataReferenceImpl("ref_grid3D");
grid3DdataRef.setData(field);
display.removeAllReferences();
display.addReference(grid3DdataRef, null);
display.reDisplayAll();
}
/**
* This method reads the new data from a file.
* @param fileName -the file to read the new data from
* @param rows -the number of rows in the volume data
* @param columns -the number of columns in the volume data
* @param layers -the number of layers in the volume data
*/
private float[][] initializeData(String fileName,
int rows, int columns, int layers) {
data = new float[1][rows * columns * layers];
data = (new ASCIIfloatReader(rows, columns, layers)).run(fileName);
return data;
}
/**
* @param -the display to add the maps to
*/
private int initializeMaps(DisplayImplJ3D display) throws
RemoteException, VisADException {
display.addMap(new ScalarMap(RealType.YAxis, Display.YAxis));
display.addMap(new ScalarMap(RealType.XAxis, Display.XAxis));
display.addMap(new ScalarMap(RealType.ZAxis, Display.ZAxis));
display.addMap(new ScalarMap(density, Display.Red));
display.addMap(new ConstantMap(0.5, Display.Blue ));
display.addMap(new ConstantMap(0.5, Display.Green));
ScalarMap map1contour = new ScalarMap(density, Display.IsoContour);
display.addMap(map1contour);
return 0;
}
-cheers, bob
PS Thanks to Bill Hibbard for answering my last question(s).
Robert S Laramee tel: (603) 868-1361 (new as of 19 Jan '00)
9 Woodman Ave, #316 office: (603) 862-0350
Durham, NH 03828 URL: http://www.cs.unh.edu/~rlaramee