Package org.opensourcephysics.display2d
Class FlatData
java.lang.Object
org.opensourcephysics.display2d.FlatData
- All Implemented Interfaces:
GridData
FlatData stores numeric data for 2d visualizations using a single array.
Components are stored in the array in row-major order.
Data components can represent almost anything. For example, we store an n by m grid of complex numbers as follows:
data=new double [2*n*m]<\code>
<\pre>- Version:
- 1.0
- Author:
- Wolfgang Christian
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal doubleGets the y value for the last row of the grid.intGets the number of data components.getComponentName(int i) Gets the name of the component,double[][][]getData()Gets the array containing the data.final doublegetDx()Gets the change in x between grid columns.final doublegetDy()Gets the change in y between grid rows.final doublegetLeft()Gets the x value for the first column in the grid.static XML.ObjectLoaderReturns the XML.ObjectLoader for this class.intgetNx()Gets the number of x entries.intgetNy()Gets the number of y entries.final doublegetRight()Gets the x value for the right column in the grid.final doublegetTop()Gets the y value for the first row of the grid.doublegetValue(int ix, int iy, int component) Gets the value of the given component at the given location.double[]getZRange(int n) Gets the minimum and maximum values of the n-th component.double[]getZRange(int n, double[] minmax) Gets the minimum and maximum values of the n-th component.doubleindexToX(int i) Gets the x coordinate for the given index.doubleindexToY(int i) Gets the y coordinate for the given index.doubleinterpolate(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).booleanGets the cellData flag.voidsetCellScale(double _left, double _right, double _bottom, double _top) Sets the left, right, bottom, and top of the grid data using a cell model.voidsetCenteredCellScale(double xmin, double xmax, double ymin, double ymax) Sets the grid such that the centers of the corner cells match the given coordinates.voidsetComponentName(int i, String name) Sets the name of the component.voidsetScale(double _left, double _right, double _bottom, double _top) Sets the left, right, bottom, and top of the grid data using a lattice model.voidsetValue(int ix, int iy, int component, double value) Sets the value of the given component at the given location.intxToIndex(double x) Gets closest index from the given x world coordinate.intyToIndex(double y) Gets closest index from the given y world coordinate.
-
Field Details
-
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
-
-
Constructor Details
-
FlatData
public FlatData(int ix, int iy, int ncomponents) FlatData constructor. The data array will contain ncomponents*ix*iy values.- Parameters:
ix- the number of x valuesiy- the number of y valuesncomponents- the number of components
-
-
Method Details
-
setComponentName
Sets the name of the component.- Specified by:
setComponentNamein interfaceGridData- Parameters:
i- int the component indexname- String
-
getComponentName
Gets the name of the component,- Specified by:
getComponentNamein interfaceGridData- Parameters:
i- int the component index- Returns:
- String the name
-
getComponentCount
public int getComponentCount()Gets the number of data components.- Specified by:
getComponentCountin interfaceGridData- 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. Lattice model XY coordinates are the edges of each cell and NOT the center. -
isCellData
public boolean isCellData()Gets the cellData flag.- Specified by:
isCellDatain interfaceGridData- 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. -
setValue
public void setValue(int ix, int iy, int component, double value) Sets the value of the given component at the given location. -
getNx
public int getNx()Gets the number of x entries. -
getNy
public int getNy()Gets the number of y entries. -
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. Cell model XY coordinates are centered on each cell NOT along the edges.- Specified by:
setCellScalein interfaceGridData- 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:
setCenteredCellScalein interfaceGridData- Parameters:
xmin-xmax-ymin-ymax-
-
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:
interpolatein interfaceGridData- Parameters:
x- the untabulated xy- the untabulated yindex-- 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:
interpolatein interfaceGridData- Parameters:
x- untabulated xy- untabulated yindexes- to be interpolatedvalues- array will contain the interpolated values- Returns:
- the interpolated array
-
getData
public double[][][] getData()Gets the array containing the data. -
getZRange
public double[] getZRange(int n) Gets the minimum and maximum values of the n-th component. -
getZRange
public double[] getZRange(int n, double[] minmax) Gets the minimum and maximum values of the n-th component. -
getLeft
public final double getLeft()Gets the x value for the first column in the grid. -
getRight
public final double getRight()Gets the x value for the right column in the grid. -
getTop
public final double getTop()Gets the y value for the first row of the grid. -
getBottom
public final double getBottom()Gets the y value for the last row of the grid. -
getDx
public final double getDx()Gets the change in x between grid columns. -
getDy
public final double getDy()Gets the change in y between grid rows. -
indexToX
public double indexToX(int i) Gets the x coordinate for the given index. -
indexToY
public double indexToY(int i) Gets the y coordinate for the given index. -
xToIndex
public int xToIndex(double x) Gets closest index from the given x world coordinate. -
yToIndex
public int yToIndex(double y) Gets closest index from the given y world coordinate. -
getLoader
Returns the XML.ObjectLoader for this class.- Returns:
- the object loader
-