/* VisAD Tutorial Copyright (C) 2000 Ugo Taddei */ package tutorial.s6; // Import needed classes import visad.*; import visad.util.*; import visad.java3d.DisplayImplJ3D; import java.rmi.RemoteException; import java.awt.*; import javax.swing.*; import java.awt.event.*; /** VisAD Tutorial example Cube Former P4_10.java */ public class Cube{ // Declare variables // The domain quantities easting and northing // and the dependent quantity temperature private RealType easting, northing, altitude; private RealType temperature; // Tuple to pack easting and northing together private RealTupleType domain_tuple; // The function (domain_tuple -> temperature ) private FunctionType func_domain_temp; // Our Data values for the domain are represented by the Set private Set domain_set; // The Data class FlatField private FlatField vals_ff; private int NCOLS = 32; private int NROWS = 32; private int NLEVS = 16; public Cube() throws RemoteException, VisADException { this(false); } public Cube(boolean random) throws RemoteException, VisADException { // Create the quantities // Use RealType(String name, Unit unit, Set set); northing = RealType.getRealTypeByName("northing"); easting = RealType.getRealTypeByName("easting"); altitude = RealType.getRealTypeByName("altitude"); domain_tuple = new RealTupleType(easting, northing, altitude); // The independent variable temperature = RealType.getRealTypeByName("temperature"); // Create a FunctionType (domain_tuple -> range_tuple ) // Use FunctionType(MathType domain, MathType range) func_domain_temp = new FunctionType( domain_tuple, temperature); // Create the domain Set // Integer3DSet(MathType type, int lengthX, int lengthY, int lengthZ) domain_set = new Linear3DSet(domain_tuple, -Math.PI, Math.PI, NROWS, -Math.PI, Math.PI, NCOLS, -Math.PI, Math.PI, NLEVS ); // Our 'flat' array // Fill our 'flat' array with the temperature values // by looping over NCOLS and NROWS // but first get the Set samples to help with the calculations // Create a FlatField // Use FlatField(FunctionType type, Set domain_set) vals_ff = new FlatField( func_domain_temp, domain_set); // ...and put the temperature values above into it // Note the argument false, meaning that the array won't be copied float[][] samples; if(random) samples = createRandomSamples(); else samples = createSimpleSamples(); vals_ff.setSamples( samples , false ); } private float[][] createSimpleSamples(){ float[][] flat_samples = new float[1][NCOLS * NROWS * NLEVS]; float[][] set_samples = null; try { set_samples = domain_set.getSamples( true ); } catch (Exception ex) { ex.printStackTrace(); } // Note the use of an index variable, indicating the order of the samples int index = 0; for(int l = 0; l < NLEVS; l++) for(int c = 0; c < NCOLS; c++) for(int r = 0; r < NROWS; r++){ // set value for RealType temperature flat_samples[0][ index ] = (float) (Math.sin( 0.850 * (double) set_samples[0][ index ]) ) + (float) Math.exp( - 1.0/(Math.pow((double) set_samples[1][ index ]*0.5/Math.PI, 2.0 ) -1.0 )) + (float) (Math.cos( 0.650 * (double) set_samples[2][ index ]) ) ; // increment index index++; } return flat_samples; } private float[][] createRandomSamples(){ float[][] flat_samples = new float[1][NCOLS * NROWS * NLEVS]; // Note the use of an index variable, indicating the order of the samples int index = 0; for(int l = 0; l < NLEVS; l++) for(int c = 0; c < NCOLS; c++) for(int r = 0; r < NROWS; r++){ // set value for RealType temperature flat_samples[0][ index ] = (float) Math.random(); // increment index index++; } return flat_samples; } // Get the FlatField representing the temperature data in the cube public FlatField getData(){ return vals_ff; } } //end of Visad Tutorial Program Cube