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: Gif`s in visad

Hi Bill,

Sorry, but i can't do what i want today...

i follow your instructions, but i don`t know what happend.

The problem is that i need to show the gif in a display with maps
longitude and latitude like in the example that i send.

i need to paint the gif on a display with flatfield 
(latitude,longitude)->(Realtype)

tanks again...

Olver.

On Wed, 31 Jan 2001, Bill Hibbard wrote:

> Hi Olver,
> 
> > But, I really got a display with just 3 maps, longitude, latuitude and RGB
> > like this:
> > 
> > visad.ScalarMap lonMap = new visad.ScalarMap(visad.RealType.Longitude, 
> > visad.Display.XAxis );
> > visad.ScalarMap latMap = new visad.ScalarMap(visad.RealType.Latitude, 
> > visad.Display.YAxis );
> > visad.ScalarMap varMap = new visad.ScalarMap(varRaster,visad.Display.RGB );
> > 
> > where varRaster is a RealType.
> > 
> > The GIFForm has as a range a tuple of 3 componets (R,G,B), and I need
> > to convert it to a RealType to put into a map Display.RGB.
> > 
> > There's an example in the P5_09 from the visad's tutorial, but it use 5
> > maps.
> 
> As described in tutorial section 5.9, a GIF image is read as
> a FlatField with MathType:
> 
>   ( (ImageElement, ImageLine) -> (Red, Green, Blue) )
> 
> This means that it is a mapping from image line and element to
> true-color red, green and blue components. A ScalarMap to RGB
> uses psuedo-color when you want to adjust the color map for
> a single RealType. You could use a ScalarMap of Red, Green or
> Blue to RGB. Or could use ScalarMaps of all three to RGB, to
> adjust non-linear mappings for each of Red, Green and Blue.
> 
> The domain of a GIF image is defined by simple line and element
> coordinates, since GIF images do not include navigation information
> for the mapping between (line, element) and (latitude, longitude).
> [Note that the McIDAS and HDF-EOS images that VisAD reads do include
> such navigation information, but they are much more complex file
> formats than GIF.]
> 
> If you happen to know the mapping between (line, element) and
> (latitude, longitude) for your GIF image, you can extract the
> colors values from the FlatField by:
> 
>   float[][] colors = gif_field.getFloats();
>   // now colors[0] is an array of red values, colors[1] is an
>   // array of green values, and colors[2] is an array of blue
>   // values
> 
> and then build a new FlatField with MathType:
> 
>   ((Latitude, Longitude) -> (Red, Green, Blue))
> 
> and use a Gridded2DSet for its domain Set, that defines the
> (lat, lon) locations of the pixels.
> 
> Cheers,
> Bill
> ----------------------------------------------------------
> Bill Hibbard, SSEC, 1225 W. Dayton St., Madison, WI  53706
> hibbard@xxxxxxxxxxxxxxxxx  608-263-4427  fax: 608-263-6738
> http://www.ssec.wisc.edu/~billh/vis.html
> 
/*
VisAD Tutorial
Copyright (C) 2000 Ugo Taddei
*/

// Import needed classes

import visad.*;
import visad.util.*;
import visad.data.gif.*;
import visad.java2d.DisplayImplJ2D;
import visad.java3d.DisplayImplJ3D;
import java.rmi.RemoteException;
import java.awt.*;
import javax.swing.*;
import java.util.Calendar;
import java.util.GregorianCalendar;

/**
  VisAD Tutorial example 5_09
  Analyse the MathType of a GIF/JPEG image
    (( longitude, latitude )  -> ( redType, greenType, blueType ) ) 
  Run program with java P5_09 image_name
 * 
 */


public class P5_09{

  // Declare variables
  // The RealTypes
  
  private RealType time, longitude, latitude;
  private RealType redType, greenType, blueType;
   
  
  // The function 
  // ( time -> ( ( longitude, latitude ) -> ( redType, greenType,blueType ) ) )
  private FunctionType func_t_latlon; 
     
   
  // Our Data values for longitude, latitude are represented by the set

  private Set latlonSet;
 
  // Time values are given by the set by the set

  private Set timeSet;

 
  // A FieldImpl
   
  private FieldImpl timeField;  

  
  // The DataReference from the data to display
  
  private DataReferenceImpl data_ref;

  // The 2D display, and its the maps
  
  private DisplayImpl display;
  private ScalarMap timeAnimMap, timeZMap;
  private ScalarMap lonXMap, latYMap, altiZMap;
  private ScalarMap redMap, greenMap, blueMap;
  
  // The VisADSlider
  
  private VisADSlider vSlider;
   
  //private AnimationWidget animWid;
  
  public P5_09 (String[] args)
    throws RemoteException, VisADException {
    
    /*if(args.length != 1){
      System.out.println("run with \"java P5_09 image_nam.gif\"");
      return;
    }*/
    
    // Create GIFForm object
    GIFForm image = new GIFForm();
    
    // Get the image data
    FlatField imageData = (FlatField)image.open("c:/windows/HLPBELL.gif");
    
    // Print out the MathType
    System.out.println(imageData.getType().prettyString());
    
    
    // Get the image type. Oh, well, we know it's a FunctionType
    FunctionType functionType = (FunctionType) imageData.getType();
    
    //MathType imageType = imageData.getType();
       
    
    // Get the domain...
    
    RealTupleType domain = (RealTupleType) functionType.getDomain();
    
    //campo= new 
RealTupleType(visad.RealType.Longitude,visad.RealType.Latitude);
  
    /*visad.Linear2DSet ValDom = (visad.Linear2DSet)imageData.getDomainSet();
    int Columnas = ValDom.getX().getLength();
    int Filas = ValDom.getY().getLength();

    System.out.println("C "+Columnas+" F "+Filas);

    visad.Linear2DSet Valdom = new visad.Linear2DSet(domain,-77,-76,Filas,
                                            5,6,Columnas);
*/
    // ...and the range
       
    RealTupleType range = (RealTupleType)functionType.getRange();
    
    //System.out.println("Dominio: \n"+imageData.getDomainSet());
    // Create the quantities
    
    longitude = (RealType) domain.getComponent(0);
    latitude = (RealType) domain.getComponent(1);
        
    
    redType = (RealType) range.getComponent(0);
    greenType = (RealType) range.getComponent(1);
    blueType = (RealType) range.getComponent(2);
    
    

    // Create Display and its maps
    
    // The display
    
    //display = new DisplayImplJ3D("display1");
    display = new DisplayImplJ2D("display1");
    
    // Get display's graphics mode control draw scales 
    
    GraphicsModeControl dispGMC = (GraphicsModeControl) 
display.getGraphicsModeControl();
    
    dispGMC.setScaleEnable(true);    
    
    
//HERE BEGINS THE PROBLEM!!!


    // Create the ScalarMaps
    
    lonXMap = new ScalarMap( RealType.Longitude, Display.XAxis );    
    latYMap = new ScalarMap( RealType.Latitude, Display.YAxis );
    
    //NOW redMap WILL BE MY  RGB MAP 
    redMap =  new ScalarMap( new RealType("RGB"), Display.RGB );
  //  greenMap =  new ScalarMap( greenType, Display.Green );
  //  blueMap =  new ScalarMap( blueType, Display.Blue );
    
    // Add maps to display
    
    display.addMap( lonXMap );
    display.addMap( latYMap );
    display.addMap( redMap );
//    display.addMap( greenMap );
//    display.addMap( blueMap );
    
      
    // Create a data reference and set the FieldImpl as our data 
    
    
    visad.RealTupleType campo=new 
visad.RealTupleType(visad.RealType.Longitude,visad.RealType.Latitude);
    visad.FunctionType functionType1 = new visad.FunctionType(campo,range);

    visad.Linear2DSet ValDom = (visad.Linear2DSet)imageData.getDomainSet();
    int Columnas = ValDom.getX().getLength();
    int Filas = ValDom.getY().getLength();



    visad.Linear2DSet Valdom = new visad.Linear2DSet(campo,0,40,Filas,
                                            0,40,Columnas);

    visad.FlatField FF = new visad.FlatField(functionType1,Valdom);
    //System.out.println("dim: "+imageData.getRangeDimension());
    for(int i=0;i<imageData.getRangeDimension();i++)
        FF.setSample(i,imageData.getSample(i));
    
    System.out.println("dom: "+imageData.getRangeSets());
    
    //float[][] colors = imaget1.getFloats();
  // now colors[0] is an array of red values, colors[1] is an
  // array of green values, and colors[2] is an array of blue
  // values

    visad.DataReferenceImpl ref_imaget1 = new 
visad.DataReferenceImpl("ref_imaget1");
    ref_imaget1.setData(FF);
    display.addReference( ref_imaget1);

    
    
    
    /*
    data_ref = new DataReferenceImpl("image_ref");
    
    data_ref.setData( imageData );
    
    // Add reference to display
    
    display.addReference( data_ref );
    
    
   */
    // Get AnimationControl from the Animation ScalarMap
    //AnimationControl ac = (AnimationControl) timeAnimMap.getControl();
    
    // and start animation
    
    //ac.setOn( true );
    
    // Create the AnimationWidget
    //animWid = new AnimationWidget( timeAnimMap );
    
    // Create application window, put display into it 
  
    JFrame jframe = new JFrame("VisAD Tutorial example 5_09");
    jframe.getContentPane().setLayout( new BorderLayout());
    jframe.getContentPane().add(display.getComponent(), BorderLayout.CENTER);
    
    // Set window size and make it visible
    
    jframe.setSize(300, 300);
    jframe.setVisible(true);
    

  }
  
  
  public static void main(String[] args)
    throws RemoteException, VisADException
  {
    new P5_09(args);
  }

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