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 TypeMethodDescriptionvoid
Sets the default palette.void
draw
(DrawingPanel panel, Graphics g) Draws the image on the panel.boolean
Get the allowRescale flag.byte[][]
Gets the current palette.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
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
Sets the black and white palette.void
setCol
(int ix, int iy_offset, byte[] val) Sets a column of values.void
setColorPalette
(Color[] colors) Sets the color palette to the given array of colors.void
Sets the color for grid line boundariesvoid
setIndexedColor
(int i, 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.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.Drawable
isInteractive
Methods 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:
resizeLattice
in 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:
getNx
in interfaceByteLattice
- Returns:
- nx
-
getNy
public int getNy()Gets the number of y entries.- Specified by:
getNy
in interfaceByteLattice
- Returns:
- ny
-
randomize
public void randomize()Randomizes the lattice values.- Specified by:
randomize
in interfaceByteLattice
-
getInterior
Gets the dimension of the lattice in pixel units.- Specified by:
getInterior
in interfaceDimensioned
- Parameters:
panel
-- Returns:
- the dimension
-
draw
Draws the image on the panel.- Specified by:
draw
in interfaceDrawable
- Overrides:
draw
in 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:
setAll
in 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:
setBlock
in 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:
setBlock
in 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:
setCol
in 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:
setRow
in 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:
setValue
in interfaceByteLattice
- Parameters:
ix
-iy
-val
-
-
getValue
public byte getValue(int ix, int iy) Gets a raster value from the given location.- Specified by:
getValue
in 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:
setColorPalette
in interfaceByteLattice
- Parameters:
colors
-
-
getColorPalette
public byte[][] getColorPalette()Gets the current palette.- Returns:
- byte[][]
-
createDefaultColors
public void createDefaultColors()Sets the default palette.- Specified by:
createDefaultColors
in interfaceByteLattice
-
setIndexedColor
Sets the color for a single index.- Specified by:
setIndexedColor
in interfaceByteLattice
- Parameters:
i
-color
-
-
showLegend
Shows the color associated with each value.- Specified by:
showLegend
in interfaceByteLattice
- Returns:
- the JFrame containing the legend
-
setShowGridLines
public void setShowGridLines(boolean showGridLines) Outlines the lattice boundaries with a grid.- Specified by:
setShowGridLines
in interfaceByteLattice
- Parameters:
showGridLines
-
-
setGridLineColor
Sets the color for grid line boundaries- Specified by:
setGridLineColor
in 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:
indexFromPoint
in interfaceByteLattice
- Parameters:
x
-y
-- Returns:
- index
-
xToIndex
public int xToIndex(double x) Gets closest index from the given x world coordinate.- Specified by:
xToIndex
in 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:
yToIndex
in 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
-