NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

Re: Test-Case GriddedTo2DSet

Hi Ugo, Steve and others,

okay, it is surely better to use double, so I changed all values in my
example programm to double, see attached file. 
There is just one line I am confused about:

// Get the Set samples to facilitate the calculations
        //float[][] set_samples = domain_set.getSamples( true );

It is not possible to change that to double, but I am not using
set_samples somewhere else anyway, what is this method doing? I can't
remember, why I put it there in the first place.

The results still exists: I am loosing points. I changed to the current
visad.jar, which did not change anything at all.
I put 4*5 = 20 points in and the result is 3*3 = 9 in the display.
You can see a screenhsot of this at my homepage:

http://www-ipf.bau-verm.uni-karlsruhe.de/Personen/hilbring/welcome.html

Thanks for your help in advance.


oooooooooooooooooooooooooooooooooooooooooooooooo
Desiree Hilbring

Institut fuer Photogrammetrie und Fernerkundung  
Universitaet Karlsruhe, Germany
email: hilbring@xxxxxxxxxxxxxxxxxxxx             
# 0721 6083676                                   
oooooooooooooooooooooooooooooooooooooooooooooooo


On Sat, 7 Jul 2001, Ugo Taddei wrote:

> 
> Hi all,
> 
> Steve Emmerson wrote:
> > 
> > Desiree,
> > 
> > I think you might be having problems with the resolution of floating-point
> > values in Java.  Differences in the coordinate values are very close to the
> > resolution of the Java "float" primitive type.
> 
> Sorry about my answer. Just got Steve's mail this morning, after I had
> sent my answer (that is, my "guess").
> 
> (...)
> 
> > 
> > Because the float values are being transferred to a double array,
> > there's no reason that I can see not to specify the float values as
> > double to begin with.
> 
> Adding to that: Either use a Gridded2DSet with floats, or
> Gridded2DDoubleSet with doubles, but not Gridded2DDoubleSet with floats.
> > 
> > Regards,
> > Steve Emmerson   <http://www.unidata.ucar.edu>
> 
> Cheers,
> 
> Ugo
> 
import visad.*;
import visad.java2d.DisplayImplJ2D;
import java.rmi.RemoteException;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import visad.java3d.DisplayImplJ3D;

  /*
  
  Note:
  
    - alternative use of a Linear2DSet
    - common heightNaN values "interpolates" domain set -> weird!
    - call GraphicsModeControl.setPolygonMode(1); to draw mesh
    
 */
  


public class DGMKleinDouble{

    // Declare variables
    // The domain quantities longitude and latitude
    // and the dependent quantities altitude, temperature
        
    private RealType eastValues,northValues;
    private RealType heightValues;
    
    // Two Tuples: one to pack longitude and latitude together, as the domain
    // and the other for the range (altitude, temperature)    
    private RealTupleType domain_tuple;
    
    // The function (domain_tuple -> range_tuple )
    private FunctionType func_en_h;

    // Our Data values for the domain are represented by the Set
    private Set domain_set;
  
    // The Data class FlatField
    private FlatField vals_ff;  
  
    // The DataReference from data to display
    private DataReferenceImpl data_ref;

    // The 2D display, and its the maps
    private DisplayImpl display;
    private ScalarMap eastMap, northMap, heightMap;
  
