public static double getInterpolatedValue(int[,] array, InterpolationChoice type, double x, double y) { int x1, y1; x1 = (int)Math.Floor(x); y1 = (int)Math.Floor(y); double z11 = getClampedCoord(array, x1, y1); double z12 = getClampedCoord(array, x1, y1 + 1); double z21 = getClampedCoord(array, x1 + 1, y1); double z22 = getClampedCoord(array, x1 + 1, y1 + 1); double z00 = getClampedCoord(array, x1 - 1, y1 - 1); double z01 = getClampedCoord(array, x1 - 1, y1); double z02 = getClampedCoord(array, x1 - 1, y1 + 1); double z03 = getClampedCoord(array, x1 - 1, y1 + 2); double z10 = getClampedCoord(array, x1, y1 - 1); double z13 = getClampedCoord(array, x1, y1 + 2); double z20 = getClampedCoord(array, x1 + 1, y1 - 1); double z23 = getClampedCoord(array, x1 + 1, y1 + 2); double z30 = getClampedCoord(array, x1 + 2, y1 - 1); double z31 = getClampedCoord(array, x1 + 2, y1); double z32 = getClampedCoord(array, x1 + 2, y1 + 1); double z33 = getClampedCoord(array, x1 + 2, y1 + 2); double muy = x - x1; double mux = y - y1; //flat land sometimes gives trouble, so a slight increase can help that. double roundingCorrection = 0.5; switch (type) { case InterpolationChoice.linear: return(Interpolate.BiLinearInterpolate(z11, z12, z21, z22, mux, muy) + roundingCorrection); case InterpolationChoice.cosine: return(Interpolate.BiCosineInterpolate(z11, z12, z21, z22, mux, muy) + roundingCorrection); case InterpolationChoice.cubic: return(Interpolate.BiCubicInterpolate(z00, z01, z02, z03, z10, z11, z12, z13, z20, z21, z22, z23, z30, z31, z32, z33, mux, muy) + roundingCorrection); case InterpolationChoice.catmulRom: return(Interpolate.BiCatmullRomInterpolate(z00, z01, z02, z03, z10, z11, z12, z13, z20, z21, z22, z23, z30, z31, z32, z33, mux, muy) + roundingCorrection); case InterpolationChoice.hermite: return(Interpolate.BiHermiteInterpolate(z00, z01, z02, z03, z10, z11, z12, z13, z20, z21, z22, z23, z30, z31, z32, z33, mux, muy, 0.75) + roundingCorrection); case InterpolationChoice.fritschCarlson: return(Interpolate.BiFritschCarlsonInterpolate(z00, z01, z02, z03, z10, z11, z12, z13, z20, z21, z22, z23, z30, z31, z32, z33, mux, muy) + roundingCorrection); } return(-1.0); }
public static double getInterpolatedValue(int[,] array, InterpolationChoice type, double x, double y) { int x1, y1; x1 = (int)Math.Floor(x); y1 = (int)Math.Floor(y); double z11 = getClampedCoord(array, x1, y1); double z12 = getClampedCoord(array, x1, y1 + 1); double z21 = getClampedCoord(array, x1 + 1, y1); double z22 = getClampedCoord(array, x1 + 1, y1 + 1); double z00 = getClampedCoord(array, x1 - 1, y1 - 1); double z01 = getClampedCoord(array, x1 - 1, y1); double z02 = getClampedCoord(array, x1 - 1, y1 + 1); double z03 = getClampedCoord(array, x1 - 1, y1 + 2); double z10 = getClampedCoord(array, x1, y1 - 1); double z13 = getClampedCoord(array, x1, y1 + 2); double z20 = getClampedCoord(array, x1 + 1, y1 - 1); double z23 = getClampedCoord(array, x1 + 1, y1 + 2); double z30 = getClampedCoord(array, x1 + 2, y1 - 1); double z31 = getClampedCoord(array, x1 + 2, y1); double z32 = getClampedCoord(array, x1 + 2, y1 + 1); double z33 = getClampedCoord(array, x1 + 2, y1 + 2); double muy = x - x1; double mux = y - y1; //flat land sometimes gives trouble, so a slight increase can help that. double roundingCorrection = 0.5; switch (type) { case InterpolationChoice.linear: return Interpolate.BiLinearInterpolate(z11, z12, z21, z22, mux, muy) + roundingCorrection; case InterpolationChoice.cosine: return Interpolate.BiCosineInterpolate(z11, z12, z21, z22, mux, muy) + roundingCorrection; case InterpolationChoice.cubic: return Interpolate.BiCubicInterpolate(z00, z01, z02, z03, z10, z11, z12, z13, z20, z21, z22, z23, z30, z31, z32, z33, mux, muy) + roundingCorrection; case InterpolationChoice.catmulRom: return Interpolate.BiCatmullRomInterpolate(z00, z01, z02, z03, z10, z11, z12, z13, z20, z21, z22, z23, z30, z31, z32, z33, mux, muy) + roundingCorrection; case InterpolationChoice.hermite: return Interpolate.BiHermiteInterpolate(z00, z01, z02, z03, z10, z11, z12, z13, z20, z21, z22, z23, z30, z31, z32, z33, mux, muy, 0.75) + roundingCorrection; case InterpolationChoice.fritschCarlson: return Interpolate.BiFritschCarlsonInterpolate(z00, z01, z02, z03, z10, z11, z12, z13, z20, z21, z22, z23, z30, z31, z32, z33, mux, muy) + roundingCorrection; } return -1.0; }