RE: Simple surface plot

Ok so I am trying to show a 2D slice out of a 3D model grid;
(currVar is a netcdf Variable)

    DimensionIterator dimIter = currVar.getDimensionIterator();
    ucar.netcdf.Dimension dim0 = ( ucar.netcdf.Dimension )
dimIter.next();
    ucar.netcdf.Dimension dim1 = ( ucar.netcdf.Dimension )
dimIter.next();
    ucar.netcdf.Dimension dim2 = ( ucar.netcdf.Dimension )
dimIter.next();
    ucar.netcdf.Dimension dim3 = ( ucar.netcdf.Dimension )
dimIter.next();
        int[] index = {0, 0, 0, 0}; // first two indices fixed at 0, 0
      int sizeX = shape[2];
      int sizeY = shape[3];
      int sizeXY = sizeX*sizeY;

      float[][] xy = new float[2][];
      float[][] z = new float[1][];
      xy[0] = new float[sizeXY];
      xy[1] = new float[sizeXY];
      z[0] = new float[sizeXY];

      for (int j=0; j<sizeY; j++) {
        for (int i=0; i<sizeX; i++) {
          index[2] = i;
          index[3] = j;
          z[0][i+j*sizeX] = currVar.getFloat(index);

          xy[0][i+j*sizeX] = (float) i;
          xy[1][i+j*sizeX] = (float) j;
        }
      }

    RealType xtype = RealTypeFactory(dim2.getName());
    RealType ytype = RealTypeFactory(dim2.getName());
    RealType ztype = RealTypeFactory(currVar.getName());

    RealTupleType xyType = new RealTupleType(xtype, ytype);
    FunctionType ft = new FunctionType(xyType, ztype);

    // look this is the one i changed!!!
    //*** Gridded2DSet xySet = new Gridded2DSet(xyType, xy,
xy[0].length);
    Gridded2DSet xySet = new Gridded2DSet(xyType, xy, sizeX , sizeY);
    FlatField ffld = new FlatField(ft, xySet);
    ffld.setSamples(z);

    // create a DataReference
    DataReference setRef = new DataReferenceImpl("Visad2D data
reference");
    setRef.setData(ffld);

    // create a Display using Java2D
    DisplayImpl display = new DisplayImplJ3D("Visad2D display");

    // map plot to display coordinates
    display.addMap(new ScalarMap(xtype, Display.XAxis));
    display.addMap(new ScalarMap(ytype, Display.YAxis));
    display.addMap(new ScalarMap(ztype, Display.ZAxis));

    // link the Display to the data
    display.addReference(setRef);


so the first pass (line designated with //***) gave me this error:
System Error:   java.lang.ArrayIndexOutOfBoundsException: 1
System Error:           at
visad.ShadowFunctionOrSetType.doTransform(ShadowFunctionOrSetType.java:2
053)
System Error:           at
visad.java3d.ShadowFunctionOrSetTypeJ3D.doTransform(ShadowFunctionOrSetT
ypeJ3D.java:101)
System Error:           at
visad.java3d.DefaultRendererJ3D.doTransform(DefaultRendererJ3D.java:84)
System Error:           at
visad.java3d.RendererJ3D.doAction(RendererJ3D.java:163)
System Error:           at visad.DisplayImpl.doAction(DisplayImpl.java:808)
System Error:           at visad.ActionImpl.run(ActionImpl.java:186)
System Error:           at
visad.util.ThreadPool$ThreadMinnow.run(ThreadPool.java:76)

the second pass (as you see it above) got me past the Exception, but the
data looks like it's
displayed wrong: perhaps only took one longitude value and replicated
it.

So I have a couple of questions:
        what is the meaning of the 2 Gridded2DSet constructors? how does it
change how the data should be passed in?
        Sindre Mehus "Simple surface plot" example uses a Gridded3DSet; how
does that differ?



> -----Original Message-----
> From: owner-visad@xxxxxxxxxxxxxxxx
> [mailto:owner-visad@xxxxxxxxxxxxxxxx]On Behalf Of From: Bill Hibbard
> <hibbard@xxxxxxxxxxxxxxxxx>
> Sent: Tuesday, October 05, 1999 4:21 PM
> To: Sindre Mehus
> Cc: visad-list@xxxxxxxxxxxxx
> Subject: Re: Newbie: Simple surface plot
>
>
> Hi Sindre,
>
> > I downloaded VisAD a couple of days ago, and I must say I was really
> > impressed, in particular by the performance.
> >
> > Now to the question;  I want to draw a surface through a
> set of points
> > in R3, say
> >
> > 10, 100, 23
> > 10, 110, 54
> > 10, 120, 65
> > 20, 100, 69
> > 20, 110, 32
> > 20, 120, 25
> > ... etc
> >
> > Furthermore, I want the scale to display the "real" X, Y, Z values.
> >
> > What's the easiest way to do this?
>
> The easiest way is to construct a Set with domain dimension = 3
> and manifold dimension = 2 (so it will define a surface).  If the
> points lie on a gridded topology, use a Gridded3DSet with the
> constructor:
>
>   public Gridded3DSet(MathType type, float[][] samples, int lengthX,
>                       int lengthY) throws VisADException;
>
> where samples = new float[3][number_of_points] with
> samples[0][0] = 10, samples[1][0] = 100, samples[2][0] = 23,
> samples[0][1] = 10, samples[1][1] = 110, samples[2][1] = 54,
> etc
> and number_of_points = lengthX * lengthY describes the 2-D grid
> topology.
>
> If the points do not lie on a gridded topology, use an
> Irregular3DSet with the constructor:
>
>   public Irregular3DSet(MathType type, float[][] samples,
>                       CoordinateSystem coord_sys, Unit[] units,
>                       ErrorEstimate[] errors, Delaunay delan)
>                                          throws VisADException;
>
> where delan is a DelaunayCustom where you define an irregular
> topology of triangles embedded in 3-D space.
>
> This can be a little complex, especially if you use Irregular3DSet
> and DelaunayCustom, so please feel free to follow up with more
> questions.
>
> Cheers,
> Bill
> ----------------------------------------------------------
> Bill Hibbard, SSEC, 1225 W. Dayton St., Madison, WI  53706
> hibbard@xxxxxxxxxxxxxxxxx  608-263-4427  fax: 608-263-6738
> http://www.ssec.wisc.edu/~billh/vis.html
>
>