Re: Visad basics

while not quite the same, I had the need to display the dataset
corresponding to a picked point for 3D scatter plots.  This was easily
done using the below code which used a right mouse click to select the
data point of interest whose data values are thereafter displayed in a
popup JTable.

      // set up object picking for J3D plot
      if ( plotType.equalsIgnoreCase ( "scatter3D" ) ) {
        pmrJ3D = new PickManipulationRendererJ3D();
        dr     = plotObj.getDisplayImpl().getDisplayRenderer();
        dr.setPickThreshhold( pickThreshhold );

        //  add data ref using pick renderer to display
        try  {
          plotObj.getDisplayImpl().addReferences( pmrJ3D,
masterSplitPane.getDataRef() );

          plotObj.getDisplayImpl().addDisplayListener( new
DisplayListener(){
            public void displayChanged ( DisplayEvent e )
                    throws VisADException, RemoteException  {

              if ( e.getId () == DisplayEvent.MOUSE_RELEASED_RIGHT )  {
                int i = pmrJ3D.getCloseIndex();

                FlatField ff
(FlatField)masterSplitPane.getDataRef().getData();
                double[] pickedPt = ff.getValues( i );

                JOptionPane.showMessageDialog( parent,
                                               createPickedDesignPanel(
realType, pickedPt ),
                                               "Picked Design Point",
 
JOptionPane.PLAIN_MESSAGE,
                                               null );
                }
              }
            });
          }
        catch ( Exception e3 )  {
          e3.printStackTrace ();
          }
        }


  /**
   * Method createPickedDesignPanel creates JTable to display picked
data point
   */
  public JPanel createPickedDesignPanel ( RealType[] realType, double[]
pickedPt )  {

    String[][] data    = new String[pickedPt.length][2];
    String[]   colName = { new String("Parameter"), new String("Value")
};

    JPanel holderPanel = new JPanel();
    holderPanel.setLayout( new BorderLayout() );
    holderPanel.setBorder( new EmptyBorder( 5, 5, 5, 5 ) );

    for ( int k = 0; k < pickedPt.length; k++ ) {
      //resultsPanel.add( new JLabel( realType[k].getName() + ":  " +
String.valueOf( pickedPt[k] ) ) );
      data[k][0] = realType[k].getName();
      data[k][1] = String.valueOf( pickedPt[k] );
    }

    JTable table = new JTable( data, colName );
    holderPanel.add( table.getTableHeader(), BorderLayout.NORTH );
    holderPanel.add( table, BorderLayout.CENTER );

    return holderPanel;

    }

-----Original Message-----
[mailto:owner-visad@xxxxxxxxxxxxxxxx]On Behalf Of Bill Hibbard
Sent: Tuesday, June 28, 2005 6:17 AM
Cc: visad@xxxxxxxxxxxxxxxx


Hi Greg,

> I need to provide some visual feedback when a user clicks on a data
> point.  My thought is to overlay a cross shape on the point, ie create
a
> new reference and add it to the display.  Reading the archives keeps
> pointing me to Test47.java example.  Unfortunately, I just can't
follow
> it very well.  I'm apparently missing some fundamental VisAD
> understanding.

Another approach to highlighting would be to include
RealTypes ScalarMap'ed to color in your Data, and changing
the values of those RealTypes when you want to highlight.

> I am able to run the example in Jbuilder and I see 6 shapes, at the
same
> elevation from left to right:
> 1) a tiny purple dot,
> 2) a small purple cube,
> 3) a pink "x",
> 4) a medium sized white cube,
> 5) text characters "1.2",
> 6) a large purple cube.
>
> In setupServerData method I see:
>     values = new float[][] {{0.0f, 1.0f, 2.0f, 3.0f, 0.0f, 1.0f}};
>
> Presumably, these are the X coordinates of the 6 objects since they
are
> all at the same height. Why it doesn't continue with 4.0f and 5.0f
after
> 3.0f, I haven't a clue.  Text is apparently mapped differently for
some
> reason.

As you note, the VisAD library is complex so its better
to analyze examples than to presume, especially when the
presumption is not consistent with the observed behavior.
In this case, the 'values' array is passed to the setSamples()
method of the histograms1 FlatField, which has MathType
(ir_radiance -> count). Hence, the numbers in the 'values'
array have RealType 'count'. 'count' is mapped to Display.Shape
rather than Display.XAxis, so they are not X coordinates.
They are indices into the 'shapes' array passed to
shape_control.setShapes() (treated as ordinary integer indices
since count_set, passed to shape_control.setShapeSet(), is
just a sequence of integers 0, 1, 2, 3). Hence the sequence
in 'values', (i.e., 0, 1, 2, 3, 0, 1) iterates through the 4
shapes in the 'shapes' array, then iterates through the first
two again.

In shapes, text is converted by the PlotText.render_label()
method into a geometrical shape and handled like any other
shape geometry. When text is used in a shape, the Display
logic doesn't know the shape came from text. If text is
displayed using a ScalarMap to Text then the Display logic
knows it is text.

> Anyway, I really have a hard time following this VisAD code.  So many
> internal details of the VisAD data structures seem to be hidden or
deeply
> layered that it makes it extremely difficult to follow.   I have
looked
> through the tutorials and understand the simpler ones for the most
part
> but this shape mapping I just don't get.  How does each of the 6 items
> get mapped to a new shape?  Does anybody have any examples with
comments
> that document each step along the way?  Preferably one that shows how
to
> provide highlighting or some other type of visual feedback when data
> points in the display are clicked.

Unfortunately, the Tutorial does not cover Shapes, so
you'll need to consult the VisAD Developer's Guide at:
  http://www.ssec.wisc.edu/~billh/guide.html
See sections 4.3.12 and 4.7.

You are correct that VisAD is complex, which is a
consequence of its generality. In order to work with
something as complex as shapes, you'll either need to
first really experiment with the simpler topics in the
tutorial, or carefully analyze (as I have above) the
examples and Developers Guide sections about shape (few
as they are).  If you do that and get stuck on some
point, we'll be happy to answer questions sent to the
list.

Good luck,
Bill