Commit 14a6236b authored by rink's avatar rink
Browse files

Option for linear or cubic time interpolation for trajectory.

parent 0dcad647
......@@ -32,12 +32,14 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import visad.util.CubicInterpolator;
import visad.util.LinearInterpolator;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
import visad.data.text.TextAdapter;
import visad.util.Interpolator;
/**
......@@ -112,9 +114,9 @@ public class TrajectoryManager {
float[] intrpU_2;
float[] intrpV_2;
float[] intrpW_2;
CubicInterpolator uInterp;
CubicInterpolator vInterp;
CubicInterpolator wInterp;
Interpolator uInterp;
Interpolator vInterp;
Interpolator wInterp;
float[][] values0;
float[][] values1;
float[][] values2;
......@@ -272,10 +274,17 @@ public class TrajectoryManager {
intrpW_2 = new float[numSpatialPts];
}
uInterp = new CubicInterpolator(trajDoIntrp, numSpatialPts);
vInterp = new CubicInterpolator(trajDoIntrp, numSpatialPts);
wInterp = new CubicInterpolator(trajDoIntrp, numSpatialPts);
if (trajParams.getInterpolationMethod() == TrajectoryParams.InterpolationMethod.Cubic) {
uInterp = new CubicInterpolator(trajDoIntrp, numSpatialPts);
vInterp = new CubicInterpolator(trajDoIntrp, numSpatialPts);
wInterp = new CubicInterpolator(trajDoIntrp, numSpatialPts);
}
else if (trajParams.getInterpolationMethod() == TrajectoryParams.InterpolationMethod.Linear) {
uInterp = new LinearInterpolator(trajDoIntrp, numSpatialPts);
vInterp = new LinearInterpolator(trajDoIntrp, numSpatialPts);
wInterp = new LinearInterpolator(trajDoIntrp, numSpatialPts);
}
values0 = null;
values1 = null;
values2 = null;
......@@ -2438,7 +2447,18 @@ public class TrajectoryManager {
else if (propStr.equals("EULER")) {
trajParams.setMethod(TrajectoryParams.Method.Euler);
}
}
}
propStr = prop.getProperty("InterpMethod");
if (propStr != null) {
propStr = propStr.trim();
if (propStr.equals("CUBIC")) {
trajParams.setInterpolationMethod(TrajectoryParams.InterpolationMethod.Cubic);
}
else if (propStr.equals("LINEAR")) {
trajParams.setInterpolationMethod(TrajectoryParams.InterpolationMethod.Linear);
}
}
is.close();
}
......
......@@ -54,6 +54,11 @@ public class TrajectoryParams {
Euler;
}
public static enum InterpolationMethod {
Cubic,
Linear;
}
public static final int LINE = 0;
public static final int RIBBON = 1;
public static final int CYLINDER = 2;
......@@ -89,6 +94,7 @@ public class TrajectoryParams {
FlatField terrain = null;
Method method = Method.HySplit; //Default
InterpolationMethod interpMethod = InterpolationMethod.Cubic;
public TrajectoryParams() {
}
......@@ -117,6 +123,7 @@ public class TrajectoryParams {
this.terrain = params.getTerrain();
this.terrainFollowEnabled = params.getTerrainFollowing();
this.method = params.getMethod();
this.interpMethod = params.getInterpolationMethod();
}
public TrajectoryParams(double trajVisibilityTimeWindow, double trajRefreshInterval, int numIntrpPts, int startSkip, SmoothParams smoothParams) {
......@@ -224,6 +231,10 @@ public class TrajectoryParams {
this.method = method;
}
public void setInterpolationMethod(InterpolationMethod m) {
this.interpMethod = m;
}
public void setCachingEnabled(boolean yesno) {
this.cachingEnabled = yesno;
}
......@@ -308,6 +319,10 @@ public class TrajectoryParams {
return method;
}
public InterpolationMethod getInterpolationMethod() {
return interpMethod;
}
public void setStartPoints(float[][] startPts) {
this.startPoints = startPts;
this.startType = Display.DisplaySpatialCartesianTuple;
......
......@@ -4,7 +4,7 @@ import Jama.Matrix;
import Jama.LUDecomposition;
import java.util.Arrays;
public class CubicInterpolator {
public class CubicInterpolator implements Interpolator {
private LUDecomposition solver;
......
package visad.util;
public interface Interpolator {
void interpolate(double xt, float[] interpValues);
void next(double x0, double x1, double x2, float[] values0, float[] values1, float[] values2);
void update(boolean[] needed);
}
package visad.util;
import java.util.Arrays;
public class LinearInterpolator implements Interpolator {
private double[][] solution = null;
private double x0 = 0;
private double x1 = 0;
private double x2 = 0;
private double x0_last = 0;
private double x0_save;
private float[] values0 = null;
private float[] values1 = null;
private float[] values2 = null;
private float[] values0_last = null;
private float[] values0_save = null;
private int numSpatialPts = 1;
private boolean doIntrp = true;
private boolean[] needed = null;
private boolean[] computed = null;
public LinearInterpolator(boolean doIntrp, int numSpatialPts) {
this.doIntrp = doIntrp;
this.numSpatialPts = numSpatialPts;
this.solution = new double[4][numSpatialPts];
this.needed = new boolean[numSpatialPts];
this.computed = new boolean[numSpatialPts];
Arrays.fill(needed, false);
Arrays.fill(computed, false);
}
@Override
public void interpolate(double xt, float[] interpValues) {
if (!doIntrp) {
if (xt == x0) {
System.arraycopy(values0, 0, interpValues, 0, numSpatialPts);
}
else if (xt == x1) {
System.arraycopy(values1, 0, interpValues, 0, numSpatialPts);
}
else if (xt == x2) {
System.arraycopy(values2, 0, interpValues, 0, numSpatialPts);
}
return;
}
java.util.Arrays.fill(interpValues, Float.NaN);
for (int k=0; k<numSpatialPts; k++) {
if (!computed[k]) { // don't need to interp at these locations, at this time
continue;
}
interpValues[k] = (float) (solution[0][k]*xt + solution[1][k]);
}
}
@Override
public void next(double x0, double x1, double x2, float[] values0, float[] values1, float[] values2) {
this.x0 = x0;
this.x1 = x1;
this.x2 = x2;
this.values0 = values0;
this.values1 = values1;
this.values2 = values2;
this.x0_last = x0_save;
this.x0_save = x0;
this.values0_last = values0_save;
this.values0_save = values0;
Arrays.fill(computed, false);
if (!doIntrp) {
return;
}
}
@Override
public void update(boolean[] needed) {
java.util.Arrays.fill(this.needed, false);
for (int k=0; k<numSpatialPts; k++) {
if (needed[k]) {
if (!computed[k]) {
this.needed[k] = true;
}
}
}
if (doIntrp) {
getSolution();
}
}
private void getSolution() {
for (int k=0; k<numSpatialPts; k++) {
if (!this.needed[k]) {
continue;
}
double D1_1 = Double.NaN;
double D1_0 = Double.NaN;
double y0 = values0[k];
double y1 = values1[k];
solution[0][k] = (y1 - y0)/(x1 - x0);
solution[1][k] = y0 - solution[0][k]*x0;
computed[k] = true;
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment