Class LookupTable


  • public class LookupTable
    extends Object
    The class LookupTable performs the function of multilinear interpolation for lookup tables with an arbitrary number of dimensions.

    todo - method for degrading a table (see C++ code below)

    • Constructor Detail

      • LookupTable

        public LookupTable​(double[] values,
                           IntervalPartition... dimensions)
        Constructs a lookup table for the lookup values and dimensions supplied as arguments.
        Parameters:
        values - the lookup values. The values array must be laid out in row-major order, so that the dimension associated with the last axis varies fastest.
        dimensions - the interval partitions defining the dimensions associated with the lookup table. An interval partition is a strictly increasing sequence of at least two real numbers, see IntervalPartition.
        Throws:
        IllegalArgumentException - if the length of the values array is not equal to the number of coordinate grid vertices.
        NullPointerException - if the values array or the dimensions array is null or any dimension is null.
      • LookupTable

        public LookupTable​(float[] values,
                           IntervalPartition... dimensions)
        Constructs a lookup table for the lookup values and dimensions supplied as arguments.
        Parameters:
        values - the lookup values. The values array must be laid out in row-major order, so that the dimension associated with the last axis varies fastest.
        dimensions - the interval partitions defining the dimensions associated with the lookup table. An interval partition is a strictly increasing sequence of at least two real numbers, see IntervalPartition.
        Throws:
        IllegalArgumentException - if the length of the values array is not equal to the number of coordinate grid vertices.
        NullPointerException - if the values array or the dimensions array is null or any dimension is null.
      • LookupTable

        public LookupTable​(double[] values,
                           double[]... dimensions)
        Constructs a lookup table for the lookup values and dimensions supplied as arguments.
        Parameters:
        values - the lookup values. The values array must be laid out in row-major order, so that the dimension associated with the last axis varies fastest.
        dimensions - the interval partitions defining the dimensions associated with the lookup table. An interval partition is a strictly increasing sequence of at least two real numbers, see IntervalPartition.
        Throws:
        IllegalArgumentException - if the length of the values array is is not equal to the number of coordinate grid vertices or any dimension is not an interval partion.
        NullPointerException - if the values array or the dimensions array is null or any dimension is null.
      • LookupTable

        public LookupTable​(float[] values,
                           float[]... dimensions)
        Constructs a lookup table for the lookup values and dimensions supplied as arguments.
        Parameters:
        values - the lookup values. The values array must be laid out in row-major order, so that the dimension associated with the last axis varies fastest.
        dimensions - the interval partitions defining the dimensions associated with the lookup table. An interval partition is a strictly increasing sequence of at least two real numbers, see IntervalPartition.
        Throws:
        IllegalArgumentException - if the length of the values array is is not equal to the number of coordinate grid vertices or any dimension is not an interval partion.
        NullPointerException - if the values array or the dimensions array is null or any dimension is null.
    • Method Detail

      • getDimensionCount

        public final int getDimensionCount()
        Returns the number of dimensions associated with the lookup table.
        Returns:
        the number of dimensions.
      • getDimensions

        public final IntervalPartition[] getDimensions()
        Returns the dimensions associated with the lookup table.
        Returns:
        the dimensions.
      • getStrides

        protected int[] getStrides()
      • getOffsets

        protected int[] getOffsets()
      • getValues

        protected Array getValues()
      • getDimension

        public final IntervalPartition getDimension​(int i)
        Returns the the ith dimension associated with the lookup table.
        Parameters:
        i - the index number of the dimension of interest
        Returns:
        the ith dimension.
      • getValue

        public final double getValue​(double... coordinates)
                              throws IllegalArgumentException,
                                     NullPointerException
        Returns an interpolated value for the given coordinates.
        Parameters:
        coordinates - the coordinates of the lookup point.
        Returns:
        the interpolated value.
        Throws:
        IllegalArgumentException - if the length of the coordinates array is not equal to the number of dimensions associated with the lookup table.
        NullPointerException - if the coordinates array is null.
      • getValue

        public final double getValue​(FracIndex[] fracIndexes,
                                     double[] v)
        Returns an interpolated value for the given fractional indices.
        Parameters:
        fracIndexes - workspace array of (at least) the same length as coordinates.
        v - workspace array of (at least) length 1 << coordinates.length.
        Returns:
        the interpolated value.
        Throws:
        ArrayIndexOutOfBoundsException - if the fracIndexes and v arrays do not have proper length.
        IllegalArgumentException - if the length of the coordinates array is not equal to the number of dimensions associated with the lookup table.
        NullPointerException - if any parameter is null or exhibits any element, which is null.
      • getValues

        public final double[] getValues​(FracIndex[] fracIndexes)
        Returns an array of interpolated values for the given fractional indices.
        Parameters:
        fracIndexes - workspace array of length coordinates - 1.
        Returns:
        the interpolated values.
        Throws:
        ArrayIndexOutOfBoundsException - if the fracIndexes and v arrays do not have proper length.
        IllegalArgumentException - if the length of the coordinates array is not exactly one less than the number of dimensions associated with the lookup table.
        NullPointerException - if fracIndexes is null or exhibits any element, which is null.
      • get2DValuesArray

        public final double[][] get2DValuesArray​(FracIndex[] fracIndexes)
        Returns a matrix of interpolated values for the given fractional indices.
        Parameters:
        fracIndexes - workspace array of length coordinates - 2.
        Returns:
        the interpolated values.
        Throws:
        ArrayIndexOutOfBoundsException - if the fracIndexes and v arrays do not have proper length.
        IllegalArgumentException - if the length of the coordinates array is not exactly two less than the number of dimensions associated with the lookup table.
        NullPointerException - if fracIndexes is null or exhibits any element, which is null.
      • computeFracIndex

        public static void computeFracIndex​(IntervalPartition partition,
                                            double coordinate,
                                            FracIndex fracIndex)
        Computes the FracIndex of a coordinate value with respect to a given interval partition. The integral component of the returned FracIndex corresponds to the index of the maximum partition member which is less than or equal to the coordinate value. The [0, 1) fractional component describes the position of the coordinate value within its bracketing subinterval.

        Exception: If the given coordinate value is equal to the partition maximum, the fractional component of the returned FracIndex is equal to 1.0, and the integral component is set to the index of the next to last partition member.

        Parameters:
        partition - the interval partition.
        coordinate - the coordinate value. If the coordinate value is less (greater) than the minimum (maximum) of the given interval partition, the returned FracIndex is the same as if the coordinate. value was equal to the partition minimum (maximum).
        fracIndex - the FracIndex.