Weird Test-Case GriddedTo2DSet

Hi Desiree, hi all,

attached is a Desiree's test version, which was slightly modified by me.
She's got a 5 x 9 2D set and some corresponding z-values. The problem
is, when the heights have common values, the 2D set (no matter whether
linear or gridded) gets scaled down to a set with smaller dimensions. In
her case, the 5 x 9 set looks like a 5 x 6 set.

This disappears when I set the samples like

// set height values according to index
   flat_samples[0][c*nRows+r] = c*nRows+r;

rather then what should be

   flat_samples[0][c*nRows+r] = heightNaN[c*nRows+r];

I can't tell if this is an old bug. In fact, I'm running an older
version of VisAD @ home (I still see an old color bug), and till next
week I won't get the chance to update it and or test on another machine. 

So, in the meantime, I'd advise Desiree to download the most recent
VisAD release and test it (best thing would be with her own test program
but to use the modified version; s. below). If the problem persists, let
the list know, because I reckon this is a bug.

The test below also shows how to draw a mesh:

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

  // "0" is point- and "1" is mesh-mode
  dispGMC.setPolygonMode(1);

The method parameter is a static var of some class, which I haven't
found it in the documentation (and didn't spend a lot of time looking
for it either ;-) but I'm sure the list-archive has this information!

Cheers,

Ugo

Ps.: the test program; my modifications are marked with // UT

/*
VisAD Tutorial
Copyright (C) 2000 Ugo Taddei
*/

// Import needed classes

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 DGM1{

    // 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 DGM1(String []args)
        throws RemoteException, VisADException {

        float[] eastNaN
{3479991.5f,3479991.5f,3479991.5f,3479991.5f,3479991.5f,
                           
3479992.5f,3479992.5f,3479992.5f,3479992.5f,3479992.5f,
                           
3479993.5f,3479993.5f,3479993.5f,3479993.5f,3479993.5f,
                           
3479994.5f,3479994.5f,3479994.5f,3479994.5f,3479994.5f,
                           
3479995.5f,3479995.5f,3479995.5f,3479995.5f,3479995.5f,
                           
3479996.5f,3479996.5f,3479996.5f,3479996.5f,3479996.5f,
                           
3479997.5f,3479997.5f,3479997.5f,3479997.5f,3479997.5f,
                           
3479998.5f,3479998.5f,3479998.5f,3479998.5f,3479998.5f,
                           
3479999.5f,3479999.5f,3479999.5f,3479999.5f,3479999.5f};
        float[] northNaN
{5417829.5f,5417830.5f,5417831.5f,5417832.5f,5417833.5f,
                            
5417829.5f,5417830.5f,5417831.5f,5417832.5f,5417833.5f,
                            
5417829.5f,5417830.5f,5417831.5f,5417832.5f,5417833.5f,
                            
5417829.5f,5417830.5f,5417831.5f,5417832.5f,5417833.5f,
                            
5417829.5f,5417830.5f,5417831.5f,5417832.5f,5417833.5f,
                            
5417829.5f,5417830.5f,5417831.5f,5417832.5f,5417833.5f,
                            
5417829.5f,5417830.5f,5417831.5f,5417832.5f,5417833.5f,
                            
5417829.5f,5417830.5f,5417831.5f,5417832.5f,5417833.5f,
                            
5417829.5f,5417830.5f,5417831.5f,5417832.5f,5417833.5f};
        float[] 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,
                             245.63f,245.65f,245.63f,200.0f,200.0f,
                             245.62f,245.65f,245.63f,200.0f,200.0f,
                             245.60f,245.62f,245.63f,245.59f,200.0f,
                             245.60f,245.62f,245.63f,245.59f,200.0f,
                             245.58f,245.57f,245.62f,245.64f,245.54f};



        int nCols = 9;
        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,9,9); 

        // Get the Set samples to facilitate the calculations
        float[][] set_samples = domain_set.getSamples( true );
        
        // We create another array, with the same number of elements of
        // altitude and temperature, but organized as 
        float[][] flat_samples = new float[1][nCols*nRows]; 
    
        // ...and then we fill our 'flat' array with the generated values
        // by looping over NCOLS and NROWS     
        // specifiy height
        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] = 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 DGM1");
        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 DGM1(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: