Re: Grid problem

Hi Karan,

> 1. We are facing some problem with our work. We are
> adding all the gridded sets to union sets and then
> adding the union sets to the reference and then
> reference to display. The same procedure for both the
> vertical and horizontal lines(gridded sets).
> When the user clicks on window the old references(here
> the gridded sets) is to be removed. We are invoking a
> method which removes these references. But we found
> only the last gridded sets are removed(one from
> vertical and horizontal).
>          The following method is used to create the
> grid and the bottom one to remove the references of
> teh gridded sets. Please let me know how to remove
> full gridded sets.
> 
> public void drawGrid(float[] X, float[] Y, int imax,
> int jmax) throws
> RemoteException, VisADException {
> 
>         float[][] samp = new float[2][2];
> 
>         for(int j = 0; j < jmax; j++) {
>             Gridded2DSet[] g_set = new
> Gridded2DSet[imax-1];
>             for(int i = 0; i < (imax-1); i++) {
>                 samp[0][0] = X[(i+j*imax)];
>                 samp[1][0] = Y[(i+j*imax)];
> 
>                 samp[0][1] = X[((i+j*imax)+1)];
>                 samp[1][1] = Y[((i+j*imax)+1)];
>                 g_set[i] = new
> Gridded2DSet(domain_tuple, samp, 2);
> 
>             }
> // for horizontal lines
>             UnionSet us = new UnionSet(g_set);
>                   //
> gridded sets added to union set
>             d_ref1 = new DataReferenceImpl("d_ref1");
>             d_ref1.setData(us);
> // for this reference the union sets are set as data.
>             display.addReference(d_ref1,
> getGriddedSetsColor());  //
> reference added to display.
> }
> 
>         for(int i = 0; i < imax; i++) {
>             Gridded2DSet[] g_set1 = new
> Gridded2DSet[jmax-1];
>             for(int j = 0; j < (jmax-1); j++) {
>                 samp[0][0] = X[(i+j*imax)];
>                 samp[1][0] = Y[(i+j*imax)];
> 
>                 samp[0][1] = X[((i+j*imax)+imax)];
>                 samp[1][1] = Y[((i+j*imax)+imax)];
>                 g_set1[j] = new
> Gridded2DSet(domain_tuple, samp, 2);
> 
>             }
> // for vertical lines
>             UnionSet us1 = new UnionSet(g_set1);
>                //
> gridded sets added to union set.
>             d_ref2 = new DataReferenceImpl("d_ref2");
>             d_ref2.setData(us1);
> // for this reference the union sets are set as data
>             display.addReference(d_ref2,
> getGriddedSetsColor());  //
> reference added to display.
>         }
>     }//end drawgrid
> 
>  public void removeMainGridReference() throws
> RemoteException,
> VisADException
> 
>         display.removeReference(d_ref1);
>         display.removeReference(d_ref2);
>     }

This is a trival programming bug, that you shouldn't need
my help with. You are calling addReference() inside two
loops, for each row and column. But you are only calling
removeReference() twice, not inside loops. In the loops
you need to save arrays of DataReferences, and then
remove them all.

> 2. We are creating a geometry and are using the
> DirectManipulationRenderer for the realtuples. With
> this i can create the geometry and when the geometry
> is satisfied i will divide the boundary points to some
> N divisions and i want to use the
> DirectManipulationRenderer separately for these
> points. Is is possible to link the display with 2
> renderers? Please let me know if there is any
> alternative apprach to achieve this.

Yes, each call to adReference() or addReferences() adds
another DataRenderer (if you don't supply one explicitly,
then a default is constructed). You can add as many as
you want.

> 3. I have a gridded set and when i click near that
> griddedset, it should be selected. Is is it possble to
> select any gridded sets. Please let me know about
> this.

I have attached a new version of visad/bom/PickManipulationRendererJ3D.java
that enables you to pick Sets. See its main() method for an
example of how to use it.

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
//
// PickManipulationRendererJ3D.java
//

/*
VisAD system for interactive analysis and visualization of numerical
data.  Copyright (C) 1996 - 2001 Bill Hibbard, Curtis Rueden, Tom
Rink, Dave Glowacki, Steve Emmerson, Tom Whittaker, Don Murray, and
Tommy Jasmin.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.

You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA
*/

package visad.bom;

import visad.*;
import visad.java3d.*;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Vector;
import java.util.Enumeration;
import java.rmi.*;

import javax.media.j3d.*;

/**
   PickManipulationRendererJ3D is the VisAD class for direct
   manipulation of rubber band boxes
*/
public class PickManipulationRendererJ3D extends DirectManipulationRendererJ3D {

  private int mouseModifiersMask = 0;
  private int mouseModifiersValue = 0;

  public PickManipulationRendererJ3D () {
    this (0, 0);
  }

  /** mmm and mmv determine whehter SHIFT or CTRL keys are required -
      this is needed since this is a greedy DirectManipulationRenderer
      that will grab any right mouse click (that intersects its 2-D
      sub-manifold) */
  public PickManipulationRendererJ3D (int mmm, int mmv) {
    super();
    mouseModifiersMask = mmm;
    mouseModifiersValue = mmv;
  }

  /** for use in drag_direct */
  private transient DataDisplayLink link = null;
  private transient DataReference ref = null;

  private float[][] spatialValues = null;
  /** index into spatialValues found by checkClose */
  private int closeIndex = -1;

  private int directManifoldDimension = -1;

  /** information calculated by checkDirect */
  /** explanation for invalid use of DirectManipulationRenderer */
  private String whyNotDirect = null;

  /** possible values for whyNotDirect */
  private final static String notSimpleField
    "not simple field";
  private final static String notSimpleTuple
    "not simple tuple";

  private boolean stop = false;

  public void checkDirect() throws VisADException, RemoteException {
    setIsDirectManipulation(false);

    DisplayImpl display = getDisplay();

    DataDisplayLink[] Links = getLinks();
    if (Links == null || Links.length == 0) {
      link = null;
      return;
    }
    link = Links[0];

    ref = link.getDataReference();

    ShadowType shadow = link.getShadow().getAdaptedShadowType();
    MathType type = link.getType();

    if (type instanceof FunctionType) {
      if (shadow.getLevelOfDifficulty() != ShadowType.SIMPLE_FIELD) {
        whyNotDirect = notSimpleField;
        return;
      }
    }
    else if (type instanceof SetType) {
      if (shadow.getLevelOfDifficulty() != ShadowType.SIMPLE_FIELD) {
        whyNotDirect = notSimpleField;
        return;
      }
    }
    else {
      if (shadow.getLevelOfDifficulty() != ShadowType.SIMPLE_TUPLE) {
        whyNotDirect = notSimpleTuple;
        return;
      }
    }

    setIsDirectManipulation(true);
  }

  private int getDirectManifoldDimension() {
    return directManifoldDimension;
  }

  public String getWhyNotDirect() {
    return whyNotDirect;
  }

  public void addPoint(float[] x) throws VisADException {
    // may need to do this for performance
  }

// methods customized from DataRenderer:

  public CoordinateSystem getDisplayCoordinateSystem() {
    return null;
  }

  /** set spatialValues from ShadowType.doTransform */
  public synchronized void setSpatialValues(float[][] spatial_values) {
    // these are X, Y, Z values
    spatialValues = spatial_values;
  }

  /** check if ray intersects sub-manifold */
  public synchronized float checkClose(double[] origin, double[] direction) {
    int mouseModifiers = getLastMouseModifiers();
    if ((mouseModifiers & mouseModifiersMask) != mouseModifiersValue) {
      return Float.MAX_VALUE;
    }

    float distance = Float.MAX_VALUE;
    if (spatialValues == null) return distance;
    float o_x = (float) origin[0];
    float o_y = (float) origin[1];
    float o_z = (float) origin[2];
    float d_x = (float) direction[0];
    float d_y = (float) direction[1];
    float d_z = (float) direction[2];
/*
System.out.println("origin = " + o_x + " " + o_y + " " + o_z);
System.out.println("direction = " + d_x + " " + d_y + " " + d_z);
*/
    for (int i=0; i<spatialValues[0].length; i++) {
      float x = spatialValues[0][i] - o_x;
      float y = spatialValues[1][i] - o_y;
      float z = spatialValues[2][i] - o_z;
      float dot = x * d_x + y * d_y + z * d_z;
      x = x - dot * d_x;
      y = y - dot * d_y;
      z = z - dot * d_z;
      float d = (float) Math.sqrt(x * x + y * y + z * z);
      if (d < distance) {
        distance = d;
        closeIndex = i;
      }
/*
System.out.println("spatialValues["+i+"] = " + spatialValues[0][i] + " " +
spatialValues[1][i] + " " + spatialValues[2][i] + " d = " + d);
*/
    }
/*
System.out.println("checkClose: distance = " + distance);
*/
    return distance;
  }

