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.
Hi,all I have been using visAD for about 3 days, and I feel it is a best visualization toolkit i have ever met. now I have a grid 2d data set, and the mathtype is (latitude, longitude)-> depth, finally I got the result like this:(see attachment) as u see, they are lots of points, so how i can form a surface of the terrain? another question is I want to isosurface, I add depthIsoMap = new ScalarMap( depth, Display.IsoContour ); display.addMap(depthMap); ContourControl isoControl = (ContourControl) depthIsoMap.getControl(); isoControl.setContourFill(true); isoControl.enableContours(true); but i got the following exception: java.lang.ArrayIndexOutOfBoundsException: -1 at visad.Contour2D.contour(Contour2D.java:355) at visad.Gridded3DSet.makeIsoLines(Gridded3DSet.java:2068) at visad.ShadowType.makeContour(ShadowType.java:3663) at visad.java3d.ShadowTypeJ3D.makeContour(ShadowTypeJ3D.java:466) at visad.ShadowFunctionOrSetType.doTransform(ShadowFunctionOrSetType.java:2110) at visad.java3d.ShadowFunctionOrSetTypeJ3D.doTransform(ShadowFunctionOrSetTypeJ3D.java:100) at visad.java3d.DefaultRendererJ3D.doTransform(DefaultRendererJ3D.java:99) at visad.java3d.RendererJ3D.doAction(RendererJ3D.java:181) at visad.DisplayImpl.doAction(DisplayImpl.java:1691) at visad.ActionImpl.run(ActionImpl.java:353) at visad.util.ThreadPool$ThreadMinnow.run(ThreadPool.java:95) the code are attached, thank you for your help in advance!! best wishes hao bo tang department of Computer Science university of Durham,uk
/* * Created on 2005-8-5 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ package test; import java.sql.Connection; import java.sql.*; /** * @author nakatayo * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class accessDB { private Connection con = null; private Statement s = null; private ResultSet rs = null; public accessDB(){ } public boolean openConnection() { boolean b = false; try { String userName = "root"; String password = "alex"; String url = "jdbc:mysql://127.0.0.1:3306/geo_data"; Class.forName("com.mysql.jdbc.Driver").newInstance(); con = DriverManager.getConnection(url,userName,password); System.out.println("Database connection established"); } catch( SQLException ex ) { // handle any errors System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); b = false; } catch (Exception e) { e.printStackTrace(); b = false; System.err.println("Cannot connect to database server"); } return b; } public double[] getLatitude() throws SQLException{ double latitude = 0.0; double[] latitude_Data = new double[407173]; try { ResultSet rs = null; int index = 0; if (s== null) s= con.createStatement(); String sql = "SELECT latitude FROM geo_data1"; s.executeQuery(sql); rs = s.getResultSet(); while (rs.next()) { latitude = rs.getDouble("latitude"); latitude_Data[index]= latitude; index++; } System.out.print(latitude_Data.length); } catch (Exception ex) { ex.printStackTrace(); System.err.println ("Error message: " + ex.getMessage ()); } return latitude_Data; } public double[] getlongitude() throws SQLException{ double longitude = 0.0; double[] longitude_Data = new double[407173]; ResultSet rs = null; try { int index = 0; if (s== null) s= con.createStatement(); String sql = "SELECT longitude FROM geo_data1"; s.executeQuery(sql); rs = s.getResultSet(); while (rs.next()) { longitude = rs.getDouble("longitude"); longitude_Data[index]= longitude; index++; } System.out.print(longitude_Data.length); } catch (Exception ex) { ex.printStackTrace(); System.err.println ("Error message: " + ex.getMessage ()); } return longitude_Data; } public double[] getdepth() throws SQLException{ double depth = 0.0; double[] depth_Data = new double[407173]; ResultSet rs = null; try { int index = 0; if (s== null) s= con.createStatement(); String sql = "SELECT depth FROM geo_data1"; s.executeQuery(sql); rs = s.getResultSet(); while (rs.next()) { depth = rs.getDouble("depth"); depth_Data[index]= depth; index++; } System.out.print(depth_Data.length); } catch (Exception ex) { ex.printStackTrace(); System.err.println ("Error message: " + ex.getMessage ()); } return depth_Data; } public void closeDB() throws SQLException { s.close(); con.close(); } public static void main(String[] args) { } }
package test; /* VisAD Tutorial Copyright (C) 2000 Ugo Taddei */ // Import needed classes import visad.*; import visad.java2d.DisplayImplJ2D; import java.rmi.RemoteException; import java.sql.SQLException; import java.awt.*; import javax.swing.*; import java.awt.event.*; import visad.java3d.DisplayImplJ3D; import visad.util.ContourWidget; /* Note: - alternative use of a Linear2DSet - common heightNaN values "interpolates" domain set -> weird! - call GraphicsModeControl.setPolygonMode(1); to draw mesh */ public class DGM1{ // Declare variables // The domain quantities longitude and latitude // and the dependent quantities altitude, temperature private RealType latitude,longitude; private RealType depth; // Two Tuples: one to pack longitude and latitude together, as the domain // and the other for the range (altitude, temperature) private RealTupleType domain_tuple; // The function (domain_tuple -> range_tuple ) private FunctionType func_en_h; // 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 latMap, lonMap, depthMap,depthIsoMap; private ContourWidget contourWid; public DGM1(String []args) throws RemoteException, VisADException, SQLException { accessDB db = new accessDB(); db.openConnection(); double[] latNaN = db.getLatitude(); double[] lonNaN = db.getlongitude(); double[] depthNaN = db.getdepth(); db.closeDB(); //System.out.println(latNaN.length); //System.out.println(lonNaN.length); //System.out.println(depthNaN.length); //for (int i=0; i<latNaN.length;i++){ // System.out.println(latNaN[i]); //} //for (int i=0; i<latNaN.length;i++){ //System.out.println(lonNaN[i]); //} int nCols = latNaN.length; int nRows = 1; double[][] coords = new double[2][latNaN.length]; for (int i=0;i<(nCols*nRows);i++) { coords[0][i]=latNaN[i]; coords[1][i]=lonNaN[i]; } // Create the quantities // Use RealType(String name); latitude = new RealType("latitude",SI.meter,null); longitude = new RealType("longitude",SI.meter,null); domain_tuple = new RealTupleType(latitude,longitude); depth = new RealType("depth",SI.meter,null); // Create a FunctionType (domain_tuple -> range_tuple ) // Use FunctionType(MathType domain, MathType range) func_en_h = new FunctionType(domain_tuple, depth); // UT domain_set = new Gridded2DDoubleSet(domain_tuple,coords,nRows,nCols); //domain_set = new Linear2DSet(domain_tuple,1,5,5,1,9,9); // Get the Set samples to facilitate the calculations float[][] set_samples = domain_set.getSamples( true ); // We create another array, with the same number of elements of // altitude and temperature, but organized as double[][] flat_samples = new double[1][nCols*nRows]; // ...and then we fill our 'flat' array with the generated values // by looping over NCOLS and NROWS // specifiy height for(int c = 0; c < nCols; c++) for(int r = 0; r < nRows; r++) flat_samples[0][ c * nRows + r ] = depthNaN[c*nRows+r];; //flat_samples[0][ c * nRows + r ]= c*nRows+r; /* int index = 0; for(int c = 0; c < 2; c++) for(int r = 0; r < nRows*nCols; r++){ // set altitude flat_samples[0][ index ] = set_samples[c][r]; // increment index index++; } */ /* for(int c = 0; c < nCols; c++){ for(int r = 0; r < nCols; r++){ // UT flat_samples[0][c*nRows+r] = c*nRows+r; //flat_samples[0][c*nRows+r] = heightNaN[c*nRows+r]; //System.out.println("height "+heightNaN[c*nRows+r]); //System.out.println("height " + flat_samples[c*nRows+r]); } } */ /* for(int c = 0; c < NCOLS; c++) for(int r = 0; r < NROWS; r++){ flat_samples[0][c*NROWS+r] = heightNaN[c*NROWS+r]; //System.out.println("height "+height[c*NROWS+r]); } */ // Get the funtionc from the FlatField for slope // Create a FlatField // Use FlatField(FunctionType type, Set domain_set) vals_ff = new FlatField( func_en_h, 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 ); // Create a ScalarMap to color slope's surface // Create Display and its maps // A 2D display display = new DisplayImplJ3D("display1"); // Create the ScalarMaps: latitude to XAxis, longitude to YAxis and // altitude to RGB and temperature to IsoContour // Use ScalarMap(ScalarType scalar, DisplayRealType display_scalar) latMap = new ScalarMap( latitude, Display.YAxis ); lonMap = new ScalarMap( longitude, Display.XAxis ); depthMap = new ScalarMap(depth,Display.ZAxis); depthIsoMap = new ScalarMap( depth, Display.IsoContour ); // Add maps to display display.addMap( latMap ); display.addMap( lonMap ); display.addMap(depthMap); // UT //display.addMap( heightMap ); // UT display.addMap( new ScalarMap(depth,Display.RGB) ); display.addMap(depthIsoMap); latMap.setRange(63.5, 63.9333); lonMap.setRange(-28.2333,-27.5833); depthMap.setRange(-5000.0,0); //latMap.setRange(60,70); //lonMap.setRange(27,29); //depthMap.setRange(0,5000); //heightMap.setRange(200,300); //heightMap.setRange(-1.0,1.0); // Create a data reference and set the FlatField as our data data_ref = new DataReferenceImpl("data_ref"); data_ref.setData( vals_ff ); display.addReference(data_ref); //ContourControl isoControl = (ContourControl) depthIsoMap.getControl(); // isoControl.setContourInterval(interval, lowValue, highValue, base); //isoControl.setContourFill(true); //isoControl.enableContours(true); // UT GraphicsModeControl dispGMC = (GraphicsModeControl) display.getGraphicsModeControl(); dispGMC.setScaleEnable(true); dispGMC.setTextureEnable(true); dispGMC.setPointMode(true); dispGMC.setPointSize(1.0f); //dispGMC.setPolygonMode(1); // Create application window and add display to window JFrame jframe = new JFrame("First Release"); 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, SQLException { new DGM1(args); } } //end of Visad Tutorial Program 3_09
visad
archives: