/** * @file Application * @author Robert S Laramee * @version 1.0 * @see Test01.java *

* start date Saturday 05 Feb 2000 * finish date *

* @description This is a modification of Test01.java *

* Handy numbers: * 128 x 128 x 128 = 2,097,152 * 64 x 64 x 64 = 262,144 * 32 x 32 x 32 = 32,768 * 16 x 16 x 16 = 4,096 **/ import rlaramee.*; import javax.swing.*; import java.awt.Component; import java.rmi.RemoteException; import java.awt.*; import java.awt.event.*; import visad.*; import visad.java3d.DisplayImplJ3D; import visad.util.ContourWidget; public class Application { private UserInterface ui = null; private boolean debug = Constant.DEBUG; /** * see page 53 of VisAD Developers Guide for the analogies between * C and VisAD data structuring tools. * RealType -> float, double, int * RealTupleType -> struct * FunctionType -> array */ private RealTupleType headLocation3D; private RealType density; private FunctionType gridFunction; private Integer3DSet integer3DSet; private FlatField field; private DataReferenceImpl grid3DdataRef; /** * constructors, called from this.main() method */ public Application() { } public Application(String[] args) throws RemoteException, VisADException { /** * only use this for perfomance evaluation * byte octant = 0; * byte[] levels = {0, -1, -1, -1, -1, -1, -1 }; * * new MarchingCubes( * new BinaryCubeReader( * (byte)0, true, Constant.MR).run(octant, levels, Constant.HEAD)); */ ui = new UserInterface(this); /* "Array constants can only be used in initializers." */ RealType[] types3D = {RealType.XAxis, RealType.YAxis, RealType.ZAxis}; headLocation3D = new RealTupleType(types3D ); density = new RealType("density", null, null); gridFunction = new FunctionType(headLocation3D, density); if (debug) System.out.println("ARrenderer() FunctionType" + "gridFunction=" + gridFunction); try { initializeField((ui.getGridDimension(ui.getLevel())), (ui.getGridDimension(ui.getLevel())), (ui.getGridDimension(ui.getLevel()))); } catch (RemoteException re) {} catch (VisADException ve) {} /* will print out all the data: * if (debug) System.out.println("ARrenderer: FlatField field=" + * field); */ initializeMaps(); /* must come before dataRef */ grid3DdataRef = new DataReferenceImpl("ref_grid3D"); grid3DdataRef.setData(field); ui.getDisplay().addReference(grid3DdataRef, null); /* should not be necessary - it is implict in addReference() * display.reDisplayAll(); */ ui.initialize(); } /** * @param filename -the file with the raw data * @param rows -number of rows (along x axis) in the volume data * @param columns -number of columns (along y axis) in the volume data * @param layers -number of layers (along z axis) in the volume data */ public int initializeField(int rows, int columns, int layers) throws RemoteException, VisADException{ if (debug) System.out.println("ARrenderer.initializeField()"); /* "use an Integer3DSet since your samples lie on an integer * lattice - you would use Gridded3DSet for a curvy lattice" * -B Hibbard */ integer3DSet = new Integer3DSet(headLocation3D, rows, columns, layers); if (debug) System.out.println("ARrenderer.initializeField():" + " integer3Dset=" + integer3DSet); /* "your data should be a FlatField rather than a Set" * -B Hibbard */ field = new FlatField(gridFunction, integer3DSet); /* set dependent density values */ field.setSamples(initializeData(rows, columns, layers)); return 0; } /** * @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(int rows, int columns, int layers) { System.out.println("ARrenderer.initializeData(): rows=" + rows + ", columns=" + columns + ", layers=" + layers); /* a FlatField is like a domain */ float[][] data = new float[1][rows * columns * layers]; //data = (new ASCIIfloatReader(rows, columns, layers)).run(fileName); for (int i = 0; i < (rows * columns * layers); i++) { data[0][i] = (float)0.0; } data[0][0] = (float)1.0; /* to set max */ data[0][1] = (float)0.001; /* to set interval */ if (debug) { for (int i = 0; i < (rows * columns * layers); i++) { System.out.print("[" + data[0][i] + "]"); } } System.out.println(); return data; } /** * @param -the display to add the maps to */ public int initializeMaps() throws RemoteException, VisADException { if (debug) System.out.println("ARrenderer.initializeMaps()"); ui.getDisplay().clearMaps(); ui.getDisplay().addMap(new ScalarMap(RealType.YAxis, Display.YAxis)); ui.getDisplay().addMap(new ScalarMap(RealType.XAxis, Display.XAxis)); ui.getDisplay().addMap(new ScalarMap(RealType.ZAxis, Display.ZAxis)); ui.getDisplay().addMap(new ScalarMap(density, Display.Red)); ui.getDisplay().addMap(new ConstantMap(0.5, Display.Blue )); //ui.getDisplay().addMap(new ConstantMap(0.5, Display.Green)); ui.getDisplay().addMap(new ScalarMap(density, Display.IsoContour)); return 0; } /** * get() methods called from UserInterface.java */ public DataReferenceImpl getDataReferenceImpl() { return grid3DdataRef; } public Field getField() { return field; } /** * */ public static void main(String[] args) throws RemoteException, VisADException { Application application = new Application(args); } /** * */ public String toString() { return ": colored iso-surfaces from regular grids and ContourWidget"; } }