Package org.opensourcephysics.display2d
Class ByteRaster
java.lang.Object
org.opensourcephysics.display.MeasuredImage
org.opensourcephysics.display2d.ByteRaster
- All Implemented Interfaces:
Dimensioned,Drawable,Measurable,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
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidSets the default palette.voiddraw(DrawingPanel panel, Graphics g) Draws the image on the panel.booleanGet the allowRescale flag.byte[][]Gets the current palette.getInterior(DrawingPanel panel) Gets the dimension of the lattice in pixel units.intgetNx()Gets the number of x entries.intgetNy()Gets the number of y entries.bytegetValue(int ix, int iy) Gets a raster value from the given location.intindexFromPoint(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.doubleindexToX(int i) Gets the x coordinate for the given index.doubleindexToY(int i) Gets the y coordinate for the given index.voidRandomizes the lattice values.voidresizeLattice(int nx, int ny) Resizes the raster using the given number of x and y entries.voidresizeRaster(int _nx, int _ny) Resizes the raster using the given number of x and y entries.voidsetAll(byte[][] val) Sets a block of data to new values.voidsetAll(byte[][] val, double xmin, double xmax, double ymin, double ymax) Sets the lattice values and scale.voidsetAllowRescale(boolean allow) Image can rescale within drawing panel.voidsetBlock(byte[][] val) Sets a block of values starting at location (0,0).voidsetBlock(int ix_offset, int iy_offset, byte[][] val) Sets a block of values using byte data.voidsetBlock(int ix_offset, int iy_offset, int[][] val) Sets a block of values using integer data.voidSets the black and white palette.voidsetCol(int ix, int iy_offset, byte[] val) Sets a column of values.voidsetColorPalette(Color[] colors) Sets the color palette to the given array of colors.voidSets the color for grid line boundariesvoidsetIndexedColor(int i, Color color) Sets the color for a single index.voidsetRow(int iy, int ix_offset, byte[] val) Sets a row of cells to new values starting at the given column.voidsetShowGridLines(boolean showGridLines) Outlines the lattice boundaries with a grid.voidsetUnderEjs(boolean underEjs) voidsetValue(int ix, int iy, byte val) Sets a pixel at the given location to a new value.Shows the color associated with each value.intxToIndex(double x) Gets closest index from the given x world coordinate.intyToIndex(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, setYMinMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.opensourcephysics.display2d.ByteLattice
setMinMax, setVisible, setXMax, setXMin, setYMax, setYMinMethods inherited from interface org.opensourcephysics.display.Drawable
isInteractiveMethods inherited from interface org.opensourcephysics.display.Measurable
getXMax, getXMin, getYMax, getYMin, isMeasured
-
Field Details
-
scaleFactor
protected double scaleFactor
-
-
Constructor Details
-
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 Details
-
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:
resizeLatticein interfaceByteLattice- Parameters:
nx- the number of x entriesny- 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:
getNxin interfaceByteLattice- Returns:
- nx
-
getNy
public int getNy()Gets the number of y entries.- Specified by:
getNyin interfaceByteLattice- Returns:
- ny
-
randomize
public void randomize()Randomizes the lattice values.- Specified by:
randomizein interfaceByteLattice
-
getInterior
Gets the dimension of the lattice in pixel units.- Specified by:
getInteriorin interfaceDimensioned- Parameters:
panel-- Returns:
- the dimension
-
draw
Draws the image on the panel.- Specified by:
drawin interfaceDrawable- Overrides:
drawin classMeasuredImage- 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:
setAllin interfaceByteLattice- Parameters:
val- int[][] the new valuesxmin- doublexmax- doubleymin- doubleymax- 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:
setBlockin interfaceByteLattice- 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:
setBlockin interfaceByteLattice- 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:
setColin interfaceByteLattice- Parameters:
ix- the x index of the columniy_offset- the y offset in the columnval- 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:
setRowin interfaceByteLattice- Parameters:
iy- the row that will be setix_offset- the offsetval- 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:
setValuein interfaceByteLattice- Parameters:
ix-iy-val-
-
getValue
public byte getValue(int ix, int iy) Gets a raster value from the given location.- Specified by:
getValuein interfaceByteLattice- Parameters:
ix-iy-- Returns:
- the cell value.
-
setBWPalette
public void setBWPalette()Sets the black and white palette. -
setColorPalette
Sets the color palette to the given array of colors.- Specified by:
setColorPalettein interfaceByteLattice- Parameters:
colors-
-
getColorPalette
public byte[][] getColorPalette()Gets the current palette.- Returns:
- byte[][]
-
createDefaultColors
public void createDefaultColors()Sets the default palette.- Specified by:
createDefaultColorsin interfaceByteLattice
-
setIndexedColor
Sets the color for a single index.- Specified by:
setIndexedColorin interfaceByteLattice- Parameters:
i-color-
-
showLegend
Shows the color associated with each value.- Specified by:
showLegendin interfaceByteLattice- Returns:
- the JFrame containing the legend
-
setShowGridLines
public void setShowGridLines(boolean showGridLines) Outlines the lattice boundaries with a grid.- Specified by:
setShowGridLinesin interfaceByteLattice- Parameters:
showGridLines-
-
setGridLineColor
Sets the color for grid line boundaries- Specified by:
setGridLineColorin interfaceByteLattice- 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:
indexFromPointin interfaceByteLattice- Parameters:
x-y-- Returns:
- index
-
xToIndex
public int xToIndex(double x) Gets closest index from the given x world coordinate.- Specified by:
xToIndexin interfaceByteLattice- 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:
yToIndexin interfaceByteLattice- 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
-