Class InverseDistanceWeightingInterpolator
- java.lang.Object
-
- org.tinfour.interpolation.InverseDistanceWeightingInterpolator
-
- All Implemented Interfaces:
IProcessUsingTin,IInterpolatorOverTin
public class InverseDistanceWeightingInterpolator extends Object implements IInterpolatorOverTin
Provides interpolation based on the classic method of inverse distance weighting (IDW).This class is intended primarily for diagnostic purposes and does not implement a comprehensive set of options in support of the inverse distance-weighting concept.
-
-
Constructor Summary
Constructors Constructor Description InverseDistanceWeightingInterpolator(IIncrementalTin tin)Construct an interpolator that operates on the specified TIN.InverseDistanceWeightingInterpolator(IIncrementalTin tin, double parameter, boolean gaussian)Constructs an interpolator using the specified method.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static doublecomputeAverageSampleSpacing(IIncrementalTin tin)Computes the average sample spacing.static doubleestimateNominalBandwidth(double pointSpacing)Estimates a nominal bandwidth for the Gaussian kernal method of interpolation using the mean length of the distances between samplesStringgetMethod()Gets a string describing the interpolation method that can be used for labeling graphs and printouts.double[]getSurfaceNormal()Not supported at this time.doubleinterpolate(double x, double y, IVertexValuator valuator)Perform inverse distance weighting interpolation.booleanisSurfaceNormalSupported()Indicates whether the interpolation class supports the computation of surface normals through the getUnitNormal() method.voidprintDiagnostics(PrintStream ps)Prints diagnostic information about sample sizes and spacing used for interpolationvoidresetForChangeToTin()Used by an application to reset the state data within the interpolator when the content of the TIN may have changed.StringtoString()
-
-
-
Constructor Detail
-
InverseDistanceWeightingInterpolator
public InverseDistanceWeightingInterpolator(IIncrementalTin tin)
Construct an interpolator that operates on the specified TIN. Because the interpolator will access the TIN on a read-only basis, it is possible to construct multiple instances of this class and allow them to operate in parallel threads.Important Synchronization Issue
To improve performance, the classes in this package frequently maintain state-data about the TIN that can be reused for query to query. They also avoid run-time overhead by not implementing any kind of Java synchronization or or even the concurrent-modification testing provided by the Java collection classes. If an application modifies the TIN, instances of this class will not be aware of the change. In such cases, interpolation methods may fail by either throwing an exception or, worse, returning an incorrect value. The onus is on the calling application to manage the use of this class and to ensure that no modifications are made to the TIN between interpolation operations. If the TIN is modified, the internal state data for this class must be reset using a call to resetForChangeToTIN().
This constructor creates an interpolator based on Shepard's classic weight = 1/(d^2) formula.
- Parameters:
tin- a valid instance of an incremental TIN.
-
InverseDistanceWeightingInterpolator
public InverseDistanceWeightingInterpolator(IIncrementalTin tin, double parameter, boolean gaussian)
Constructs an interpolator using the specified method.Gaussian Kernel: If the Gaussian Kernel option is specified, the parameter will be interpreted as the bandwidth (lambda) for the formula weight = exp(-(1/2)(d/lambda)).
Power formula: If the Gaussian Kernel options is not specified, the parameter will be interpreted as a power for the formula weight = 1/pow(d, power);
- Parameters:
tin- a valid TINparameter- a parameter specifying either bandwidth (for Gaussian) or power. In both cases the parameter must be greater than zero.gaussian- true if the Gaussian kernel is to be used; otherwise the non-Gaussian method (power) will be used
-
-
Method Detail
-
resetForChangeToTin
public void resetForChangeToTin()
Used by an application to reset the state data within the interpolator when the content of the TIN may have changed. Resetting the state data unnecessarily may result in a performance reduction when processing a large number of interpolations, but is otherwise harmless.- Specified by:
resetForChangeToTinin interfaceIProcessUsingTin
-
interpolate
public double interpolate(double x, double y, IVertexValuator valuator)Perform inverse distance weighting interpolation.This interpolation is not defined beyond the convex hull of the TIN and this method will produce a Double.NaN if the specified coordinates are exterior to the TIN.
- Specified by:
interpolatein interfaceIInterpolatorOverTin- Parameters:
x- the x coordinate for the interpolation pointy- the y coordinate for the interpolation pointvaluator- a valid valuator for interpreting the z value of each vertex or a null value to use the default.- Returns:
- if the interpolation is successful, a valid floating point value; otherwise, a NaN.
-
isSurfaceNormalSupported
public boolean isSurfaceNormalSupported()
Description copied from interface:IInterpolatorOverTinIndicates whether the interpolation class supports the computation of surface normals through the getUnitNormal() method.- Specified by:
isSurfaceNormalSupportedin interfaceIInterpolatorOverTin- Returns:
- true if the class implements the ability to compute surface normals; otherwise, false.
-
getSurfaceNormal
public double[] getSurfaceNormal()
Not supported at this time.- Specified by:
getSurfaceNormalin interfaceIInterpolatorOverTin- Returns:
- a zero-sized array.
-
getMethod
public String getMethod()
Description copied from interface:IInterpolatorOverTinGets a string describing the interpolation method that can be used for labeling graphs and printouts. Because this string may be used as a column header in a table, its length should be kept short.- Specified by:
getMethodin interfaceIInterpolatorOverTin- Returns:
- A valid string
-
estimateNominalBandwidth
public static double estimateNominalBandwidth(double pointSpacing)
Estimates a nominal bandwidth for the Gaussian kernal method of interpolation using the mean length of the distances between samples- Parameters:
pointSpacing- a positive value- Returns:
- if successful, a positive value; otherwise, Double.NaN
-
computeAverageSampleSpacing
public static double computeAverageSampleSpacing(IIncrementalTin tin)
Computes the average sample spacing.In many cases, the sample spacing of the perimeter edges of a TIN is much larger than the mean sample spacing for the interior. So if the TIN contains more than 3 points, the perimeter edges are not included in the tabulation.
- Parameters:
tin- a valid instance- Returns:
- if the TIN is valid, a positive value; otherwise Double.NaN
-
printDiagnostics
public void printDiagnostics(PrintStream ps)
Prints diagnostic information about sample sizes and spacing used for interpolation- Parameters:
ps- a valid instance (such as System.out).
-
-