  public int getCloseIndex() {
    return closeIndex;
  }

  public synchronized void drag_direct(VisADRay ray, boolean first,
                                       int mouseModifiers) {
    if (ref == null) return;

    if (first) {
      try {
        ref.setData(ref.getData());
      }
      catch (VisADException e) {
      }
      catch (RemoteException e) {
      }
    }
  }

  private static final int N = 64;

  /** test PickManipulationRendererJ3D */
  public static void main(String args[])
         throws VisADException, RemoteException {

    RealType x = new RealType("x");
    RealType y = new RealType("y");
    RealType z = new RealType("z");
    FunctionType f1d = new FunctionType(x, y);
    RealTupleType xy = new RealTupleType(x, y);
    FunctionType f2d = new FunctionType(xy, z);
    TextType t = new TextType("text");
    RealType s = new RealType("shape");

    Data[] td = {new Real(x, 0.5),
                 new Real(y, 0.5),
                 new Real(z, 0.5),
                 new Text(t, "text")};
    Tuple text = new Tuple(td);

    Real[] sd = {new Real(x, -0.5),
                 new Real(y, -0.5),
                 new Real(z, -0.5),
                 new Real(s, 0.0)};
    RealTuple shape = new RealTuple(sd);

    Real real = new Real(x, -0.5);

    Real[] rtd = {new Real(x, 0.5),
                 new Real(y, -0.5),
                 new Real(z, 0.0)};
    RealTuple real_tuple = new RealTuple(rtd);

    FlatField field1d = new FlatField(f1d, new Linear1DSet(x, -1.0, -0.5, 64));
    double[][] values = new double[1][64];
    for (int i=0; i<64; i++) values[0][i] = 0.5 + Math.abs(i - 31.5) / 63.0;
    field1d.setSamples(values);

    Set set2d = new Linear2DSet(xy, 0.5, 1.0, 32, -0.25, 0.25, 32);
    FlatField field2d = new FlatField(f2d, set2d);
    values = new double[1][1024];
    int k = 0;
    for (int i=0; i<32; i++) {
      for (int j=0; j<32; j++) {
        values[0][k++]
          Math.sqrt((i-15.5) * (i-15.5) + (j-15.5) * (j-15.5)) / 32.0;
      }
    }
    field2d.setSamples(values);

    // construct Java3D display and mappings
    DisplayImpl display = new DisplayImplJ3D("display");
    DisplayRenderer dr = display.getDisplayRenderer();
    dr.setPickThreshhold(0.2f); // allow sloppy picking

    ScalarMap xmap = new ScalarMap(x, Display.XAxis);
    display.addMap(xmap);
    xmap.setRange(-1.0, 1.0);

    ScalarMap ymap = new ScalarMap(y, Display.YAxis);
    display.addMap(ymap);
    ymap.setRange(-1.0, 1.0);

    ScalarMap zmap = new ScalarMap(z, Display.ZAxis);
    display.addMap(zmap);
    zmap.setRange(-1.0, 1.0);

    ScalarMap tmap = new ScalarMap(t, Display.Text);
    display.addMap(tmap);
    TextControl tcontrol = (TextControl) tmap.getControl();
    tcontrol.setCenter(true);

    ScalarMap smap = new ScalarMap(s, Display.Shape);
    display.addMap(smap);
    ShapeControl scontrol = (ShapeControl) smap.getControl();
    scontrol.setShapeSet(new Integer1DSet(s, 1));
    VisADLineArray cross = new VisADLineArray();
    cross.coordinates = new float[]
      {0.1f,  0.1f, 0.0f,    -0.1f, -0.1f, 0.0f,
       0.1f, -0.1f, 0.0f,    -0.1f,  0.1f, 0.0f};
    cross.vertexCount = cross.coordinates.length / 3;
    scontrol.setShapes(new VisADGeometryArray[] {cross});

    GraphicsModeControl mode = display.getGraphicsModeControl();
    mode.setScaleEnable(true);

    DataReferenceImpl tref = new DataReferenceImpl("text");
    tref.setData(text);
    display.addReferences(new PickManipulationRendererJ3D(), tref);
    CellImpl cellt = new CellImpl() {
      private boolean first = true;
      public void doAction() throws VisADException, RemoteException {
        if (first) first = false;
        else System.out.println("text picked");
      }
    };
    cellt.addReference(tref);

    DataReferenceImpl sref = new DataReferenceImpl("shape");
    sref.setData(shape);
    display.addReferences(new PickManipulationRendererJ3D(), sref);
    CellImpl cells = new CellImpl() {
      private boolean first = true;
      public void doAction() throws VisADException, RemoteException {
        if (first) first = false;
        else System.out.println("shape picked");
      }
    };
    cells.addReference(sref);

    DataReferenceImpl rref = new DataReferenceImpl("Real");
    rref.setData(real);
    ConstantMap[] rmaps = {new ConstantMap(5.0, Display.PointSize)};
    display.addReferences(new PickManipulationRendererJ3D(), rref, rmaps);
    CellImpl cellr = new CellImpl() {
      private boolean first = true;
      public void doAction() throws VisADException, RemoteException {
        if (first) first = false;
        else System.out.println("Real picked");
      }
    };
    cellr.addReference(rref);

    DataReferenceImpl rtref = new DataReferenceImpl("RealTuple");
    rtref.setData(real_tuple);
    ConstantMap[] rtmaps = {new ConstantMap(5.0, Display.PointSize)};
    display.addReferences(new PickManipulationRendererJ3D(), rtref, rtmaps);
    CellImpl cellrt = new CellImpl() {
      private boolean first = true;
      public void doAction() throws VisADException, RemoteException {
        if (first) first = false;
        else System.out.println("RealTuple picked");
      }
    };
    cellrt.addReference(rtref);

    DataReferenceImpl field1dref = new DataReferenceImpl("field1d");
    field1dref.setData(field1d);
    display.addReferences(new PickManipulationRendererJ3D(), field1dref);
    CellImpl cellfield1d = new CellImpl() {
      private boolean first = true;
      public void doAction() throws VisADException, RemoteException {
        if (first) first = false;
        else System.out.println("1-D Field picked");
      }
    };
    cellfield1d.addReference(field1dref);

    DataReferenceImpl field2dref = new DataReferenceImpl("field2d");
    field2dref.setData(field2d);
    display.addReferences(new PickManipulationRendererJ3D(), field2dref);
    CellImpl cellfield2d = new CellImpl() {
      private boolean first = true;
      public void doAction() throws VisADException, RemoteException {
        if (first) first = false;
        else System.out.println("2-D Field picked");
      }
    };
    cellfield2d.addReference(field2dref);

    DataReferenceImpl setref = new DataReferenceImpl("set");
    setref.setData(set2d);
    ConstantMap[] smaps = {new ConstantMap(-1.0, Display.ZAxis)};
    display.addReferences(new PickManipulationRendererJ3D(), setref, smaps);
    CellImpl cellset = new CellImpl() {
      private boolean first = true;
      public void doAction() throws VisADException, RemoteException {
        if (first) first = false;
        else System.out.println("set picked");
      }
    };
    cellset.addReference(setref);

    // create JFrame (i.e., a window) for display and slider
    JFrame frame = new JFrame("test PickManipulationRendererJ3D");
    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {System.exit(0);}
    });

    // create JPanel in JFrame
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.setAlignmentY(JPanel.TOP_ALIGNMENT);
    panel.setAlignmentX(JPanel.LEFT_ALIGNMENT);
    frame.getContentPane().add(panel);

    // add display to JPanel
    panel.add(display.getComponent());

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

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