Package org.esa.snap.core.util.math
Class LookupTable
java.lang.Object
org.esa.snap.core.util.math.LookupTable
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 Summary
ConstructorsConstructorDescriptionLookupTable(double[] values, double[]... dimensions) Constructs a lookup table for the lookup values and dimensions supplied as arguments.LookupTable(double[] values, IntervalPartition... dimensions) Constructs a lookup table for the lookup values and dimensions supplied as arguments.LookupTable(float[] values, float[]... dimensions) Constructs a lookup table for the lookup values and dimensions supplied as arguments.LookupTable(float[] values, IntervalPartition... dimensions) Constructs a lookup table for the lookup values and dimensions supplied as arguments. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcomputeFracIndex(IntervalPartition partition, double coordinate, FracIndex fracIndex) Computes theFracIndexof a coordinate value with respect to a given interval partition.final double[][]get2DValuesArray(FracIndex[] fracIndexes) Returns a matrix of interpolated values for the given fractional indices.final IntervalPartitiongetDimension(int i) Returns the the ith dimension associated with the lookup table.final intReturns the number of dimensions associated with the lookup table.final IntervalPartition[]Returns the dimensions associated with the lookup table.protected int[]protected int[]final doublegetValue(double... coordinates) Returns an interpolated value for the given coordinates.final doubleReturns an interpolated value for the given coordinates.final doubleReturns an interpolated value for the given fractional indices.protected Arrayfinal double[]Returns an array of interpolated values for the given fractional indices.
-
Constructor Details
-
LookupTable
Constructs a lookup table for the lookup values and dimensions supplied as arguments.- Parameters:
values- the lookup values. Thevaluesarray 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, seeIntervalPartition.- Throws:
IllegalArgumentException- if the length of thevaluesarray is not equal to the number of coordinate grid vertices.NullPointerException- if thevaluesarray or thedimensionsarray isnullor any dimension isnull.
-
LookupTable
Constructs a lookup table for the lookup values and dimensions supplied as arguments.- Parameters:
values- the lookup values. Thevaluesarray 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, seeIntervalPartition.- Throws:
IllegalArgumentException- if the length of thevaluesarray is not equal to the number of coordinate grid vertices.NullPointerException- if thevaluesarray or thedimensionsarray isnullor any dimension isnull.
-
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. Thevaluesarray 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, seeIntervalPartition.- Throws:
IllegalArgumentException- if the length of thevaluesarray is is not equal to the number of coordinate grid vertices or any dimension is not an interval partion.NullPointerException- if thevaluesarray or thedimensionsarray isnullor any dimension isnull.
-
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. Thevaluesarray 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, seeIntervalPartition.- Throws:
IllegalArgumentException- if the length of thevaluesarray is is not equal to the number of coordinate grid vertices or any dimension is not an interval partion.NullPointerException- if thevaluesarray or thedimensionsarray isnullor any dimension isnull.
-
-
Method Details
-
getDimensionCount
public final int getDimensionCount()Returns the number of dimensions associated with the lookup table.- Returns:
- the number of dimensions.
-
getDimensions
Returns the dimensions associated with the lookup table.- Returns:
- the dimensions.
-
getStrides
protected int[] getStrides() -
getOffsets
protected int[] getOffsets() -
getValues
-
getDimension
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 thecoordinatesarray is not equal to the number of dimensions associated with the lookup table.NullPointerException- if thecoordinatesarray isnull.
-
getValue
public final double getValue(double[] coordinates, FracIndex[] fracIndexes, double[] v) throws IllegalArgumentException, IndexOutOfBoundsException, NullPointerException Returns an interpolated value for the given coordinates.- Parameters:
coordinates- the coordinates of the lookup point.fracIndexes- workspace array of (at least) the same length ascoordinates.v- workspace array of (at least) length1 << coordinates.length.- Returns:
- the interpolated value.
- Throws:
ArrayIndexOutOfBoundsException- if thefracIndexesandvarrays do not have proper length.IllegalArgumentException- if the length of thecoordinatesarray is not equal to the number of dimensions associated with the lookup table.NullPointerException- if any parameter isnullor exhibits any element, which isnull.IndexOutOfBoundsException
-
getValue
Returns an interpolated value for the given fractional indices.- Parameters:
fracIndexes- workspace array of (at least) the same length ascoordinates.v- workspace array of (at least) length1 << coordinates.length.- Returns:
- the interpolated value.
- Throws:
ArrayIndexOutOfBoundsException- if thefracIndexesandvarrays do not have proper length.IllegalArgumentException- if the length of thecoordinatesarray is not equal to the number of dimensions associated with the lookup table.NullPointerException- if any parameter isnullor exhibits any element, which isnull.
-
getValues
Returns an array of interpolated values for the given fractional indices.- Parameters:
fracIndexes- workspace array of lengthcoordinates - 1.- Returns:
- the interpolated values.
- Throws:
ArrayIndexOutOfBoundsException- if thefracIndexesandvarrays do not have proper length.IllegalArgumentException- if the length of thecoordinatesarray is not exactly one less than the number of dimensions associated with the lookup table.NullPointerException- iffracIndexesisnullor exhibits any element, which isnull.
-
get2DValuesArray
Returns a matrix of interpolated values for the given fractional indices.- Parameters:
fracIndexes- workspace array of lengthcoordinates - 2.- Returns:
- the interpolated values.
- Throws:
ArrayIndexOutOfBoundsException- if thefracIndexesandvarrays do not have proper length.IllegalArgumentException- if the length of thecoordinatesarray is not exactly two less than the number of dimensions associated with the lookup table.NullPointerException- iffracIndexesisnullor exhibits any element, which isnull.
-
computeFracIndex
public static void computeFracIndex(IntervalPartition partition, double coordinate, FracIndex fracIndex) Computes theFracIndexof a coordinate value with respect to a given interval partition. The integral component of the returnedFracIndexcorresponds 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
FracIndexis 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 returnedFracIndexis the same as if the coordinate. value was equal to the partition minimum (maximum).fracIndex- theFracIndex.
-