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

Here is a small example that I used when training in Australia which
illustrates what Bill wrote.  Hope you find it helpful...

tom



// import needed classes
import visad.*;
import visad.java2d.DisplayImplJ2D;
import visad.java2d.DirectManipulationRendererJ2D;
import java.rmi.RemoteException;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ShapeTest {

  // type 'java ShapeTest' to run this application
  public static void main(String args[])
         throws VisADException, RemoteException {

    final RealType x = new RealType("x");
    final RealType y = new RealType("y");
    final RealType shape = new RealType("shape");

    DisplayImpl disp = new DisplayImplJ2D("display");

    ScalarMap sx = new ScalarMap(x, Display.XAxis);
    sx.setRange(-1.0, 1.0);
    disp.addMap(sx);

    ScalarMap sy = new ScalarMap(y, Display.YAxis);
    sy.setRange(-1.0, 1.0);
    disp.addMap(sy);

    ScalarMap shape_map = new ScalarMap(shape, Display.Shape);
    disp.addMap(shape_map);

    final RealTupleType coord_type = new RealTupleType(x, y, shape);
    RealTuple coord_tuple = 
             new RealTuple(coord_type, new double[] {0.7, -0.3, 0});
    RealTuple coord_tuple2 = 
             new RealTuple(coord_type, new double[] {-0.7, 0.3, 1});

    // make some shapes..
    VisADLineArray cross = new VisADLineArray();
    cross.coordinates = new float[]
      {0.2f,  0.2f, 0.0f,    -0.2f, -0.2f, 0.0f,
       0.2f, -0.2f, 0.0f,    -0.2f,  0.2f, 0.0f};
    cross.vertexCount = cross.coordinates.length / 3;

    double[] start = {0.0, 0.0, 0.0}; // text at origin
    double[] base = {0.1, 0.0, 0.0};  // text out along XAxis
    double[] up = {0.0, 0.1, 0.0};    // character up along YAxis
    boolean center = true;            // center text

    VisADLineArray tom = PlotText.render_label("Tom", start, base, up, center);

    VisADGeometryArray[] shapes = new VisADGeometryArray[] {cross, tom};

    ShapeControl shape_control = (ShapeControl) shape_map.getControl();
    shape_control.setShapeSet(new Integer1DSet(2));
    shape_control.setShapes(shapes);

    // now attach to the display

    DataReferenceImpl ref_coord_tuple = new DataReferenceImpl("ref_c_t");
    ref_coord_tuple.setData(coord_tuple);
    
    DataReferenceImpl ref_coord_tuple2 = new DataReferenceImpl("ref_c_t2");
    ref_coord_tuple2.setData(coord_tuple2);

    ConstantMap[] yellow = new ConstantMap[] {
      new ConstantMap(1., Display.Red),
      new ConstantMap(1., Display.Green),
      new ConstantMap(0., Display.Blue),
    };
    ConstantMap[] cyan  = new ConstantMap[] {
      new ConstantMap(0., Display.Red),
      new ConstantMap(1., Display.Green),
      new ConstantMap(1., Display.Blue),
    };


    // for simple dipslay, use
    //disp.addReference(ref_coord_tuple);
    //disp.addReference(ref_coord_tuple2);


// ...or...for interactive display, use
    disp.addReferences(new DirectManipulationRendererJ2D(), ref_coord_tuple,
cyan);
    disp.addReferences(new DirectManipulationRendererJ2D(), ref_coord_tuple2,
yellow);

    // to list out the values at the cursor
    final DisplayRenderer dr = disp.getDisplayRenderer();

    CellImpl cell = new CellImpl() {
      public void doAction() throws VisADException {
        double xcoord = dr.getDirectAxisValue(x);
        double ycoord = dr.getDirectAxisValue(y);
        System.out.println("x,y ="+xcoord+"  "+ycoord);
      }
    };
    cell.addReference(ref_coord_tuple);
    cell.addReference(ref_coord_tuple2);
// end of list out values addition...


    JFrame frame = new JFrame("Dot Application");
    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {System.exit(0);}
    });

    // create JPanel in JFrame
    JPanel panel = new JPanel();
    frame.getContentPane().add(disp.getComponent());

    // set size of JFrame and make it visible
    frame.setSize(300, 300);
    frame.setVisible(true);
  }
}



-- 
Tom Whittaker (tomw@xxxxxxxxxxxxx)
University of Wisconsin-Madison
Space Science and Engineering Center
Phone/VoiceMail: 608/262-2759
Fax: 608/262-5974


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