/* VisAD Tutorial Copyright (C) 2000 Ugo Taddei */ package tutorial.s6; // Import needed classes import visad.*; import visad.java2d.DisplayImplJ2D; import java.rmi.RemoteException; import java.awt.*; import javax.swing.*; import java.awt.event.*; /** Originally Surface changed for Sec 6: method getData returns FlatField VisAD Tutorial example 3_05 We have the function temperature = f(northing, easting) represented by the MathType ( (easting, northing) -> elevation ) Map the elevation and temperature to IsoContour (and to RGB) Run program with "java Surface" */ public class Surface{ // Declare variables // The domain quantities easting and northing // and the dependent quantity temperature private RealType easting, northing; private RealType temperature; // Tuple to pack easting and northing together, as the domain private RealTupleType domain_tuple; // The function (domain_tuple -> temperature ) // Remeber, range is only "temperature" private FunctionType func_domain_range; // Our Data values for the domain are represented by the Set private Set domain_set; // The Data class FlatField private FlatField vals_ff; public Surface() throws RemoteException, VisADException { // Create the quantities // Use RealType(String name); northing = RealType.getRealTypeByName("northing"); easting = RealType.getRealTypeByName("easting"); domain_tuple = new RealTupleType(easting, northing); temperature = RealType.getRealTypeByName("temperature"); // Create a FunctionType (domain_tuple -> range_tuple ) // Use FunctionType(MathType domain, MathType range) func_domain_range = new FunctionType( domain_tuple, temperature); // Create the domain Set // Use LinearDSet(MathType type, double first1, double last1, int lengthX, // double first2, double last2, int lengthY) int NCOLS = 50; int NROWS = NCOLS; domain_set = new Linear2DSet(domain_tuple, -Math.PI, Math.PI, NROWS, -Math.PI, Math.PI, NCOLS); // Get the Set samples to facilitate the calculations float[][] set_samples = domain_set.getSamples( true ); // The actual temperature values are stored in this array // float[1][ number_of_samples ] float[][] flat_samples = new float[1][NCOLS * NROWS]; // We fill our 'flat' array with the generated values // by looping over NCOLS and NROWS for(int c = 0; c < NCOLS; c++) for(int r = 0; r < NROWS; r++){ // ...temperature flat_samples[0][ c * NROWS + r ] = (float)( (Math.sin( 0.50*(double) set_samples[0][ c * NROWS + r ]) ) * Math.cos( (double) set_samples[1][ c * NROWS + r ] ) ) ; } // Create a FlatField // Use FlatField(FunctionType type, Set domain_set) vals_ff = new FlatField( func_domain_range, domain_set); // ...and put the values above into it // Note the argument false, meaning that the array won't be copied vals_ff.setSamples( flat_samples , false ); } // Get the FlatField representing the temperature data public FlatField getData(){ return vals_ff; } } //end of Visad Tutorial Program 3_05