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 bill, We are able to get the position of the mouse click using PointManipulationRendererJ3D. We want to display a tuple at the place of a mouse click and when we set the data to the reference of the PointManipulationRenderer the point is not displayed .But if added to a new reference the point is displayed only at the edges. Please, suggest us in achieving this. thanks karan Here is the code ====================================================== import visad.*; import visad.java2d.DisplayImplJ2D; import visad.java3d.*; import java.rmi.RemoteException; import javax.swing.*; import visad.java2d.*; import javax.media.j3d.*; import java.util.*; import java.awt.event.*; import visad.bom.PointManipulationRendererJ3D; public class DrawGeometry2 extends Object { RealType row, column, index; RealTupleType domain_tuple; DisplayImpl display; ScalarMap rowMap, colMap; DataReferenceImpl data_ref; DisplayRenderer dr; String ag[]; DataReferenceImpl d_ref; private static final int N = 64; float dx, dy; RealTuple rt; /** Creates new DrawGeometry2 */ public DrawGeometry2() { } public void displayGrid() throws RemoteException, VisADException { row = new RealType("X", SI.meter, null); column = new RealType("Y", SI.meter, null); domain_tuple = new RealTupleType(row, column); RealType index = new RealType("index"); FunctionType func_type = new FunctionType(domain_tuple, index); Integer2DSet integer_set = new Integer2DSet(domain_tuple, N, N); FlatField field = new FlatField(func_type, integer_set); display = new DisplayImplJ3D("display1"); dr = display.getDisplayRenderer(); dr.setBoxOn(false); GraphicsModeControl dispGMC (GraphicsModeControl) display.getGraphicsModeControl(); rowMap = new ScalarMap( row, Display.XAxis ); colMap = new ScalarMap( column, Display.YAxis ); display.addMap(colMap); display.addMap(rowMap); float[][] values = new float[1][N * N]; int k = 0; for (int i=0; i<N; i++) { for (int j=0; j<N; j++) { values[0][k++] = (i - N / 2) * (j - N / 2); } } ConstantMap[] colMap = { new ConstantMap( 0.0f, Display.Red ), new ConstantMap( 0.0f, Display.Green ), new ConstantMap( 0.0f, Display.Blue ) }; field.setSamples(values); DataReferenceImpl data_ref = new DataReferenceImpl("field"); data_ref.setData(field); display.addReference(data_ref, colMap); RealTuple dummy_rt = new RealTuple(domain_tuple, new double[] {Double.NaN, Double.NaN}); final DataReferenceImpl ref = new DataReferenceImpl("rt"); ref.setData(dummy_rt); final ConstantMap[] pointsCol = { new ConstantMap( 1.0f, Display.Red), new ConstantMap( 1.0f, Display.Green), new ConstantMap( 1.0f, Display.Blue), new ConstantMap( 10.0f, Display.PointSize)}; int m = (ag.length > 1) ? InputEvent.CTRL_MASK : 0; display.addReferences(new PointManipulationRendererJ3D(row, column, m, m), ref, pointsCol); CellImpl cell = new CellImpl() { public void doAction() throws VisADException, RemoteException { rt = (RealTuple) ref.getData(); dx = (float)((Real) rt.getComponent(0)).getValue(); dy = (float)((Real) rt.getComponent(1)).getValue(); if (dx == dx && dy == dy) { System.out.println("point (" + dx + ", " + dy + ")"); } } }; cell.addReference(ref); final DataReferenceImpl d_ref = new DataReferenceImpl("d_ref"); display.addDisplayListener(new DisplayListener() { public void displayChanged(DisplayEvent e) throws RemoteException, VisADException { if(e.getId() = DisplayEvent.MOUSE_RELEASED_RIGHT) { System.out.println("right pressed"); d_ref.setData(rt); display.addReference(d_ref); } } }); JFrame jframe = new JFrame("2D Grid"); jframe.getContentPane().add(display.getComponent()); jframe.setSize(400, 400); jframe.setVisible(true); jframe.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { System.exit(0); } } ); } public static void main(String args[]) { DrawGeometry2 g = new DrawGeometry2(); g.ag = args; try { g.displayGrid(); } catch (Exception e) { e.printStackTrace(); } } } -===================================================== __________________________________________________ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
visad
archives: