Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## sim.util
Class TableLoader

    java.lang.Object
      sim.util.TableLoader

    public class TableLoader

extends java.lang.Object

TABLELOADER.java

This class provides utility methods for loading tables from files into int[][] or double[][] arrays. In MASON it's particularly useful for loading files of numbers or graphics into an IntGrid2D or DoubleGrid2D to display.

TableLoader at present can load the following kinds of files:

- "Plain" PBM files. These store binary (1 and 0) bitmaps in a text-readable format.
- "Raw" PBM files. These store binary (1 and 0) bitmaps in a somewhat more compressed binary format.
- "Plain" PGM files. These store grayscale images (from 0 to under some MAXVAL you can define) in a text-readable format.
- "Raw" PGM files. These store grayscale images (from 0 to under some MAXVAL you can define) in a somewhat more compressed binary format.
- PNG and GIF files which store binary, 8-bit grayscale, or 8-bit indexed data.
- Whitespace-delimited text files. These store each array row as a single line of numbers. The numbers are set off with spaces or tabs.

PBM And PGM ("PNM" files) The first four formats are defined by the Netpbm file format specification. Various graphics programs can emit PBM or PGM files. These files are collectively known as PNM files. MASON reads these files into int[][] arrays. Note that graphics programs typically emit PBM (black and white) files in the opposite numerical format than you'd expect: 1 is black, and 0 is white. On the other hand, PGM (monochrome) files are emitted however your graphics program sees fit, typically with 0 being black and MAXVAL-1, whatever you've set it to, being white.

If you're constructing these files by hand, note that MASON is a bit more generous about plain formats than the specification allows: MASON permits lines of any length, and you can have a MAXVAL of any size you like, as long as its within the integer data type range (normally, PGM only allows lines of about 70 chars and a MAXVAL of no more than 2^16).

PNG and GIF files These files must have colors stored as binary (black and white), 8-bit grayscale, or 8-bit indexed color.

Whitespace-delimited text filesnbsp; These files consist of rows of numbers, each row delimited with newlines. The numbers in each row are delimited with spaces or tabs. Unlike the PBM/PGM format, you cannot at present have comments in the file. The files are loaded into double[][] arrays, though TableLoader provides a simple utility conversion function to int[][] if you're sure that all the values are actually integers and would like an int array.

MASON determines the row width of the first row by parsing through the first line. Thereafter it checks to make sure that all subsequent rows are the same width (in terms of number of elements) and thus that the int[][] array is rectangular.

Constructor Summary
`TableLoader()`

Method Summary
`static double[][]` | `convertToDoubleArray(int[][] vals)` Converts an int[][] array to a double[][] array.
`static int[][]` | `convertToIntArray(double[][] vals)` Converts a double[][] array to an int[][] array only if all values are within the int range.
`static long[][]` | `convertToLongArray(double[][] vals)` Converts a double[][] array to a long[][] array only if all values are within the long range.
`static long[][]` | `convertToLongArray(int[][] vals)` Converts an int[][] array to a long[][] array.
`static int[][]` | `loadGIFFile(java.io.InputStream str)` Loads GIF files and returns the result as an int[][], where each integer value represents the color table index of the pixel.
`static int[][]` | `loadGIFFile(java.io.InputStream str, boolean flipY)` Loads GIF files and returns the result as an int[][], where each integer value represents the color table index of the pixel.
`static int[][]` | `loadPNGFile(java.io.InputStream str)` Loads PNG files and returns the result as an int[][].
`static int[][]` | `loadPNGFile(java.io.InputStream str, boolean flipY)` Loads PNG files and returns the result as an int[][].
`static int[][]` | `loadPNMFile(java.io.InputStream str)` Loads plain or raw PGM files or plain or raw PBM files and return the result as an int[][].
`static int[][]` | `loadPNMFile(java.io.InputStream str, boolean flipY)` Loads plain or raw PGM files or plain or raw PBM files and return the result as an int[][].
`static double[][]` | `loadTextFile(java.io.InputStream stream)` Loads into a double[][] a plain text file of numbers, with newlines dividing the numbers into rows and tabs or spaces delimiting columns.
`static double[][]` | `loadTextFile(java.io.InputStream str, boolean flipY)` Loads into a double[][] a plain text file of numbers, with newlines dividing the numbers into rows and tabs or spaces delimiting columns.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### TableLoader

    public TableLoader()

