Re: questions on functionalities of VisAD X-Y style 2D plots

(forgot to cc the list and thank Tom W and Doug L for their
contributions to the code below)

One more thing:

m huang wrote:
> Hi
>
> Sorry to pile on so many questions. I appreciate people,
> particularly Bill, to take time to answer. I will reply
> the answers after finish this round.

> 2) Is there an *existing* set of shapes for the user to use
> as data points in the plot? I see there is support for creating
> any shapes and there is an example as how to do this for those
> who want to make a shape from scratch. I have tinkered with
> the tutorial example P2_06 and tried to map the example realTypes
> into Display.Shape, but I don't see anything showing up.

Here's the method I use to create some standard shapes.  All
shapes are drawn in a 1x1 box, so you have to scale them to
make the size you want.  I've attached the method we use for
that also:

     public static final String PLUS = "PLUS";
     public static final String CROSS = "CROSS";
     public static final String SQUARE = "SQUARE";
     public static final String FILLED_SQUARE = "FILLED_SQUARE";
     public static final String CUBE = "CUBE";
     public static final String TRIANGLE = "TRIANGLE";
     public static final String FILLED_TRIANGLE = "FILLED_TRIANGLE";

     /**
      * Create a predefined shape.  Shapes are drawn on a 1x1(x1) box.
      * Use <code>setSize()</code> methods to rescale.
      * @param  s  shape to create
      * @return corresponding shape
      */
     public static VisADGeometryArray makeShape(String s) {

         VisADGeometryArray shape = null;

         if (s.equals(PLUS)) {
             shape = new VisADLineArray();
             shape.coordinates
                 new float[] {-1.0f, 0.0f, 0.0f,  1.0f, 0.0f, 0.0f,
                               0.0f,-1.0f, 0.0f,  0.0f, 1.0f, 0.0f};

         } else if (s.equals(CROSS)) {
             shape = new VisADLineArray();
             shape.coordinates
                 new float[] { 1.0f,  0.0f, 0.0f, -1.0f,  0.0f,  0.0f,
                               0.0f, -1.0f, 0.0f,  0.0f,  1.0f,  0.0f,
                               0.0f,  0.0f, 1.0f,  0.0f,  0.0f, -1.0f};

         } else if (s.equals(SQUARE)) {
             shape = new VisADLineArray();
             shape.coordinates
                 new float[] { 1.0f,  1.0f, 0.0f,  1.0f, -1.0f, 0.0f,
                               1.0f, -1.0f, 0.0f, -1.0f, -1.0f, 0.0f,
                              -1.0f, -1.0f, 0.0f, -1.0f,  1.0f, 0.0f,
                              -1.0f,  1.0f, 0.0f,  1.0f,  1.0f, 0 };

         } else if (s.equals(FILLED_SQUARE)) {
             shape = new VisADQuadArray();
             shape.coordinates = new float[]
             {1.0f,  1.0f, 0.0f,     1.0f, -1.0f, 0.0f,
              -1.0f, -1.0f, 0.0f,    -1.0f, 1.0f, 0.0f};

             shape.normals = new float[12];
             for (int i=0; i<12; i+=3) {
                 shape.normals[i]   = 0.0f;
                 shape.normals[i+1] = 0.0f;
                 shape.normals[i+2] = 1.0f;
             }

         } else if (s.equals(CUBE)) {
             shape = new VisADQuadArray();
             shape.coordinates = new float[]
             {1.0f,  1.0f, -1.0f,     1.0f, -1.0f, -1.0f,
              1.0f, -1.0f, -1.0f,    -1.0f, -1.0f, -1.0f,
              -1.0f, -1.0f, -1.0f,    -1.0f,  1.0f, -1.0f,
              -1.0f,  1.0f, -1.0f,     1.0f,  1.0f, -1.0f,

              1.0f,  1.0f,  1.0f,     1.0f, -1.0f,  1.0f,
              1.0f, -1.0f,  1.0f,    -1.0f, -1.0f,  1.0f,
              -1.0f, -1.0f,  1.0f,    -1.0f,  1.0f,  1.0f,
              -1.0f,  1.0f,  1.0f,     1.0f,  1.0f,  1.0f,

              1.0f,  1.0f,  1.0f,     1.0f,  1.0f, -1.0f,
              1.0f,  1.0f, -1.0f,     1.0f, -1.0f, -1.0f,
              1.0f, -1.0f, -1.0f,     1.0f, -1.0f,  1.0f,
              1.0f, -1.0f,  1.0f,     1.0f,  1.0f,  1.0f,

              -1.0f,  1.0f,  1.0f,    -1.0f,  1.0f, -1.0f,
              -1.0f,  1.0f, -1.0f,    -1.0f, -1.0f, -1.0f,
              -1.0f, -1.0f, -1.0f,    -1.0f, -1.0f,  1.0f,
              -1.0f, -1.0f,  1.0f,    -1.0f,  1.0f,  1.0f,

              1.0f,  1.0f,  1.0f,     1.0f,  1.0f, -1.0f,
              1.0f,  1.0f, -1.0f,    -1.0f,  1.0f, -1.0f,
              -1.0f,  1.0f, -1.0f,    -1.0f,  1.0f,  1.0f,
              -1.0f,  1.0f,  1.0f,     1.0f,  1.0f,  1.0f,

              1.0f, -1.0f,  1.0f,     1.0f, -1.0f, -1.0f,
              1.0f, -1.0f, -1.0f,    -1.0f, -1.0f, -1.0f,
              -1.0f, -1.0f, -1.0f,    -1.0f, -1.0f,  1.0f,
              -1.0f, -1.0f,  1.0f,     1.0f, -1.0f,  1.0f};

             shape.normals = new float[144];
             for (int i=0; i<24; i+=3) {
                 shape.normals[i]     =  0.0f;
                 shape.normals[i+1]   =  0.0f;
                 shape.normals[i+2]   = -1.0f;

                 shape.normals[i+24]  =  0.0f;
                 shape.normals[i+25]  =  0.0f;
                 shape.normals[i+26]  =  1.0f;

                 shape.normals[i+48]  =  1.0f;
                 shape.normals[i+49]  =  0.0f;
                 shape.normals[i+50]  =  0.0f;

                 shape.normals[i+72]  = -1.0f;
                 shape.normals[i+73]  =  0.0f;
                 shape.normals[i+74]  =  0.0f;

                 shape.normals[i+96]  =  0.0f;
                 shape.normals[i+97]  =  1.0f;
                 shape.normals[i+98]  =  0.0f;

                 shape.normals[i+120] =  0.0f;
                 shape.normals[i+121] = -1.0f;
                 shape.normals[i+122] =  0.0f;
                 shape.normals[i+122] =  0.0f;
             }
         } else if (s.equals(TRIANGLE)) {
             shape = new VisADLineArray();
             shape.coordinates
                 new float[] { -1.0f, -0.5f, 0.0f,
                                1.0f, -0.5f, 0.0f,
                                0.0f,  1.0f, 0.0f };
         } else if (s.equals(FILLED_TRIANGLE)) {
             shape = new VisADTriangleArray();
             shape.coordinates
                 new float[] { -1.0f, -0.5f, 0.0f,
                                1.0f, -0.5f, 0.0f,
                                0.0f,  1.0f, 0.0f };

         } else {
             throw new IllegalArgumentException("unsupported shape " + s);
         }
         shape.vertexCount = shape.coordinates.length / 3;

         return shape;

     }

     /**
      * Set the size of the shapes.  Scales the size by size.
      * @param  shapes   shapes to resize
      * @param  size  scaling factor
      */
     public static VisADGeometryArray setSize(VisADGeometryArray shape,
                                              float size) {
         if (shape.coordinates != null) {
             for (int i=0; i<shape.coordinates.length; i++) {
                 shape.coordinates[i] *= size;
             }
         }
         return shape;
     }

Don
*************************************************************
Don Murray                               UCAR Unidata Program
dmurray@xxxxxxxxxxxxxxxx                        P.O. Box 3000
(303) 497-8628                              Boulder, CO 80307
http://www.unidata.ucar.edu/staff/donm
*************************************************************


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