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.

Re: Gridded2DSet, Irregular2DSet ?

Hi.

Sorry here is the code I mentioned :-)

Corne Kloppers

//Wed Feb 28 13:42:05 SAST 2001
import visad.*;
import visad.java2d.DisplayImplJ2D;
import java.rmi.RemoteException;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class UserMeshDisplay{

    private TextType text; 
    private TupleType text_tuple; 
    private FlatField nodeFlatField;
    private RealTupleType time_type; 
    private FunctionType text_function;
    private RealTupleType domain_tuple; 
    private RealType pixel;
    private RealType index; 
    private FunctionType func_dom_node_pix; 
    private Irregular2DSet nodeSet;
    private Gridded2DSet nodeOutlineSet;
    private int nodeCornersLength = 0;
    private Integer1DSet indexSet; 
    private FunctionType index_flatfield;
    private FieldImpl fieldImpl; 
    private Set time_set; 
    private FieldImpl text_field;
    private Tuple tt;
    private DisplayImplJ2D display;
    private GraphicsModeControl dispGMC;
    private ScalarMap colMap;
    private ScalarMap rowMap;
    private ScalarMap pixMap;
    private ScalarMap text_map; 
    private TextControl tcontrol;
    private DataReferenceImpl dataReference;
    private DataReferenceImpl ref_text_field1; 
    private JFrame jframe;

    public UserMeshDisplay(String args[]) throws RemoteException, 
VisADException {

       // constructs for the labels
       text = new TextType("text");
       RealType[] time = {RealType.Time};
       time_type = new RealTupleType(time);
       MathType[] mtypes = {RealType.YAxis, RealType.XAxis, text};
       text_tuple = new TupleType(mtypes);
       text_function = new FunctionType(RealType.Time, text_tuple);
   
       domain_tuple = new RealTupleType(RealType.XAxis, RealType.YAxis);
       pixel = new RealType("pixel");
       index = new RealType("index");
    
       func_dom_node_pix = new FunctionType( domain_tuple, pixel);

       float[][] nodeFlatSamplesArray = {{2f,2f,2f,2f,2f,2f,2f}};
       float[][] nodeOutlineFlatSamplesArray = {{8f,8f,8f,8f,8f,8f,8f}};

       indexSet = new Integer1DSet(index, 2);
       index_flatfield = new FunctionType( index, func_dom_node_pix);
       fieldImpl = new FieldImpl(index_flatfield, indexSet);

       // Labels time_set
       //time_set = new Linear1DSet(time_type, 0.0, (double) (1 - 1.0), 1);
       time_set = new Linear1DSet(time_type, 0.0, 0.0, 1);

       text_field = new FieldImpl(text_function, time_set);

       float[][] aNode = {{15f,18f,20f,19f,18f,17f,15f},
                          {8f,10f,8f,5f,1f,5f,8f}};

       nodeSet = new Irregular2DSet(domain_tuple, aNode);

       //Create a Gridded2DSet for the outline
       nodeOutlineSet = new Gridded2DSet(domain_tuple, aNode, 7);

       //Create a FlatField from the irregular set for the colour within.
       nodeFlatField = new FlatField(func_dom_node_pix, nodeSet);
       nodeFlatField.setSamples(nodeFlatSamplesArray);

       fieldImpl.setSample(0, nodeFlatField);

       //Create and add the outline
       nodeFlatField = new FlatField(func_dom_node_pix, nodeOutlineSet);
       nodeFlatField.setSamples(nodeOutlineFlatSamplesArray);
       fieldImpl.setSample(1, nodeFlatField);
            
       // Put in the Label: call function
       tt = put_lable(aNode, 6, "test");
       text_field.setSample(0, tt);

       display = new DisplayImplJ2D("display1");
    
       // Get display's graphics mode control and draw scales
       dispGMC = (GraphicsModeControl) display.getGraphicsModeControl();
       dispGMC.setScaleEnable(true);    
    
       // Create the ScalarMaps: column to XAxis, row to YAxis and pixel to RGB
       colMap = new ScalarMap( RealType.XAxis, Display.XAxis );
       rowMap = new ScalarMap( RealType.YAxis, Display.YAxis );
       pixMap = new ScalarMap( pixel,  Display.RGB );
       text_map = new ScalarMap(text, Display.Text);

       // Add maps to display
       display.addMap( colMap );
       display.addMap( rowMap );
       display.addMap( pixMap );
       display.addMap(text_map);

       //Fonts
       tcontrol = (TextControl) text_map.getControl();
       tcontrol.setCenter(true);
       tcontrol.setSize(0.6);
       //Font font = new Font("Dialog", Font.BOLD, 16);
       //tcontrol.setFont(font);
    
       dataReference = new DataReferenceImpl("data_ref");
       dataReference.setData(fieldImpl.getSample(0));
       display.addReference(dataReference);

       dataReference = new DataReferenceImpl("data_ref");
       dataReference.setData(fieldImpl.getSample(1));
       display.addReference(dataReference);

       ref_text_field1 = new DataReferenceImpl("ref_text_field");
       ref_text_field1.setData(text_field.getSample(0));
       display.addReference( ref_text_field1 );

       // Create application window and add display to window
       jframe = new JFrame("VSOP AjayGridColorJobbie");
       jframe.addWindowListener(new WindowAdapter() {
       public void windowClosing(WindowEvent e) {System.exit(0);} });
       jframe.getContentPane().add(display.getComponent());
    
       // Set window size and make it visible
       jframe.setSize(300, 300);
       jframe.setVisible(true);
    }

  /** 
   * Calculate the centriode off the points region,
   * put the name string in the middle.
   */
  public Tuple put_lable(float[][] points, int size, String name) 
    throws RemoteException, VisADException
  {

  float x_sum = 0;
  float y_sum = 0;

  for (int i=0; i < size-1; i++)
  {
        x_sum += points[0][i];
        y_sum += points[1][i];
  }

  float x_val = x_sum / (size-1); 
  float y_val = y_sum / (size-1);

  //Debug code
  System.out.print("y_val = "+y_val+"\t");
  System.out.println("x_val = "+x_val);

  // create Data
  Data[] td = {
                  new Real(RealType.YAxis, y_val),
                  new Real(RealType.XAxis, x_val),
                  new Text(text, name)
              };
  //set sample to the text_field
  Tuple tt = new Tuple(text_tuple, td);
  return tt;
  }

  public static void main(String[] args)
    throws RemoteException, VisADException
  {
    new UserMeshDisplay(args);
  }

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