Re: domain values

Hi Isaac,

the technique I use to achieve this was taken from previous postings
to the visad-list.  I have attached the code and hope you find it useful.

I can't say I understand the code completely, but it works.  However, I'll
tell you as much as I know about the method...

If you have a look at the javadoc for ScalarMap.getScale(), you will see:
display_value = data_value * so[0] + so[1];

where "so" is an array to contain scale and offset.

Taking a guess, I would say that "so[0]" is the
scale, and "so[1]" is the offset.  "data_value" is
the domain value you are after.  Putting this
all together, we get:

display_value = (domain_value * scale) + offset;
domain_value = (display_value - offset) / scale;

Note that you have to do this for each type in
your domain.  In the attached code, it's done
twice, as the domain type is (Latitude, Longitude).

Hope this helps,
Jim.
---
Jim Koutsovasilis
Bureau of Meteorology, Australia
jimk@xxxxxxxxxx


Brobbey,Isaac wrote:

hi all:

can anyone show me how to translate the cursor values from the display into
domain values ?
if the cursor picks say (23, -12), is there any method in visad that takes
this value and changes it to reflect a data value in the domain?

thanks

Isaac




/**
  * Converts the screen coordinates (x,y) into 
  * domain coordinates (lat,lon).
  *
  * In this sample, the domain is:
  * (Latitude, Longitude)
  *
  * @param x            the x screen value.
  * @param y            the y screen value.
  * @param display      the display.
  * @return             an array of domain values.  First element is
  *                     the latitude, second element in the longitude.
  */
public float [] screenToLatLon(int x, int y, DisplayImpl display)
{
        DisplayRenderer renderer = display.getDisplayRenderer();
        MouseBehavior mouse = renderer.getMouseBehavior();
        if ( null == mouse ) {
                return null;
        }

        VisADRay ray = mouse.findRay( x, y );

        double [] cursor = new double[] {
                                ray.position[ 0 ], // x
                                ray.position[ 1 ], // y
                                ray.position[ 2 ]  // z
                                };
        double [] xScaleOffset = new double[ 2 ];
        double [] yScaleOffset = new double[ 2 ];

        double [] dummy1 = new double[ 2 ];
        double [] dummy2 = new double[ 2 ];

        // "lonMap" is a scalar map that has been mapped
        // from RealType.Longitude to Display.XAxis.
        // The code assumes that lonMap is of type ScalarMap
        // and is a member variable of the enclosing class.
        lonMap.getScale( xScaleOffset, dummy1, dummy2 );

        // "latMap" is a scalar map that has been mapped
        // from RealType.Latitude to Display.YAxis.
        // The code assumes that latMap is of type ScalarMap
        // and is a member variable of the enclosing class.
        latMap.getScale( yScaleOffset, dummy1, dummy2 );

        final float [] result = new float[2];

        // Extract the latitude.
        result[ 0 ]= (float)( ( cursor[ 1 ] - yScaleOffset[ 1 ] ) /
                         yScaleOffset[ 0 ] );

        // Extract the longitude.
        result[ 1 ]= (float)( ( cursor[ 0 ] - xScaleOffset[ 1 ] ) / 
                        xScaleOffset[ 0 ]) ;

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