Method Detail

### loadPNMFile

    public static int[][] loadPNMFile(java.io.InputStream str,
                                      boolean flipY)
                               throws java.io.IOException

  Loads plain or raw PGM files or plain or raw PBM files and return the result as an int[][]. If flipY is true, then the Y dimension is flipped.

  Throws:
    `java.io.IOException`

### loadPNMFile

    public static int[][] loadPNMFile(java.io.InputStream str)
                               throws java.io.IOException

  Loads plain or raw PGM files or plain or raw PBM files and return the result as an int[][]. The Y dimension is not flipped.

  Throws:
    `java.io.IOException`

### loadTextFile

    public static double[][] loadTextFile(java.io.InputStream str,
                                          boolean flipY)
                                   throws java.lang.RuntimeException,
                                          java.io.IOException

  Loads into a double[][] a plain text file of numbers, with newlines dividing the numbers into rows and tabs or spaces delimiting columns. If flipY is true, then the Y dimension is flipped.

  Throws:
    `java.lang.RuntimeException`
    `java.io.IOException`

### loadTextFile

    public static double[][] loadTextFile(java.io.InputStream stream)
                                   throws java.io.IOException

  Loads into a double[][] a plain text file of numbers, with newlines dividing the numbers into rows and tabs or spaces delimiting columns. The Y dimension is not flipped.

  Throws:
    `java.io.IOException`

### loadGIFFile

    public static int[][] loadGIFFile(java.io.InputStream str,
                                      boolean flipY)
                               throws java.io.IOException

  Loads GIF files and returns the result as an int[][], where each integer value represents the color table index of the pixel. If flipY is true, then the Y dimension is flipped.

  Throws:
    `java.io.IOException`

### loadGIFFile

    public static int[][] loadGIFFile(java.io.InputStream str)
                               throws java.io.IOException

  Loads GIF files and returns the result as an int[][], where each integer value represents the color table index of the pixel. The Y dimension is not flipped.

  Throws:
    `java.io.IOException`

### loadPNGFile

    public static int[][] loadPNGFile(java.io.InputStream str,
                                      boolean flipY)
                               throws java.io.IOException

  Loads PNG files and returns the result as an int[][]. The only PNG formats permitted are those with up to 256 grays (including simple black and white) or indexed colors from an up to 256-sized color table. Each integer value represents the gray level or the color table index value of the pixel. flipY is true, then the Y dimension is flipped.

  Throws:
    `java.io.IOException`

### loadPNGFile

    public static int[][] loadPNGFile(java.io.InputStream str)
                               throws java.io.IOException

  Loads PNG files and returns the result as an int[][]. The only PNG formats permitted are those with up to 256 grays (including simple black and white) or indexed colors from an up to 256-sized color table. Each integer value represents the gray level or the color table index value of the pixel. The Y dimension is not flipped.

  Throws:
    `java.io.IOException`

### convertToIntArray

    public static int[][] convertToIntArray(double[][] vals)

  Converts a double[][] array to an int[][] array only if all values are within the int range. If not, returns null.

### convertToDoubleArray

    public static double[][] convertToDoubleArray(int[][] vals)

  Converts an int[][] array to a double[][] array.

### convertToLongArray

    public static long[][] convertToLongArray(double[][] vals)

  Converts a double[][] array to a long[][] array only if all values are within the long range. If not, returns null.

### convertToLongArray

    public static long[][] convertToLongArray(int[][] vals)

  Converts an int[][] array to a long[][] array.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD