Class ByteRaster

java.lang.Object
org.opensourcephysics.display.MeasuredImage
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 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 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 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, 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(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, Color color)
      Sets the color for a single index.
      Specified by:
      setIndexedColor in interface ByteLattice
      Parameters:
      i -
      color -
    • showLegend

      public 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(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