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.
Hello,i am just start learning this powerful visualisation library and now some questions come up.
When i use Linear*DSet with arithmetic progression, i get different visualisation results when first/last arguments are quite high.
For example, if i use this domain_set = new Linear2DSet(domain_tuple, 0.0, NROWS, NROWS, 0, NCOLS, NCOLS); the plot looks fine. But when i use long xEnd=System.currentTimeMillis(); long xStart = xEnd-NCOLS; domain_set = new Linear2DSet(domain_tuple, 0.0, NROWS, NROWS, 0, NCOLS, NCOLS); (Look at the attachment for a full working example , line 112ff) The plot looks very strange. I expect that the plot is the same except the labels of the xAxis. Maybe someone can give me a hint? Or do i have to set the Axis values in an other way? Thanks, Stefan Below
/* VisAD Tutorial Copyright (C) 2000 Ugo Taddei */ package y; // 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 FlowTest{ // 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; // 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; private RealType pixelX; private RealType pixelY; private ScalarMap pixMapX; private ScalarMap pixMapY; public FlowTest(String []args) throws RemoteException, VisADException { // Create the quantities // Use RealType(String name); row = RealType.getRealType("ROW"); Unit scale = CommonUnit.secondsSinceTheEpoch.scale(0.001); column = RealType.getRealType("COLUMN",scale); domain_tuple = new RealTupleType(row, column); pixelX = RealType.getRealType("flowX"); pixelY = RealType.getRealType("flowY"); RealTupleType fuunc_Tuple = new RealTupleType(pixelX,pixelY); // Create a FunctionType (domain_tuple -> pixel ) // Use FunctionType(MathType domain, MathType range) func_dom_pix = new FunctionType( domain_tuple, fuunc_Tuple); // Create the domain Set, with 5 columns and 6 rows, using an // Integer2DSet(MathType type, int lengthX, lengthY) int NCOLS = 5; int NROWS = 6; // modify Axis scale // long t=System.currentTimeMillis(); long t=100000000; long xStart = t-NCOLS; // long xEnd = t; System.err.println(domain_tuple); // domain_set = new Linear2DSet(domain_tuple, 0.0, NROWS, NROWS, // 0, NCOLS, NCOLS); // domain_set = new Linear2DSet(domain_tuple, 0.0, NROWS, NROWS, xStart, xEnd, NCOLS); System.err.println(domain_set); // Our pixel values, given as a float[6][5] array float[][] pixel_vals1 = 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} }; float[][] pixel_vals2 = 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[2][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_vals1[r][c]; flat_samples[0][ c * NROWS + r ] = pixel_vals2[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 scales GraphicsModeControl 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 ); pixMapX = new ScalarMap( pixelX, Display.Flow1X ); pixMapY = new ScalarMap( pixelY, Display.Flow1Y ); // Add maps to display display.addMap( colMap ); display.addMap( rowMap ); display.addMap( pixMapX ); display.addMap( pixMapY ); FlowControl control = (FlowControl) pixMapX.getControl(); control.setArrowScale(0.1f); control.setFlowScale(0.3f); // 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 FlowTest(args); } } //end of Visad Tutorial Program 3_01
visad
archives: