Changed code to use true Linear Interpolation rather than even cell distance distribution

This commit is contained in:
vimsh 2014-10-12 17:31:24 -04:00 committed by Scotthew
parent bd39e419bf
commit 8aeb766fc4
3 changed files with 73 additions and 60 deletions

View File

@ -1143,35 +1143,19 @@ public abstract class Table extends JPanel implements Serializable {
}
public void verticalInterpolate() {
horizontalInterpolate();
}
public void horizontalInterpolate() {
int[] coords = { getDataSize(), 0};
DataCell[] tableData = getData();
int y;
for (y = 0; y < getDataSize(); y++) {
if (tableData[y].isSelected()) {
if (y < coords[0])
coords[0] = y;
if (y > coords[1])
coords[1] = y;
}
}
if (coords[1] - coords[0] > 1) {
double diff = (tableData[coords[0]].getRealValue() - tableData[coords[1]].getRealValue()) / (coords[1] - coords[0]);
if (Math.abs(diff) > 0) {
for (y = coords[0] + 1; y < coords[1]; y++)
data[y].setRealValue(String.valueOf(tableData[y - 1].getRealValue() - diff));
}
}
}
public void interpolate() {
horizontalInterpolate();
}
public double linearInterpolation(double x, double x1, double x2, double y1, double y2) {
return (x1 == x2) ? 0.0 : (y1 + (x - x1) * (y2 - y1) / (x2 - x1));
}
public void validateScaling() {
if (type != Settings.TABLE_SWITCH) {

View File

@ -317,7 +317,30 @@ public class Table2D extends Table {
@Override
public void horizontalInterpolate() {
super.horizontalInterpolate();
int[] coords = { getDataSize(), 0};
DataCell[] tableData = getData();
DataCell[] axisData = getAxis().getData();
for (int i = 0; i < getDataSize(); ++i) {
if (tableData[i].isSelected()) {
if (i < coords[0])
coords[0] = i;
if (i > coords[1])
coords[1] = i;
}
}
if (coords[1] - coords[0] > 1) {
double x, x1, x2, y1, y2;
x1 = axisData[coords[0]].getValue();
y1 = tableData[coords[0]].getValue();
x2 = axisData[coords[1]].getValue();
y2 = tableData[coords[1]].getValue();
for (int i = coords[0] + 1; i < coords[1]; ++i) {
x = axisData[i].getValue();
data[i].setRealValue(String.valueOf(linearInterpolation(x, x1, x2, y1, y2)));
}
}
// Interpolate x axis in case the x axis in selected.
this.getAxis().horizontalInterpolate();
}

View File

@ -784,29 +784,32 @@ public class Table3D extends Table {
public void verticalInterpolate() {
int[] coords = { getSizeX(), getSizeY(), 0, 0};
DataCell[][] tableData = get3dData();
int x, y;
for (x = 0; x < getSizeX(); x++) {
for (y = 0; y < getSizeY(); y++) {
if (tableData[x][y].isSelected()) {
if (x < coords[0])
coords[0] = x;
if (x > coords[2])
coords[2] = x;
if (y < coords[1])
coords[1] = y;
if (y > coords[3])
coords[3] = y;
DataCell[] axisData = getYAxis().getData();
int i, j;
for (i = 0; i < getSizeX(); ++i) {
for (j = 0; j < getSizeY(); ++j) {
if (tableData[i][j].isSelected()) {
if (i < coords[0])
coords[0] = i;
if (i > coords[2])
coords[2] = i;
if (j < coords[1])
coords[1] = j;
if (j > coords[3])
coords[3] = j;
}
}
}
if (coords[3] - coords[1] > 1) {
double diff;
for (y = coords[0]; y <= coords[2]; y++) {
diff = (tableData[y][coords[1]].getRealValue() - tableData[y][coords[3]].getRealValue()) / (coords[3] - coords[1]);
if (Math.abs(diff) > 0) {
for (x = coords[1] + 1; x < coords[3]; x++)
tableData[y][x].setRealValue(String.valueOf(tableData[y][x - 1].getRealValue() - diff));
double x, x1, x2, y1, y2;
x1 = axisData[coords[1]].getValue();
x2 = axisData[coords[3]].getValue();
for (i = coords[0]; i <= coords[2]; ++i) {
y1 = tableData[i][coords[1]].getValue();
y2 = tableData[i][coords[3]].getValue();
for (j = coords[1] + 1; j < coords[3]; ++j) {
x = axisData[j].getValue();
tableData[i][j].setRealValue(String.valueOf(linearInterpolation(x, x1, x2, y1, y2)));
}
}
}
@ -818,30 +821,33 @@ public class Table3D extends Table {
public void horizontalInterpolate() {
int[] coords = { getSizeX(), getSizeY(), 0, 0 };
DataCell[][] tableData = get3dData();
int x, y;
for (x = 0; x < getSizeX(); x++) {
for (y = 0; y < getSizeY(); y++) {
if (tableData[x][y].isSelected()) {
if (x < coords[0])
coords[0] = x;
if (x > coords[2])
coords[2] = x;
if (y < coords[1])
coords[1] = y;
if (y > coords[3])
coords[3] = y;
DataCell[] axisData = getXAxis().getData();
int i, j;
for (i = 0; i < getSizeX(); ++i) {
for (j = 0; j < getSizeY(); ++j) {
if (tableData[i][j].isSelected()) {
if (i < coords[0])
coords[0] = i;
if (i > coords[2])
coords[2] = i;
if (j < coords[1])
coords[1] = j;
if (j > coords[3])
coords[3] = j;
}
}
}
if (coords[2] - coords[0] > 1) {
double diff;
for (x = coords[1]; x <= coords[3]; x++) {
diff = (tableData[coords[0]][x].getRealValue() - tableData[coords[2]][x].getRealValue()) / (coords[2] - coords[0]);
if (Math.abs(diff) > 0) {
for (y = coords[0] + 1; y < coords[2]; y++)
tableData[y][x].setRealValue(String.valueOf(tableData[y - 1][x].getRealValue() - diff));
}
double x, x1, x2, y1, y2;
x1 = axisData[coords[0]].getValue();
x2 = axisData[coords[2]].getValue();
for (i = coords[1]; i <= coords[3]; ++i) {
y1 = tableData[coords[0]][i].getValue();
y2 = tableData[coords[2]][i].getValue();
for (j = coords[0] + 1; j < coords[2]; ++j) {
x = axisData[i].getValue();
tableData[j][i].setRealValue(String.valueOf(linearInterpolation(x, x1, x2, y1, y2)));
}
}
}
// Interpolate x axis in case the x axis in selected.