RE: Setting Aspect Ratio while using autoscale

Hi Dave,

Here's a test program I wrote up just to display a particle doing a random 
walk. Jar files for the example are available at 
http://dods.shore.mbari.org/brian/pub/. The classes are in test.jar; the source 
is in test_src.jar. Run it from the command line as: java -cp 
test.jar;visad.jar org.mbari.test.PointVis3

The PointVis3 example is fairly simple. I've taken a slightly different 
approach when I need to add or remove DataReferences on the fly. To do that, I 
subclass JPanel and add code to initialize the DisplayImpl, RealTypes and the 
associated ScalarMaps and add the display to the Panel. Then I pass references 
of the display and RealTypes to a DataHandler class that creates the gravy that 
visad needs (tuples, functions, fields, etc), sets the data values, creates a 
DataReferenceImpl, and adds the DataReference to the display. The DataHandler 
class implements a listener interface, which would look something like:

public interface ISomeDataListener {
    public void update(Point point);
}

The DataHandler's update method then looks something like:
    public void update(Point point) throws RemoteException {
        // Pop the new point in the top of the queue and drop the lastpoint
        for (int i = points.length - 1; i > 0; i--) {
            points[i] = points[i - 1];
        }
        points[0] = (Point) point.clone(); 

        // Update the data on the display
        try {
            // the getXY method is illustrated below
            pointsFf.setSamples(getXY()); // a FlatField
        } catch (VisADException e) {
            e.printStackTrace();
        }

    }

    private float[][] getXY() {
        float[][] tmp = new float[2][points.length];
        for (int i = 0; i < points.length; i++) {
            if (points[i] != null) {
                tmp[0][i] = (float) points[i].getX();
                tmp[1][i] = (float) points[i].getY();
            } else {
                tmp[0][i] = 0F;
                tmp[1][i] = 0F;
            }
        }
        return tmp;
    }

The nice thing about this approach is that you can add and remove 
DataReferences as needed and whenever you update the data in a FlatField (with 
setSamples()) the display is updated.

Anyway, hope that helps.

Cheers
B
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Brian Schlining
Software Application Developer
Monterey Bay Aquarium Research Institute
brian@xxxxxxxxx
(831) 775-1855
http://www.mbari.org/~brian
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

> -----Original Message-----
> From: David Homiak [mailto:dhomiak@xxxxxxxxxxxx]
> Sent: Wednesday, November 07, 2001 12:36 PM
> To: 'Schlining, Brian'
> Subject: RE: Setting Aspect Ratio while using autoscale
> 
> Brian,
>       I've been interested in visualizing real-time data (time --> value)
> in VisAD as well, but am unsure of the best approach to incrementally and
> efficiently add data to the Gridded1DdoubleSet (time) and FlatField
> (value)
> so that the DisplayImpl updates properly with each addition. Would you
> mind
> sharing the approach you've taken to handle this? Thanks much!
> 
>     Dave Homiak
>     dhomiak@xxxxxxxxxxxx
> 
> > -----Original Message-----
> > From:       Schlining, Brian [SMTP:brian@xxxxxxxxx]
> > Sent:       Wednesday, November 07, 2001 1:15 PM
> > To: 'visad-list@xxxxxxxxxxxxx'
> > Subject:    Setting Aspect Ratio while using autoscale
> >
> > I've a display that's tracking the position of several objects
> continually
> > in real time. The display is set to autoscale (i.e
> > display.setAlwaysAutoScale(true)). My question is...Is there some way to
> > fix the Aspect Ratio of the display, so that 1 unit along the x-axis is
> > the same length as 1 unit along the y-axis, while using auto scaling?
> >
> > Cheers
> > B
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > Brian Schlining
> > Software Application Developer
> > Monterey Bay Aquarium Research Institute
> > brian@xxxxxxxxx
> > (831) 775-1855
> > http://www.mbari.org/~brian
> >
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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