/* VisAD Tutorial Copyright (C) 2000-2001 Ugo Taddei */ package tutorial.s6; // Import needed classes import visad.*; import visad.java2d.DisplayImplJ2D; import visad.java2d.DirectManipulationRendererJ2D; import visad.java3d.*; import visad.util.*; import java.rmi.RemoteException; import java.awt.*; import javax.swing.*; import java.util.Vector; /** VisAD Tutorial example 6_06 Direct Manipulation Use Function.resample( line ) to sampe a field Show sampled line with another display Use a Cell to perform the necessary action Run program with java P6_06 * */ public class P6_06{ // Declare variables // The quantities to be displayed in x- and y-axes private RealType easting, northing, temperature; // lat and lon form a domain private RealTupleType domain; // A Tuple of Reals (a subclass of VisAD Data) // which will hold cursor data. private Real cursorCoords; // and this FlatField will hold the surface private FlatField surfsField; // The temperature line private FlatField temperLine; // The white line private Set whiteLine; // The DataReferences from the data to display private DataReferenceImpl cursorDataRef, surfDataRef; private DataReferenceImpl wLineDataRef, tLineDataRef; // The 2D display, and its the maps private DisplayImpl[] displays; private ScalarMap lonMap, latMap, rgbMap; public P6_06 (String[] args) throws RemoteException, VisADException { // Create the quantities easting = RealType.getRealType("easting", SI.meter, null); northing = RealType.getRealType("northing", SI.meter, null); temperature = RealType.getRealType("temperature", SI.kelvin, null); //...and the domain domain = new RealTupleType(easting, northing); // Create the Data: // The cursor double initLatitude = 0.50; cursorCoords = new Real(northing, initLatitude); // Create the DataReference cursorDataRef = new DataReferenceImpl("cursorDataRef"); // ...and initialize it with the RealTuple cursorDataRef.setData( cursorCoords ); // More Data: create a Surface object and get its data // ...which we know from section 3.5 that is a FlatField // with MathType ( (easting, northing) -> elevation ) Surface surf = new Surface(); surfsField = surf.getData(); surfDataRef = new DataReferenceImpl("surfDataRef"); surfDataRef.setData(surfsField); // Create the white line // with so many points int numberOfPoints = 100; whiteLine = (Set) makeLineSet(initLatitude, numberOfPoints); // Create the line's data ref and set data wLineDataRef = new DataReferenceImpl("wLineDataRef"); wLineDataRef.setData(whiteLine); // Create the temperature line to be shown on display temperLine = (FlatField) surfsField.resample( whiteLine); tLineDataRef = new DataReferenceImpl("tLineDataRef"); tLineDataRef.setData(temperLine); CellImpl cell = new CellImpl() { public void doAction() throws RemoteException, VisADException { // get the data object from the reference. We know it's a RealTuple Real lat = (Real) cursorDataRef.getData(); // test if cursor postion (northing) has changed significantly if( Util.isApproximatelyEqual( lat.getValue(), cursorCoords.getValue(), 0.2 ) ){ return; // leave method and thus don't update line } double latValue = lat.getValue(); // make a new line int nOfPoints = 2; whiteLine = (Set) makeLineSet(latValue, nOfPoints); // Re-set Data, will update display wLineDataRef.setData(whiteLine); // Re-create the temperature line temperLine = (FlatField) surfsField.resample( makeLineSet(latValue, 100) ); // and update ist data reference -> will update display tLineDataRef.setData(temperLine); // assign current cursor position to old cursor position cursorCoords = lat; } }; // link cursor with cell // so that doAction gets called whenever cursor moves cell.addReference(cursorDataRef); // Create the Displays and their maps // Two 2D displays displays = new DisplayImpl[2]; for( int i = 0; i<2;i++){ displays[i] = new DisplayImplJ2D("display" + i); } // Why not try with a 3D display for display 1? // uncomment the following line and add some more ScalarMaps below //displays[1] = new DisplayImplJ3D("display" + 1); // Get display's graphics mode control draw scales for( int i = 0; i<2;i++){ GraphicsModeControl dispGMC = (GraphicsModeControl) displays[i].getGraphicsModeControl(); dispGMC.setScaleEnable(true); } // Create the ScalarMaps lonMap = new ScalarMap( easting, Display.XAxis ); latMap = new ScalarMap( northing, Display.YAxis ); rgbMap = new ScalarMap( temperature, Display.RGB ); // Add maps to display displays[0].addMap( lonMap ); displays[0].addMap( latMap ); displays[0].addMap( rgbMap ); // Copy those maps and add to second display // could get all of display 1 maps with /*Vector mapsVec = displays[0].getMapVector(); for( int i = 0; i