/** * Returns an interpolated value for the given coordinates. * * @param coordinates the coordinates of the lookup point. * * @return the interpolated value. * * @throws IllegalArgumentException if the length of the {@code coordinates} array is * not equal to the number of dimensions associated * with the lookup table. * @throws NullPointerException if the {@code coordinates} array is {@code null}. */ public final double getValue(final double... coordinates) throws IllegalArgumentException, NullPointerException { return getValue(coordinates, FracIndex.createArray(coordinates.length), new double[1 << coordinates.length]); }
/** * Returns an interpolated value for the given coordinates. * * @param coordinates the coordinates of the lookup point. * @param fracIndexes workspace array of (at least) the same length as {@code coordinates}. * @param v workspace array of (at least) length {@code 1 << coordinates.length}. * * @return the interpolated value. * * @throws ArrayIndexOutOfBoundsException if the {@code fracIndexes} and {@code v} arrays * do not have proper length. * @throws IllegalArgumentException if the length of the {@code coordinates} array is * not equal to the number of dimensions associated * with the lookup table. * @throws NullPointerException if any parameter is {@code null} or exhibits any * element, which is {@code null}. */ public final double getValue(final double[] coordinates, final FracIndex[] fracIndexes, final double[] v) throws IllegalArgumentException, IndexOutOfBoundsException, NullPointerException { ensureLegalArray(coordinates, dimensions.length); for (int i = 0; i < dimensions.length; ++i) { computeFracIndex(dimensions[i], coordinates[i], fracIndexes[i]); } return getValue(fracIndexes, v); }
public void testInterpolation2D() { final double[][] dimensions = new double[][]{{0, 1}, {0, 1}}; final double[] values = new double[]{0, 1, 2, 3}; final LookupTable lut = new LookupTable(values, dimensions); assertEquals(2, lut.getDimensionCount()); assertEquals(0.0, lut.getDimension(0).getMin(), 0.0); assertEquals(1.0, lut.getDimension(0).getMax(), 0.0); assertEquals(0.0, lut.getDimension(1).getMin(), 0.0); assertEquals(1.0, lut.getDimension(1).getMax(), 0.0); assertEquals(0.0, lut.getValue(0.0, 0.0), 0.0); assertEquals(1.0, lut.getValue(0.0, 1.0), 0.0); assertEquals(2.0, lut.getValue(1.0, 0.0), 0.0); assertEquals(3.0, lut.getValue(1.0, 1.0), 0.0); assertEquals(0.5, lut.getValue(0.0, 0.5), 0.0); assertEquals(1.5, lut.getValue(0.5, 0.5), 0.0); assertEquals(2.5, lut.getValue(1.0, 0.5), 0.0); }
public void testInterpolation1D() { final double[] dimension = new double[]{0, 1}; final double[] values = new double[]{0, 1}; final LookupTable lut = new LookupTable(values, dimension); assertEquals(1, lut.getDimensionCount()); assertEquals(0.0, lut.getDimension(0).getMin(), 0.0); assertEquals(1.0, lut.getDimension(0).getMax(), 0.0); assertEquals(0.0, lut.getValue(0.0), 0.0); assertEquals(1.0, lut.getValue(1.0), 0.0); assertEquals(0.5, lut.getValue(0.5), 0.0); }