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.
Howdy, Folks:I changed program P3_01 a little bit, the domain_set is a irregular 2d set. I want to use this changed program to visualize the pixel_value in the given domain, which is a annular area with inner radius of 1 and outer radius of 6. I wonder why the area with radius<1 is also painted. If you could please run it and you will see it. I will appreciate it if you could keep me informed why? Thanks so much.
Yi /* VisAD Tutorial Copyright (C) 2000 Ugo Taddei */ // Import needed classes import visad.*; import visad.java2d.DisplayImplJ2D; import java.rmi.RemoteException; import javax.swing.*; /** VisAD Tutorial example 3_01 A function pixel_value = f(row, column) with MathType ( (row, column) -> pixel ) is plotted The domain set is an Integer1DSet Run program with "java P3_01" */ public class P3_01{ // Declare variables // The quantities to be displayed in x- and y-axes: row and column // The quantity pixel will be mapped to RGB color private RealType row, column, pixel; // A Tuple, to pack row and column together, as the domain private RealTupleType domain_tuple; // The function ( (row, column) -> pixel ) // That is, (domain_tuple -> pixel ) private FunctionType func_dom_pix; // Our Data values for the domain are represented by the Set private Set domain_set; // The Data class FlatField private FlatField vals_ff; // The DataReference from data to display private DataReferenceImpl data_ref; // The 2D display, and its the maps private DisplayImpl display; private ScalarMap rowMap, colMap, pixMap; public P3_01(String []args) throws RemoteException, VisADException { // Create the quantities // Use RealType(String name); row = new RealType("ROW"); column = new RealType("COLUMN"); domain_tuple = new RealTupleType(row, column); pixel = new RealType("PIXEL"); // Create a FunctionType (domain_tuple -> pixel ) // Use FunctionType(MathType domain, MathType range) func_dom_pix = new FunctionType( domain_tuple, pixel); // Create the domain Set, with 5 columns and 6 rows, using an // Integer2DSet(MathType type, int lengthX, lengthY) int NCOLS = 5; int NROWS = 6; float[][] sd=new float[][]{ { 1f,2f,3f,4f,5f,6.0f, 0.92f,1.84f,2.76f,3.68f,4.6f,5.52f, 0.71f,1.42f,2.13f,2.84f,3.55f,4.26f, 0.38f,0.76f,1.14f,1.52f,1.9f,2.3f, 0f,0f,0f,0f,0f,0f }, { 0f,0f,0f,0f,0f,0f, 0.38f,0.76f,1.14f,1.52f,1.9f,2.3f, 0.71f,1.42f,2.13f,2.84f,3.55f,4.26f, 0.92f,1.84f,2.76f,3.68f,4.6f,5.52f, 1f,2f,3f,4f,5f,6.0f, }, }; Set domain_set=new Irregular2DSet(domain_tuple,sd); for(int i=0;i<30;i++){ System.out.print(sd[0][i]+"\t"); } // Our pixel values, given as a float[6][5] array float[][] pixel_vals = new float[][]{{0, 6, 12, 18, 24}, {1, 7, 12, 19, 25}, {2, 8, 14, 20, 26}, {3, 9, 15, 21, 27}, {4, 10, 16, 22, 28}, {5, 11, 17, 23, 29} }; // We create another array, with the same number of elements of // pixel_vals[][], but organized as float[1][ number_of_samples ] float[][] flat_samples = new float[1][NCOLS * NROWS]; // ...and then we fill our 'flat' array with the original values // Note that the pixel values indicate the order in which these values // are stored in flat_samples for(int c = 0; c < NCOLS; c++) for(int r = 0; r < NROWS; r++) flat_samples[0][ c * NROWS + r ] = pixel_vals[r][c]; // Create a FlatField // Use FlatField(FunctionType type, Set domain_set) vals_ff = new FlatField( func_dom_pix, domain_set); // ...and put the pixel values above into it vals_ff.setSamples( flat_samples ); // Create Display and its maps // A 2D display display = new DisplayImplJ2D("display1"); // Get display's graphics mode control and draw scalesGraphicsModeControl dispGMC = (GraphicsModeControl) display.getGraphicsModeControl();
dispGMC.setScaleEnable(true); // Create the ScalarMaps: column to XAxis, row to YAxis and pixel to RGB // Use ScalarMap(ScalarType scalar, DisplayRealType display_scalar) colMap = new ScalarMap( column, Display.XAxis ); rowMap = new ScalarMap( row, Display.YAxis ); pixMap = new ScalarMap( pixel, Display.RGB ); // Add maps to display display.addMap( colMap ); display.addMap( rowMap ); display.addMap( pixMap ); // Create a data reference and set the FlatField as our data data_ref = new DataReferenceImpl("data_ref"); data_ref.setData( vals_ff ); // Add reference to display display.addReference( data_ref ); // Create application window and add display to window JFrame jframe = new JFrame("VisAD Tutorial example 3_01"); jframe.getContentPane().add(display.getComponent()); // Set window size and make it visible jframe.setSize(300, 300); jframe.setVisible(true); } public static void main(String[] args) throws RemoteException, VisADException { new P3_01(args); } } //end of Visad Tutorial Program 3_01 _________________________________________________________________ Chat with friends online, try MSN Messenger: http://messenger.msn.com
visad
archives: