Gridded2DSet problem


 Oops...forgot to add the code.

=====================================================


import visad.*;
import visad.java2d.DisplayImplJ2D;
import visad.java3d.*;
import java.rmi.RemoteException;
import javax.swing.*;
import java.io.*;
import visad.java2d.*;
import javax.media.j3d.*;

public class MouseCreateGeometry3 extends Object {
    RealType row, column, index;
    RealTupleType domain_tuple;
    Gridded2DSet grid2d;
    GridCoordinateSystem grid_coord;
    FlatField vals_ff;
    DisplayImplJ2D display;
    ScalarMap rowMap, colMap, indexMap;
    DataReferenceImpl data_ref;
    DisplayRenderer dr;
    Gridded2DSet gf1;
    Gridded2DSet gf2;
    int nverts;
    DataReference data_ref1;
    UnionSet us;
    RealTuple rt1[];
    float frt1, frt2, frtt1, frtt2;
    Data[] drt1, drt2;
    RealTuple rt;
       
    float line1[][] = new float[2][2];
    float line2[][] = new float[2][2];


    /** Creates new MouseCreateGeometry3 */
    public MouseCreateGeometry3() {
    }
    
     public void displayGrid() throws RemoteException,
VisADException {
        row = new RealType("X", null, null);    
        column = new RealType("Y", null, null);
        FunctionType ftype = new FunctionType(row,
column);
        
        domain_tuple = new RealTupleType(row, column);
        
        int size = 64;
        FlatField flatfield
FlatField.makeField(ftype, size, false);
              
        
        display = new DisplayImplJ2D("display1");
        dr = display.getDisplayRenderer();
        dr.setBoxOn(false);
        
        display.addMap(new ScalarMap(row,
Display.XAxis));
        display.addMap(new ScalarMap(column,
Display.YAxis));
        
        GraphicsModeControl dispGMC
(GraphicsModeControl)
display.getGraphicsModeControl();
                
        float flat_samples[][] = new float[][] {{0, 1,
1, 0, 0 },
                                                {0, 0,
1, 1, 0 }};
            
   
        DataReferenceImpl dt = new
DataReferenceImpl("d_ref");
        
            
        final Gridded2DSet[] g = new Gridded2DSet[4];
        
        final DataReferenceImpl dr[] = new
DataReferenceImpl[4];
        rt1 = new RealTuple[4];
        
        ConstantMap[] pointsCol = {     new
ConstantMap( 1.0f, Display.Red),
                                     new ConstantMap( 0.0f, Display.Green),
                                     new ConstantMap( 0.0f, Display.Blue), 
                                     new ConstantMap( 5.0f,
Display.PointSize)};
        
         
        float f1[][] = new float[2][2];
        nverts = 4;
       
        data_ref1 = new DataReferenceImpl("data");
        
        for(int i = 0; i < 4; i++) {
            f1[0][0] = flat_samples[0][i];
            f1[1][0] = flat_samples[1][i];
            f1[0][1] = flat_samples[0][i+1];
            f1[1][1] = flat_samples[1][i+1];
            
            g[i] = new Gridded2DSet(domain_tuple, f1,
2);
          
            Real r1[] = new Real[] { new Real(row,
flat_samples[0][i]), new Real(column,
flat_samples[1][i]) };
            rt1[i] = new RealTuple(r1);
            dr[i] = new
DataReferenceImpl("ref_direct");
            dr[i].setData(rt1[i]);
            final int n = i;  
             
            display.addReferences( new
DirectManipulationRendererJ2D(), dr[i], pointsCol);
            
            
            CellImpl cell = new CellImpl() {
                private boolean first = true;
                
                public void doAction() throws
VisADException, RemoteException {
                    if (first) first = false;
                    else {
                    
                    rt = (RealTuple) dr[n].getData(); 
                    Data[] d = rt.getComponents();
             
                    if(n == 0) {
                        gf1 = g[n];
                        gf2 = g[nverts-1];
                        drt1 = rt1[1].getComponents();
                        frt1 = (new
Double(drt1[0].toString())).floatValue();
                        frt2 = (new
Double(drt1[1].toString())).floatValue(); 
                        
                        drt2
rt1[nverts-1].getComponents();
                        frtt1 = (new
Double(drt2[0].toString())).floatValue();
                        frtt2 = (new
Double(drt2[1].toString())).floatValue(); 
                        
                   } else if(n == (nverts-1)) {
                        drt1 = rt1[0].getComponents();
                        frt1 = (new
Double(drt1[0].toString())).floatValue();
                        frt2 = (new
Double(drt1[1].toString())).floatValue(); 
                        
                        drt2
rt1[(nverts-1)-1].getComponents();
                        frtt1 = (new
Double(drt2[0].toString())).floatValue();
                        frtt2 = (new
Double(drt2[1].toString())).floatValue(); 
                        
                    } else {
                        gf1 = g[n];
                        gf2 = g[n-1];
                        drt1
rt1[n+1].getComponents();
                        frt1 = (new
Double(drt1[0].toString())).floatValue();
                        frt2 = (new
Double(drt1[1].toString())).floatValue(); 
                        
                        drt2
rt1[n-1].getComponents();
                        frtt1 = (new
Double(drt2[0].toString())).floatValue();
                        frtt2 = (new
Double(drt2[1].toString())).floatValue(); 
                    }
                                   
                             
                    float pt1[] = new float[2];
                    float pt2[] = new float[2];
                    
                    pt1[0] = frt1;
                    pt1[1] = frt2;
                    
                    pt2[0] = frtt1;
                    pt2[1] = frtt2;
            
                    line1[0][0] = pt1[0];
                    line1[0][1] = (new
Double(d[0].toString())).floatValue();
                   
                    line1[1][0] = pt1[1];
                    line1[1][1] = (new
Double(d[1].toString())).floatValue();
                    
                    line2[0][0] = pt2[0];
                    line2[0][1] = (new
Double(d[0].toString())).floatValue();
                    line2[1][0] = pt2[1];
                    line2[1][1] = (new
Double(d[1].toString())).floatValue();
                    
         //           System.out.println("ln1 : " +
"x1: " + line1[0][0] + " x2:  " +line1[0][1] + "   y1:
" + line1[1][0]+ " y2: " + line1[1][1] );
         //           System.out.println("ln2 : " +
"x1: " +line2[0][0] + " x2: " +line2[0][1] + "   y1: "
+ line2[1][0]+ " y2: " + line2[1][1] );
                    
                    
                    gf1 = new
Gridded2DSet(domain_tuple, line1, 2);
                    gf2 = new
Gridded2DSet(domain_tuple, line2, 2);
                    
                    Gridded2DSet[] gsd = { gf1, gf2 };
                    us = new UnionSet(domain_tuple,
gsd);
                    
                    data_ref1.setData(us);
                   
                 }
            }
        };
        
        cell.addReference(dr[i]);
        
        }
        
        UnionSet u_set = new UnionSet(g);
        dt.setData(u_set);
        display.addReference( dt);
        
        display.addReference(data_ref1);
        
        JFrame jframe = new JFrame("2D Grid");
       
jframe.getContentPane().add(display.getComponent());
        
        jframe.setSize(300, 300);
        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) {
        MouseCreateGeometry3 g = new
MouseCreateGeometry3();
        try {
            g.displayGrid();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}


======================================================

thanks 
karan

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/


  • 2001 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: