Labelling problem

Hi Bill,

Thanks a lot Bill for your kind suggestions.

According to your mail yesterday we tried to work on
labelling the real tuples with the vertex numbers(1,
2,... etc). We tried to do for one tuple according to
the "Delaunay.java" and we found that only the label
is visible and no real tuple. We want both of them to
be visible and the vertex labelling to be displayed
bit far away from the tuple. we worked on it and it is
shown in our code commented. un-commenting the
setdata() method, we cannot see even the tuples also
and it gives exception. Please help us in this matter.

Thanks a lot again,

karan.

Here is the code:
======================================================
/*
 * MouseCreateGeometry4.java
 *
 * Created on July 16, 2001, 2:53 PM
 */


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 MouseCreateGeometry4 extends Object {
    RealType row, column;
    RealTupleType domain_tuple;
    DisplayImplJ2D display;
    ScalarMap rowMap, colMap, indexMap;
    DisplayRenderer dRenderer;
    DataReference data_ref1;
    FieldImpl field;
    float dx1, dx2, dy1, dy2;
    float samp[][];
    int nverts;
    int size = 64;
    
    Gridded2DSet[] g = new Gridded2DSet[4];
    
    DataReferenceImpl dr[] = new DataReferenceImpl[4];
    RealTuple rt1[] = new RealTuple[4];
    
    float flat_samples[][] = new float[][] {{0, 1, 1,
0, 0 },
    {0, 0, 1, 1, 0 }};
    
    float f1[][] = new float[2][2];
    
    /** Creates new MouseCreateGeometry4 */
    public MouseCreateGeometry4() {
    }
    
    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);
        
        FlatField flatfield
FlatField.makeField(ftype, size, false);
        
        display = new DisplayImplJ2D("display1");
        
        //setBackground and cursor colors.
        dRenderer = display.getDisplayRenderer();
        dRenderer.setBoxOn(false);
        dRenderer.setBackgroundColor(1.0f, 1.0f,
1.0f);
        dRenderer.setCursorColor( 0.0f, 0.0f, 1.0f );
        
        //add maps to display.
        display.addMap(new ScalarMap(row,
Display.XAxis));
        display.addMap(new ScalarMap(column,
Display.YAxis));
        
        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)};
        
        ConstantMap[] linesCol = {      new
ConstantMap( 0.0f, Display.Red),
        new ConstantMap( 0.0f, Display.Green),
        new ConstantMap( 1.0f, Display.Blue)};
        
        
        //data reference for adding union sets.
        data_ref1 = new DataReferenceImpl("data");
        
        //for labelling the vertices
        TextType text = new TextType("text");
        RealType t = new RealType("t");
        RealTupleType rtt = new RealTupleType(new
RealType[] {t});
        Linear1DSet time_set = new Linear1DSet(rtt, 0,
10, 10);
        TupleType text_tuple = new TupleType(new
MathType[] {row, column, text});
        FunctionType text_function = new
FunctionType(t, text_tuple);
        FieldImpl text_field = new
FieldImpl(text_function, time_set);
        display.addMap(new ScalarMap(text,
Display.Text));
        
        nverts = 4;
        //loop which goes to nverts and caluculates
the gidded sets and forms the real tuples.
        for(int i = 0; i < nverts; i++) {
            //constructing gridded sets.
            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);
            
            //constructing real tuples.
            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]);
            
            //naming the verices.
            Data[] td = {   new Real(row,
flat_samples[0][i]),
                            new Real(column,
flat_samples[1][i]),
                            new Text(text, "" + i)};
            TupleIface tt = new Tuple(text_tuple, td);
            
            text_field.setSample(i, tt);
            
          //    dr[i].setData(text_field);
            
            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 {
                        //reconstructing the gridded
sets.
                        for(int i = 0; i < nverts;
i++) {
                            if(i == (nverts-1)) {
                                dx1
(float)((Real)((RealTuple)
dr[(nverts-1)].getData()).getComponent(0)).getValue();
                                dy1
(float)((Real)((RealTuple)
dr[(nverts-1)].getData()).getComponent(1)).getValue();
                                
                                dx2
(float)((Real)((RealTuple)
dr[0].getData()).getComponent(0)).getValue();
                                dy2
(float)((Real)((RealTuple)
dr[0].getData()).getComponent(1)).getValue();
                                
                                samp = new float[][]  
 {{dx1, dx2},
                                {dy1, dy2}};
                                
                                g[(nverts-1)] = new
Gridded2DSet(domain_tuple, samp, 2);
                                
                            } else {
                                dx1
(float)((Real)((RealTuple)
dr[i].getData()).getComponent(0)).getValue();
                                dy1
(float)((Real)((RealTuple)
dr[i].getData()).getComponent(1)).getValue();
                                
                                dx2
(float)((Real)((RealTuple)
dr[i+1].getData()).getComponent(0)).getValue();
                                dy2
(float)((Real)((RealTuple)
dr[i+1].getData()).getComponent(1)).getValue();
                                
                                samp = new float[][]
{{dx1, dx2},
                                {dy1, dy2}};
                                
                                g[i] = new
Gridded2DSet(domain_tuple, samp, 2);
                                
                            }
                        }
                        UnionSet u_set = new
UnionSet(g);
                        data_ref1.setData(u_set);
                    }
                }
            };
            cell.addReference(dr[i]);
        }
        
        UnionSet u_set = new UnionSet(g);
        data_ref1.setData(u_set);
        display.addReference(data_ref1,linesCol);
        
        JFrame jframe = new JFrame("Draggable Vertices
Made Easy");
       
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) {
        MouseCreateGeometry4 g = new
MouseCreateGeometry4();
        try {
            g.displayGrid();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
}








__________________________________________________
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: