org.opensourcephysics.display2d
Class ByteRaster

java.lang.Object
  extended by org.opensourcephysics.display.MeasuredImage
      extended by org.opensourcephysics.display2d.ByteRaster
All Implemented Interfaces:
Dimensioned, Drawable, Measurable, ByteLattice

public class ByteRaster
extends MeasuredImage
implements Dimensioned, ByteLattice

A ByteRaster contains an array of bytes where each byte represents an image pixel. The image dimensions are the same as the dimensions of the byte array.

Version:
1.0
Author:
Wolfgang Christian

Field Summary
protected  double scaleFactor
           
 
Fields inherited from class org.opensourcephysics.display.MeasuredImage
image, visible, xmax, xmin, ymax, ymin
 
Constructor Summary
ByteRaster(int _nx, int _ny)
          Constructs a byte raster with the given size.
 
Method Summary
 void createDefaultColors()
          Sets the default palette.
 void draw(DrawingPanel panel, java.awt.Graphics g)
          Draws the image on the panel.
 boolean getAllowRescale()
          Get the allowRescale flag.
 byte[][] getColorPalette()
          Gets the current palette.
 java.awt.Dimension getInterior(DrawingPanel panel)
          Gets the dimension of the lattice in pixel units.
 int getNx()
          Gets the number of x entries.
 int getNy()
          Gets the number of y entries.
 byte getValue(int ix, int iy)
          Gets a raster value from the given location.
 int indexFromPoint(double x, double y)
          Determines the lattice index (row-major order) from given x and y world coordinates Returns -1 if the world coordinates are outside the lattice.
 double indexToX(int i)
          Gets the x coordinate for the given index.
 double indexToY(int i)
          Gets the y coordinate for the given index.
 void randomize()
          Randomizes the lattice values.
 void resizeLattice(int nx, int ny)
          Resizes the raster using the given number of x and y entries.
 void resizeRaster(int _nx, int _ny)
          Resizes the raster using the given number of x and y entries.
 void setAll(byte[][] val)
          Sets a block of data to new values.
 void setAll(byte[][] val, double xmin, double xmax, double ymin, double ymax)
          Sets the lattice values and scale.
 void setAllowRescale(boolean allow)
          Image can rescale within drawing panel.
 void setBlock(byte[][] val)
          Sets a block of values starting at location (0,0).
 void setBlock(int ix_offset, int iy_offset, byte[][] val)
          Sets a block of values using byte data.
 void setBlock(int ix_offset, int iy_offset, int[][] val)
          Sets a block of values using integer data.
 void setBWPalette()
          Sets the black and white palette.
 void setCol(int ix, int iy_offset, byte[] val)
          Sets a column of values.
 void setColorPalette(java.awt.Color[] colors)
          Sets the color palette to the given array of colors.
 void setGridLineColor(java.awt.Color c)
          Sets the color for grid line boundaries
 void setIndexedColor(int i, java.awt.Color color)
          Sets the color for a single index.
 void setRow(int iy, int ix_offset, byte[] val)
          Sets a row of cells to new values starting at the given column.
 void setShowGridLines(boolean showGridLines)
          Outlines the lattice boundaries with a grid.
 void setUnderEjs(boolean underEjs)
           
 void setValue(int ix, int iy, byte val)
          Sets a pixel at the given location to a new value.
 javax.swing.JFrame showLegend()
          Shows the color associated with each value.
 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 org.opensourcephysics.display.MeasuredImage
getImage, getXMax, getXMin, getYMax, getYMin, isMeasured, setImage, setMinMax, setVisible, setXMax, setXMin, setYMax, setYMin
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.opensourcephysics.display2d.ByteLattice
setMinMax, setVisible, setXMax, setXMin, setYMax, setYMin
 
Methods inherited from interface org.opensourcephysics.display.Measurable
getXMax, getXMin, getYMax, getYMin, isMeasured
 

Field Detail

scaleFactor

protected double scaleFactor
Constructor Detail

ByteRaster

public ByteRaster(int _nx,
                  int _ny)
Constructs a byte raster with the given size. Unsigned cell values are 0 to 255. Signed cell values are -128 to 127.

Parameters:
_nx - the number of values in x direction
_ny - the number of values in y direction
Method Detail

resizeLattice

public void resizeLattice(int nx,
                          int ny)
Resizes the raster using the given number of x and y entries. Implementation of ByteLattice interface.

Specified by:
resizeLattice in interface ByteLattice
Parameters:
nx - the number of x entries
ny - the number of y entries

setUnderEjs

public void setUnderEjs(boolean underEjs)

resizeRaster

public void resizeRaster(int _nx,
                         int _ny)
Resizes the raster using the given number of x and y entries.

Parameters:
_nx - the number of x entries
_ny - the number of y entries

getNx

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

Specified by:
getNx in interface ByteLattice
Returns:
nx

getNy

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

Specified by:
getNy in interface ByteLattice
Returns:
ny

randomize

public void randomize()
Randomizes the lattice values.

Specified by:
randomize in interface ByteLattice

getInterior

public java.awt.Dimension getInterior(DrawingPanel panel)
Gets the dimension of the lattice in pixel units.

Specified by:
getInterior in interface Dimensioned
Parameters:
panel -
Returns:
the dimension

draw

public void draw(DrawingPanel panel,
                 java.awt.Graphics g)
Draws the image on the panel.

Specified by:
draw in interface Drawable
Overrides:
draw in class MeasuredImage
Parameters:
panel -
g -

setAllowRescale

public void setAllowRescale(boolean allow)
Image can rescale within drawing panel.

Parameters:
allow -

getAllowRescale

public boolean getAllowRescale()
Get the allowRescale flag.

Returns:
true if image will rescale

setAll

public void setAll(byte[][] val)
Sets a block of data to new values. The lattice is resized to fit the new data if needed.

Parameters:
val -

setAll

public void setAll(byte[][] val,
                   double xmin,
                   double xmax,
                   double ymin,
                   double ymax)
Sets the lattice values and scale. The lattice is resized to fit the new data if needed.

Specified by:
setAll in interface ByteLattice
Parameters:
val - int[][] the new values
xmin - double
xmax - double
ymin - double
ymax - double

setBlock

public void setBlock(byte[][] val)
Sets a block of values starting at location (0,0). A pixel is set to 1 if the value is >0; the cell is set to zero otherwise

Specified by:
setBlock in interface ByteLattice
Parameters:
val -

setBlock

public void setBlock(int ix_offset,
                     int iy_offset,
                     byte[][] val)
Sets a block of values using byte data. A pixel is set to 1 if the value is >0; the cell is set to zero otherwise

Specified by:
setBlock in interface ByteLattice
Parameters:
ix_offset -
iy_offset -
val -

setBlock

public void setBlock(int ix_offset,
                     int iy_offset,
                     int[][] val)
Sets a block of values using integer data. A pixel is set to 1 if the value is >0; the cell is set to zero otherwise

Parameters:
ix_offset -
iy_offset -
val -

setCol

public void setCol(int ix,
                   int iy_offset,
                   byte[] val)
Sets a column of values.

Specified by:
setCol in interface ByteLattice
Parameters:
ix - the x index of the column
iy_offset - the y offset in the column
val - values in column

setRow

public void setRow(int iy,
                   int ix_offset,
                   byte[] val)
Sets a row of cells to new values starting at the given column. A cell is set to 1 if the value is >0; the cell is set to zero otherwise

Specified by:
setRow in interface ByteLattice
Parameters:
iy - the row that will be set
ix_offset - the offset
val - the value

setValue

public void setValue(int ix,
                     int iy,
                     byte val)
Sets a pixel at the given location to a new value.

Specified by:
setValue in interface ByteLattice
Parameters:
ix -
iy -
val -

getValue

public byte getValue(int ix,
                     int iy)
Gets a raster value from the given location.

Specified by:
getValue in interface ByteLattice
Parameters:
ix -
iy -
Returns:
the cell value.

setBWPalette

public void setBWPalette()
Sets the black and white palette.


setColorPalette

public void setColorPalette(java.awt.Color[] colors)
Sets the color palette to the given array of colors.

Specified by:
setColorPalette in interface ByteLattice
Parameters:
colors -

getColorPalette

public byte[][] getColorPalette()
Gets the current palette.

Returns:
byte[][]

createDefaultColors

public void createDefaultColors()
Sets the default palette.

Specified by:
createDefaultColors in interface ByteLattice

setIndexedColor

public void setIndexedColor(int i,
                            java.awt.Color color)
Sets the color for a single index.

Specified by:
setIndexedColor in interface ByteLattice
Parameters:
i -
color -

showLegend

public javax.swing.JFrame showLegend()
Shows the color associated with each value.

Specified by:
showLegend in interface ByteLattice
Returns:
the JFrame containing the legend

setShowGridLines

public void setShowGridLines(boolean showGridLines)
Outlines the lattice boundaries with a grid.

Specified by:
setShowGridLines in interface ByteLattice
Parameters:
showGridLines -

setGridLineColor

public void setGridLineColor(java.awt.Color c)
Sets the color for grid line boundaries

Specified by:
setGridLineColor in interface ByteLattice
Parameters:
c -

indexFromPoint

public int indexFromPoint(double x,
                          double y)
Determines the lattice index (row-major order) from given x and y world coordinates Returns -1 if the world coordinates are outside the lattice.

Specified by:
indexFromPoint in interface ByteLattice
Parameters:
x -
y -
Returns:
index

xToIndex

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

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

indexToX

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

Parameters:
i - int
Returns:
double the x coordinate

yToIndex

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

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

indexToY

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

Parameters:
i - int
Returns:
double the y coordinate