    public DGMKleinDouble(String []args)
        throws RemoteException, VisADException {

        double[] eastNaN =
        {3479991.5 ,3479991.5 ,3479991.5 ,3479991.5 ,3479991.5 ,
         
         3479992.5 ,3479992.5 ,3479992.5 ,3479992.5 ,3479992.5 ,
         
         3479993.5 ,3479993.5 ,3479993.5 ,3479993.5 ,3479993.5 ,
         
         3479994.5 ,3479994.5 ,3479994.5 ,3479994.5 ,3479994.5 };
         
         
        double[] northNaN =
        {5417829.5 ,5417830.5 ,5417831.5 ,5417832.5 ,5417833.5 ,
         
         5417829.5 ,5417830.5 ,5417831.5 ,5417832.5 ,5417833.5 ,
         
         5417829.5 ,5417830.5 ,5417831.5 ,5417832.5 ,5417833.5 ,
         
         5417829.5 ,5417830.5 ,5417831.5 ,5417832.5 ,5417833.5 };
        double[] heightNaN = {245.00,200.0,245.0,200.0,245.0,
                             245.00,200.0,245.0,200.0,245.0,
                             245.00 ,200.0 ,245.00 ,200.0 ,245.0 ,
                              245.00 ,200.0 ,245.0 ,200.0 ,245.0 };       
        /*
        double[] heightNaN = {245.65f,200.0f,200.0f,200.0f,200.0f,
                             245.65f,200.0f,200.0f,200.0f,200.0f,
                             245.68f,245.66f,200.0f,200.0f,200.0f,
                              245.64f,245.64f,200.0f,200.0f,200.0f};          
        */



        int nCols = 4;
        int nRows = 5;
        double[][] coords = new double[2][nCols*nRows]; 
        for (int i=0;i<(nCols*nRows);i++) {
            coords[0][i]=eastNaN[i];
            coords[1][i]=northNaN[i];
        }
        
        
        // Create the quantities
        // Use RealType(String name);   
        eastValues = new RealType("eastValues");
        northValues = new RealType("northValues");
        
        domain_tuple = new RealTupleType(eastValues,northValues);
    
        heightValues = new RealType("heightValues");
    
        // Create a FunctionType (domain_tuple -> range_tuple )
        // Use FunctionType(MathType domain, MathType range)    
        func_en_h = new FunctionType(domain_tuple, heightValues);
  // UT  
        //domain_set = new Gridded2DDoubleSet(domain_tuple,coords,nRows,nCols); 
        domain_set = new Linear2DSet(domain_tuple,1,5,5,1,4,4); 

        // Get the Set samples to facilitate the calculations
        //double[][] set_samples = domain_set.getSamples( true );
        //float[][] set_samples = domain_set.getSamples( true );
        
        // We create another array, with the same number of elements of
        // altitude and temperature, but organized as 
        double[][] flat_samples = new double[1][nCols*nRows]; 
    
        // ...and then we fill our 'flat' array with the generated values
        // by looping over NCOLS and NROWS     
        // specifiy height
        int i=0;
        for(int c = 0; c < nCols; c++){
            for(int r = 0; r < nRows; r++){  
        // UT   
                flat_samples[0][c*nRows+r] = c*nRows+r;
                //flat_samples[0][c*nRows+r] = i++;
                //flat_samples[0][c*nRows+r] = heightNaN[c*nRows+r];
            }
        }
        /*
        for(int c = 0; c < NCOLS; c++)    
            for(int r = 0; r < NROWS; r++){     
                flat_samples[0][c*NROWS+r] = heightNaN[c*NROWS+r];              
                //System.out.println("height "+height[c*NROWS+r]);
            }
        */
    
      
        // Create a FlatField  
        // Use FlatField(FunctionType type, Set domain_set)    
        vals_ff = new FlatField( func_en_h, domain_set);
    
        // ...and put the values above into it
        // Note the argument false, meaning that the array won't be copied 
        vals_ff.setSamples( flat_samples , false ); 
     
        // Create Display and its maps    
        // A 2D display    
        display = new DisplayImplJ3D("display1");    
        
        // Create the ScalarMaps: latitude to XAxis, longitude to YAxis and
        // altitude to RGB and temperature to IsoContour
        // Use ScalarMap(ScalarType scalar, DisplayRealType display_scalar) 
        eastMap = new ScalarMap( eastValues,    Display.YAxis );
        northMap = new ScalarMap( northValues, Display.XAxis );
        heightMap = new ScalarMap(heightValues,Display.ZAxis);  
   
        // Add maps to display
        display.addMap( eastMap );
        display.addMap( northMap );    
  // UT
        display.addMap( heightMap );

  // UT
  display.addMap( new ScalarMap(heightValues,Display.RGB) );

        /*
        eastMap.setRange(-1.0, 1.0);
        northMap.setRange(-1.0, 1.0);
        heightMap.setRange(-1.0, 1.0);
        */

        //eastMap.setRange(3532000,3533000);
        //northMap.setRange(5379000,5380000);
        //heightMap.setRange(600,700);
        //heightMap.setRange(200,300);
        //heightMap.setRange(-1.0,1.0);
  
        // Create a data reference and set the FlatField as our data 
        data_ref = new DataReferenceImpl("data_ref");
        data_ref.setData( vals_ff );
    
        // Add reference to display
        display.addReference( data_ref );
  
  // UT
  GraphicsModeControl dispGMC = (GraphicsModeControl) 
display.getGraphicsModeControl();
  //dispGMC.setScaleEnable(true);
  dispGMC.setPolygonMode(1);
  
        // Create application window and add display to window
        JFrame jframe = new JFrame("VisAD Tutorial example DGMKleinDouble");
        jframe.getContentPane().add(display.getComponent());
    
    
        // Set window size and make it visible
        jframe.setSize(300, 300);
        jframe.setVisible(true);        
    }
  
  
    public static void main(String[] args)
        throws RemoteException, VisADException
    {
        new DGMKleinDouble(args);
    }

} //end of Visad Tutorial Program 3_09
  • 2001 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: