Skip to content
Snippets Groups Projects
Commit f91ffb08 authored by Luc Maisonobe's avatar Luc Maisonobe
Browse files

Use the four corners of each pixel to initialize min/max kd-tree.

parent 0f831bc3
No related branches found
No related tags found
No related merge requests found
......@@ -106,11 +106,15 @@ public class MinMaxTreeTile extends SimpleTile {
// compute min/max trees
if (start.length > 0) {
// TODO: we need to pre-process pixels so the min/max of *interpolation* is used
// now, we consider a single corner in each pixel, but all four corners
// contributes to the min/max at interpolation stage
applyRecursively(minTree, start.length - 1, nbRows, nbCols, new Min(), elevations, 0);
applyRecursively(maxTree, start.length - 1, nbRows, nbCols, new Max(), elevations, 0);
final double[] preprocessed = new double[elevations.length];
preprocess(preprocessed, elevations, nbRows, nbCols, new Min());
applyRecursively(minTree, start.length - 1, nbRows, nbCols, new Min(), preprocessed, 0);
preprocess(preprocessed, elevations, nbRows, nbCols, new Max());
applyRecursively(maxTree, start.length - 1, nbRows, nbCols, new Max(), preprocessed, 0);
}
}
......@@ -357,8 +361,50 @@ public class MinMaxTreeTile extends SimpleTile {
}
/** Preprocess recursive application of a function.
* <p>
* At start, the min/max should be computed for each pixel using the four corners values.
* </p>
* @param preprocessed preprocessed array to fill up
* @param elevations raw elevations te preprocess
* @param nbRows number of rows
* @param nbCols number of columns
* @param f function to apply
*/
private void preprocess(final double[] preprocessed, final double[] elevations,
final int nbRows, final int nbCols,
final BivariateFunction f) {
int k = 0;
for (int i = 0; i < nbRows - 1; ++i) {
// regular elements with both a column at right and a row below
for (int j = 0; j < nbCols - 1; ++j) {
preprocessed[k] = f.value(f.value(elevations[k], elevations[k + 1]),
f.value(elevations[k + nbCols], elevations[k + nbCols + 1]));
k++;
}
// last column elements, lacking a right column
preprocessed[k] = f.value(elevations[k], elevations[k + nbCols]);
k++;
}
// last row elements, lacking a below row
for (int j = 0; j < nbCols - 1; ++j) {
preprocessed[k] = f.value(elevations[k], elevations[k + 1]);
k++;
}
// last element
preprocessed[k] = elevations[k];
}
/** Recursive application of a function.
* @param tree to fill-up with the recursive applications
* @param tree tree to fill-up with the recursive applications
* @param level current level
* @param levelRows number of rows at current level
* @param levelColumns number of columns at current level
......
......@@ -113,8 +113,8 @@ public class MinMaxTreeTileTest {
int[] neighbors = neighbors(row, column, nbRows, nbColumns, tile.getLevels() - level);
double min = Double.POSITIVE_INFINITY;
double max = Double.NEGATIVE_INFINITY;
for (int i = neighbors[0]; i < neighbors[1]; ++i) {
for (int j = neighbors[2]; j < neighbors[3]; ++j) {
for (int i = neighbors[0]; i < FastMath.min(neighbors[1] + 1, nbRows); ++i) {
for (int j = neighbors[2]; j < FastMath.min(neighbors[3] + 1, nbColumns); ++j) {
double pixelValue = tile.getElevationAtIndices(i, j);
min = FastMath.min(min, pixelValue);
max = FastMath.max(max, pixelValue);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment