Re: Domain, Range

Hi Vikram:

I've been through this myself in the past year (since my math
background is not strong I've had to learn a bunch of terminology),
so I'd like to add a couple of things to Bill's reply in the hopes
it might help you, too.

First, the Developer's Guide Section 2 has a nice diagram that for
me help solidify some of these relationships within the VisAD
contexts:

          FunctionType (image_sequence_type)
             /                      \
     function domain           function range
     RealType (hour)         FunctionType (image_type)
                                /               \
                       function domain      function range
                       RealTupleType        RealType(brightness)
                       /           \
            RealType (line)     RealType (element)

Secondly, I always like examples.  Just below is very short and
completely self-contained (well, except for using VisAD ;-)
application that might help illustrate two uses of domains and
ranges: one to define the function mapping ((line,element) - >
brightness) and the other to illustrate overriding the default range
on the Y axis.  I did this primarily to better understand the
relationships between the MathTypes and the Data.

import visad.*;
import visad.java2d.DisplayImplJ2D;
import java.io.IOException;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/* very, very simple display example.  Define a function that maps
from 
 * (line,element) to a brightness value.  Create a FlatField that
 * realizes this mapping for a domain of (300,300).  Fill the
FlatField
 * with values in the range (0-255).
 *
 * Create ScalaMappings of (line->YAxis), (element->XAxis) and
 * (brightness -> RGB).
 *
 * Also, set a range on the ScalaMap for the YAxis to illustrate the
 * effect/use of this.
*/

public class vt {

  public static void main(String args[])
         throws VisADException, IOException {

    // define types
    RealType line = new RealType("row");
    RealType element = new RealType("col");
    RealTupleType domain = new RealTupleType(line, element);

    RealType brightness = new RealType("brightness");
    RealTupleType range = new RealTupleType(brightness);

    FunctionType image_func = new FunctionType(domain, range);

    // now, define the Data objects
    Set domain_set = new Integer2DSet(300,300);
    FlatField image_data = new FlatField(image_func, domain_set);

    // make up some data (line,element) => brightness values
    double[][] values = new double[1][300*300];
    for (int i=0; i<300; i++) {
      for (int j=0; j<300; j++) {
        values[0][i + 300*j] = ((16*i)/300.) * ((16*j)/300);
      }
    }

    // put the data into the flatfield
    image_data.setSamples(values);

    // now make a reference for the data so it can be displayed
    DataReference image_ref =new DataReferenceImpl("image");
    image_ref.setData(image_data);

    // define the mappings of the display
    DisplayImpl di = new DisplayImplJ2D("display");

    // override the default range on display's Y axis
    ScalarMap line_map = new ScalarMap(line, Display.YAxis);
    line_map.setRange(-100,400);

    di.addMap(line_map);
    di.addMap(new ScalarMap(element, Display.XAxis));
    di.addMap(new ScalarMap(brightness, Display.RGB));

    // add the data reference
    di.addReference(image_ref);

    // create JFrame (i.e., a window) for display and slider
    // (cobbled from the DisplayTest examples)

      JFrame frame = new JFrame("Simple VisAD Application");

      frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {System.exit(0);}
      });

      // create JPanel in JFrame
      JPanel panel = new JPanel();
      panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
      panel.setAlignmentY(JPanel.TOP_ALIGNMENT);
      panel.setAlignmentX(JPanel.LEFT_ALIGNMENT);

      frame.getContentPane().add(panel);

      panel.add(di.getComponent());

      // set size of JFrame and make it visible
      frame.setSize(500, 600);
      frame.setVisible(true);
  }
}


Hope it helps...

tom

-- 
Tom Whittaker (tomw@xxxxxxxxxxxxx)
University of Wisconsin-Madison
Space Science and Engineering Center
Phone/VoiceMail: 608/262-2759
Fax: 608/263-6738

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