org.opensourcephysics.display2d
Class GridPointData

java.lang.Object
  extended by org.opensourcephysics.display2d.GridPointData
All Implemented Interfaces:
GridData

public class GridPointData
extends java.lang.Object
implements GridData

GridPointData stores numeric data on a scaled rectangular grid using an array of points. Every grid point contains the x and y coordinates and one or more components. The first component is usually the magnitude of the quantity of interest. Components can represent almost anything. For example, we often use color-coded arrows to display vector fields. The arrows's color is the first sample and its vertical and horizonal components are the second and third components. This data is stored in an internal array as follows:

 data=new double [n][m][5]<\code>
 vertex=data[n][m]<\code>

 vertex[0] = x  <\code>
 vertex[1] = y  <\code>
 vertex[2] = val_1  <\code>
 vertex[3] = val_2  <\code>
 vertex[4] = val_3  <\code>
 <\pre>

Version:
1.1
Author:
Wolfgang Christian

Field Summary
protected  double bottom
           
protected  boolean cellData
           
protected  double[][][] data
           
protected  double dx
           
protected  double dy
           
protected  double left
           
protected  java.lang.String[] names
           
protected  double right
           
protected  double top
           
 
Constructor Summary
GridPointData(int ix, int iy, int ncomponents)
          Constructor Data2D
 
Method Summary
 GridPointData createGridPointData(int ncomponents)
          Creates a new GridPointData object with the same grid points and the given number of components.
 double getBottom()
          Gets the y value for the last row of the grid.
 int getComponentCount()
          Gets the number of data components.
 java.lang.String getComponentName(int i)
          Gets the name of the component,
 double[][][] getData()
          Gets the array containing the data.
 double getDx()
          Gets the change in x between grid columns.
 double getDy()
          Gets the change in y between grid rows.
 double getLeft()
          Gets the x value for the first column in the grid.
static XML.ObjectLoader getLoader()
          Returns the XML.ObjectLoader for this class.
 int getNx()
          Gets the number of x entries.
 int getNy()
          Gets the number of y entries.
 double getRight()
          Gets the x value for the right column in the grid.
 double getTop()
          Gets the y value for the first row of the grid.
 double getValue(int ix, int iy, int component)
          Gets the value of the given component at the given location.
 double[] getVertex(double x, double y)
          Gets the vertex closest to the specified location
 double[] getZRange(int n)
          Gets the minimum and maximum values of the n-th component.
 double indexToX(int i)
          Gets the x coordinate for the given index.
 double indexToY(int i)
          Gets the y coordinate for the given index.
 double interpolate(double x, double y, int index)
          Estimates the value of a component at an untabulated point, (x,y).
 double[] interpolate(double x, double y, int[] indexes, double[] values)
          Estimates multiple sample components at an untabulated point, (x,y).
 boolean isCellData()
          Gets the cellData flag.
 void setCellScale(double _left, double _right, double _bottom, double _top)
          Sets the left, right, bottom, and top of the grid data using a cell model.
 void setCenteredCellScale(double xmin, double xmax, double ymin, double ymax)
          Sets the grid such that the centers of the corner cells match the given coordinates.
 void setComponentName(int i, java.lang.String name)
          Sets the name of the component.
 void setData(double[][][] newdata)
          Sets the array containing the data.
 void setScale(double _left, double _right, double _bottom, double _top)
          Sets the left, right, bottom, and top of the grid data using a lattice model.
 void setValue(int ix, int iy, int component, double value)
          Sets the value of the given component at the given location.
 int xToIndex(double x)
          Gets closest index from the given x world coordinate.
 int yToIndex(double y)
          Gets closest index from the given y world coordinate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

data

protected double[][][] data

left

protected double left

right

protected double right

bottom

protected double bottom

top

protected double top

dx

protected double dx

dy

protected double dy

cellData

protected boolean cellData

names

protected java.lang.String[] names
Constructor Detail

GridPointData

public GridPointData(int ix,
                     int iy,
                     int ncomponents)
Constructor Data2D

Parameters:
ix -
iy -
ncomponents -
Method Detail

createGridPointData

public GridPointData createGridPointData(int ncomponents)
Creates a new GridPointData object with the same grid points and the given number of components.

Parameters:
ncomponents - number of samples dataset.
Returns:
the newly created Data2D

setComponentName

public void setComponentName(int i,
                             java.lang.String name)
Sets the name of the component.

Specified by:
setComponentName in interface GridData
Parameters:
i - int the component index
name - String

getComponentName

public java.lang.String getComponentName(int i)
Gets the name of the component,

Specified by:
getComponentName in interface GridData
Parameters:
i - int the component index
Returns:
String the name

getComponentCount

public int getComponentCount()
Gets the number of data components.

Specified by:
getComponentCount in interface GridData
Returns:
int

setScale

public void setScale(double _left,
                     double _right,
                     double _bottom,
                     double _top)
Sets the left, right, bottom, and top of the grid data using a lattice model.

Specified by:
setScale in interface GridData
Parameters:
_left -
_right -
_bottom -
_top -

setCellScale

public void setCellScale(double _left,
                         double _right,
                         double _bottom,
                         double _top)
Sets the left, right, bottom, and top of the grid data using a cell model. Coordinates are centered on each cell and will NOT include the edges.

Specified by:
setCellScale in interface GridData
Parameters:
_left -
_right -
_bottom -
_top -

setCenteredCellScale

public void setCenteredCellScale(double xmin,
                                 double xmax,
                                 double ymin,
                                 double ymax)
Sets the grid such that the centers of the corner cells match the given coordinates. Coordinates are centered on each cell and the bounds are ouside the max and min values.

Specified by:
setCenteredCellScale in interface GridData
Parameters:
xmin -
xmax -
ymin -
ymax -

isCellData

public boolean isCellData()
Gets the cellData flag.

Specified by:
isCellData in interface GridData
Returns:
true if cell data.

getValue

public double getValue(int ix,
                       int iy,
                       int component)
Gets the value of the given component at the given location.

Specified by:
getValue in interface GridData
Parameters:
ix - x index
iy - y index
component -
Returns:
the value.

setValue

public void setValue(int ix,
                     int iy,
                     int component,
                     double value)
Sets the value of the given component at the given location.

Specified by:
setValue in interface GridData
Parameters:
ix - x index
iy - y index
component -
value -

getNx

public int getNx()
Gets the number of x entries.

Specified by:
getNx in interface GridData
Returns:
nx

getNy

public int getNy()
Gets the number of y entries.

Specified by:
getNy in interface GridData
Returns:
ny

getZRange

public double[] getZRange(int n)
Gets the minimum and maximum values of the n-th component.

Specified by:
getZRange in interface GridData
Parameters:
n - the component
Returns:
{zmin,zmax}

getVertex

public double[] getVertex(double x,
                          double y)
Gets the vertex closest to the specified location

Parameters:
x -
y -
Returns:
vertex array

interpolate

public double interpolate(double x,
                          double y,
                          int index)
Estimates the value of a component at an untabulated point, (x,y). Interpolate uses bilinear interpolation on the grid. Although the interpolating function is continous across the grid boundaries, the gradient changes discontinuously at the grid square boundaries.

Specified by:
interpolate in interface GridData
Parameters:
x - the untabulated x
y - the untabulated y
index - the component index
Returns:
the interpolated sample

interpolate

public double[] interpolate(double x,
                            double y,
                            int[] indexes,
                            double[] values)
Estimates multiple sample components at an untabulated point, (x,y). Interpolate uses bilinear interpolation on the grid. Although the interpolating function is continous across the grid boundaries, the gradient changes discontinuously at the grid square boundaries.

Specified by:
interpolate in interface GridData
Parameters:
x - untabulated x
y - untabulated y
indexes - to be interpolated
values - array will contain the interpolated values
Returns:
the interpolated array

getData

public double[][][] getData()
Gets the array containing the data.

Specified by:
getData in interface GridData
Returns:
the data

setData

public void setData(double[][][] newdata)
Sets the array containing the data. Use with caution. This method is included for backward compatibility. Users are responsible for setting the x and y coordinate values. Users are also responsible for synchronization with clients.


getLeft

public final double getLeft()
Gets the x value for the first column in the grid.

Specified by:
getLeft in interface GridData
Returns:
the leftmost x value

getRight

public final double getRight()
Gets the x value for the right column in the grid.

Specified by:
getRight in interface GridData
Returns:
the rightmost x value

getTop

public final double getTop()
Gets the y value for the first row of the grid.

Specified by:
getTop in interface GridData
Returns:
the topmost y value

getBottom

public final double getBottom()
Gets the y value for the last row of the grid.

Specified by:
getBottom in interface GridData
Returns:
the bottommost y value

getDx

public final double getDx()
Gets the change in x between grid columns.

Specified by:
getDx in interface GridData
Returns:
the bottommost y value

getDy

public final double getDy()
Gets the change in y between grid rows.

Specified by:
getDy in interface GridData
Returns:
the bottommost y value

indexToX

public double indexToX(int i)
Gets the x coordinate for the given index.

Specified by:
indexToX in interface GridData
Parameters:
i - int
Returns:
double the x coordinate

indexToY

public double indexToY(int i)
Gets the y coordinate for the given index.

Specified by:
indexToY in interface GridData
Parameters:
i - int
Returns:
double the y coordinate

xToIndex

public int xToIndex(double x)
Gets closest index from the given x world coordinate.

Specified by:
xToIndex in interface GridData
Parameters:
x - double the coordinate
Returns:
int the index

yToIndex

public int yToIndex(double y)
Gets closest index from the given y world coordinate.

Specified by:
yToIndex in interface GridData
Parameters:
y - double the coordinate
Returns:
int the index

getLoader

public static XML.ObjectLoader getLoader()
Returns the XML.ObjectLoader for this class.

Returns:
the object loader