use of javax.media.jai.iterator.WritableRandomIter in project hortonmachine by TheHortonMachine.
the class OmsDrainDir method orlandiniD8LTD.
private void orlandiniD8LTD(int[] indexes, WritableRaster deviationsWR, BitMatrix analizedMatrix, WritableRaster pitWR, WritableRaster flowWR, WritableRaster tcaWR, WritableRaster dirWR, int nelev) {
/*
* it indicates the position of the triangle's vertexes
*/
// ncelle = 0;
RandomIter pitRandomIter = RandomIterFactory.create(pitWR, null);
RandomIter flowRandomIter = RandomIterFactory.create(flowWR, null);
WritableRandomIter tcaRandomIter = RandomIterFactory.createWritable(tcaWR, null);
WritableRandomIter deviationRandomIter = RandomIterFactory.createWritable(deviationsWR, null);
WritableRandomIter dirRandomIter = RandomIterFactory.createWritable(dirWR, null);
try {
int ncelle = 0;
pm.beginTask(msg.message("draindir.orlandiniltd"), rows * cols);
for (int i = rows * cols - 1; i >= 0; i--) {
if (pm.isCanceled()) {
return;
}
double count = indexes[i] - 1;
int row = (int) Math.floor(count / cols);
int col = (int) (count % cols);
if (!isNovalue(pitRandomIter.getSampleDouble(col, row, 0)) && !isNovalue(flowRandomIter.getSample(col, row, 0))) {
ncelle = ncelle + 1;
double[] maxSlopeData = calculateMaximumSlope(analizedMatrix, pitRandomIter, tcaRandomIter, col, row);
if (maxSlopeData[1] > 0) {
double dev1 = (xRes * Math.sin(maxSlopeData[2]));
double dev2 = (xRes * Math.sqrt(2.0) * Math.sin(PI / 4 - maxSlopeData[2]));
if (maxSlopeData[9] == 1) {
dev2 = -dev2;
} else {
dev1 = -dev1;
}
calculateDrainageArea(row, col, maxSlopeData, analizedMatrix, deviationRandomIter, pitRandomIter, tcaRandomIter, dirRandomIter, cols, rows);
double sumdev = maxSlopeData[6];
double sumdev1 = dev1 + pLambda * sumdev;
double sumdev2 = dev2 + pLambda * sumdev;
if (Math.abs(sumdev1) <= Math.abs(sumdev2) && (maxSlopeData[3] - maxSlopeData[4]) > 0.0) {
dirRandomIter.setSample(col, row, 0, (int) maxSlopeData[7]);
deviationRandomIter.setSample(col, row, 0, sumdev1);
} else if (Math.abs(sumdev1) > Math.abs(sumdev2) || (maxSlopeData[3] - maxSlopeData[5]) > 0.0) {
dirRandomIter.setSample(col, row, 0, (int) maxSlopeData[8]);
deviationRandomIter.setSample(col, row, 0, sumdev2);
} else {
break;
}
} else if (maxSlopeData[1] == 0) {
if (ncelle == nelev) {
/* sono all'uscita */
calculateDrainageArea(row, col, maxSlopeData, analizedMatrix, deviationRandomIter, pitRandomIter, tcaRandomIter, dirRandomIter, cols, rows);
dirRandomIter.setSample(col, row, 0, FlowNode.OUTLET);
deviationRandomIter.setSample(col, row, 0, pLambda * maxSlopeData[6]);
pm.done();
return;
} else {
calculateDrainageArea(row, col, maxSlopeData, analizedMatrix, deviationRandomIter, pitRandomIter, tcaRandomIter, dirRandomIter, cols, rows);
double sumdev = pLambda * maxSlopeData[6];
dirRandomIter.setSample(col, row, 0, flowRandomIter.getSample(col, row, 0));
int flow = dirRandomIter.getSample(col, row, 0);
int nr = row + order[flow][0];
int nc = col + order[flow][1];
while (analizedMatrix.isMarked(nc, nr)) {
tcaRandomIter.setSample(nc, nr, 0, (tcaRandomIter.getSample(nc, nr, 0) + tcaRandomIter.getSample(col, row, 0)));
flow = dirRandomIter.getSample(nc, nr, 0);
nr = nr + order[flow][0];
nc = nc + order[flow][1];
}
deviationRandomIter.setSample(col, row, 0, sumdev);
}
}
}
pm.worked(1);
}
pm.done();
} finally {
dirRandomIter.done();
pitRandomIter.done();
flowRandomIter.done();
deviationRandomIter.done();
tcaRandomIter.done();
}
}
use of javax.media.jai.iterator.WritableRandomIter in project hortonmachine by TheHortonMachine.
the class OmsDrainDir method orlandiniD8LAD.
private void orlandiniD8LAD(int[] indexes, WritableRaster deviationsWR, BitMatrix analizedMatrix, WritableRaster pitWR, WritableRaster flowWR, WritableRaster tcaWR, WritableRaster dirWR, int nelev) {
RandomIter pitRandomIter = RandomIterFactory.create(pitWR, null);
RandomIter flowRandomIter = RandomIterFactory.create(flowWR, null);
WritableRandomIter tcaRandomIter = RandomIterFactory.createWritable(tcaWR, null);
WritableRandomIter deviationRandomIter = RandomIterFactory.createWritable(deviationsWR, null);
WritableRandomIter dirRandomIter = RandomIterFactory.createWritable(dirWR, null);
try {
int ncelle = 0;
pm.beginTask(msg.message("draindir.orlandinilad"), rows * cols);
for (int i = rows * cols - 1; i >= 0; i--) {
if (pm.isCanceled()) {
return;
}
double count = indexes[i] - 1;
int row = (int) Math.floor(count / cols);
int col = (int) (count % cols);
try {
if (!isNovalue(pitRandomIter.getSampleDouble(col, row, 0)) && !isNovalue(flowRandomIter.getSample(col, row, 0))) {
ncelle = ncelle + 1;
double[] maxSlopeData = calculateMaximumSlope(analizedMatrix, pitRandomIter, tcaRandomIter, col, row);
if (maxSlopeData[1] > 0) {
double dev1 = maxSlopeData[2];
double dev2 = ((PI / 4) - maxSlopeData[2]);
if (maxSlopeData[9] == 1) {
dev2 = -dev2;
} else {
dev1 = -dev1;
}
calculateDrainageArea(row, col, maxSlopeData, analizedMatrix, deviationRandomIter, pitRandomIter, tcaRandomIter, dirRandomIter, i, i);
double sumdev = maxSlopeData[6];
double sumdev1 = dev1 + (pLambda * sumdev);
double sumdev2 = dev2 + (pLambda * sumdev);
if ((Math.abs(sumdev1) <= Math.abs(sumdev2)) && ((maxSlopeData[3] - maxSlopeData[4]) > 0.0)) {
dirRandomIter.setSample(col, row, 0, maxSlopeData[7]);
deviationRandomIter.setSample(col, row, 0, sumdev1);
} else if (Math.abs(sumdev1) > Math.abs(sumdev2) || (maxSlopeData[3] - maxSlopeData[5]) > 0.0) {
dirRandomIter.setSample(col, row, 0, maxSlopeData[8]);
deviationRandomIter.setSample(col, row, 0, sumdev2);
} else {
break;
}
} else if (maxSlopeData[1] == 0) {
if (ncelle == nelev) {
/* sono all'uscita */
calculateDrainageArea(row, col, maxSlopeData, analizedMatrix, deviationRandomIter, pitRandomIter, tcaRandomIter, dirRandomIter, cols, rows);
dirRandomIter.setSample(col, row, 0, FlowNode.OUTLET);
deviationRandomIter.setSample(col, row, 0, pLambda * maxSlopeData[6]);
pm.done();
return;
} else {
calculateDrainageArea(row, col, maxSlopeData, analizedMatrix, deviationRandomIter, pitRandomIter, tcaRandomIter, dirRandomIter, cols, rows);
double sumdev = pLambda * maxSlopeData[6];
dirRandomIter.setSample(col, row, 0, flowRandomIter.getSample(col, row, 0));
int flow = dirRandomIter.getSample(col, row, 0);
int nr = row + order[flow][0];
int nc = col + order[flow][1];
while (analizedMatrix.isMarked(nc, nr)) {
tcaRandomIter.setSample(nc, nr, 0, tcaRandomIter.getSample(nc, nr, 0) + tcaRandomIter.getSample(col, row, 0));
flow = dirRandomIter.getSample(nc, nr, 0);
nr = nr + order[(int) flow][0];
nc = nc + order[(int) flow][1];
}
deviationRandomIter.setSample(col, row, 0, sumdev);
}
}
}
} catch (Exception e) {
pm.errorMessage("Error in col: " + col + " row: " + row);
e.printStackTrace();
}
pm.worked(1);
}
pm.done();
} finally {
dirRandomIter.done();
pitRandomIter.done();
flowRandomIter.done();
deviationRandomIter.done();
tcaRandomIter.done();
}
}
use of javax.media.jai.iterator.WritableRandomIter in project hortonmachine by TheHortonMachine.
the class OmsDrainDir method newDirections.
/**
* The fixed network method allows you to assign a known channel network and
* to then correct the drainage directions.
*/
private void newDirections(WritableRaster pitWR, WritableRaster dirWR) {
int[][] odir = { { 0, 0, 0 }, { 0, 1, 1 }, { -1, 1, 2 }, { -1, 0, 3 }, { -1, -1, 4 }, { 0, -1, 5 }, { 1, -1, 6 }, { 1, 0, 7 }, { 1, 1, 8 }, { 0, 0, 9 }, { 0, 0, 10 } };
int[] flow = new int[2], nflow = new int[2];
RandomIter pitRandomIter = RandomIterFactory.create(pitWR, null);
RandomIter flowFixedIter = CoverageUtilities.getRandomIterator(inFlownet);
WritableRandomIter dirRandomIter = RandomIterFactory.createWritable(dirWR, null);
WritableRaster modifiedFlowWR = CoverageUtilities.createWritableRaster(pitWR.getWidth(), pitWR.getHeight(), Integer.class, null, null);
WritableRandomIter modflowRandomIter = RandomIterFactory.createWritable(modifiedFlowWR, null);
try {
pm.beginTask("Correcting drainage directions...", rows);
for (int j = 0; j < rows; j++) {
if (pm.isCanceled()) {
return;
}
for (int i = 0; i < cols; i++) {
if (!isNovalue(flowFixedIter.getSample(i, j, 0))) {
flow[0] = i;
flow[1] = j;
for (int k = 1; k <= 8; k++) {
nflow[0] = flow[0] + odir[k][1];
nflow[1] = flow[1] + odir[k][0];
if (modflowRandomIter.getSample(nflow[0], nflow[1], 0) == 0 && isNovalue(flowFixedIter.getSample(nflow[0], nflow[1], 0))) {
double elev = pitRandomIter.getSampleDouble(nflow[0] + odir[1][1], nflow[1] + odir[1][0], 0);
for (int n = 2; n <= 8; n++) {
if (nflow[0] + odir[n][0] >= 0 && nflow[0] + odir[n][1] < rows && nflow[1] + odir[n][0] >= 0 && nflow[1] + odir[n][0] < cols) {
double tmpElev = pitRandomIter.getSampleDouble(nflow[0] + odir[n][1], nflow[1] + odir[n][0], 0);
if (tmpElev >= elev) {
elev = tmpElev;
dirRandomIter.setSample(nflow[0], nflow[1], 0, odir[n][2]);
}
}
}
for (int s = 1; s <= 8; s++) {
if (nflow[0] + odir[s][0] >= 0 && nflow[0] + odir[s][0] < rows && nflow[1] + odir[s][1] >= 0 && nflow[1] + odir[s][1] < cols) {
if (!isNovalue(flowFixedIter.getSample(nflow[0] + odir[s][1], nflow[1] + odir[s][0], 0))) {
double tmpElev = pitRandomIter.getSampleDouble(nflow[0] + odir[s][1], nflow[1] + odir[s][0], 0);
if (tmpElev <= elev) {
elev = tmpElev;
dirRandomIter.setSample(nflow[0], nflow[1], 0, odir[s][2]);
}
}
}
}
modflowRandomIter.setSample(nflow[0], nflow[1], 0, 1);
}
}
}
if (!isNovalue(flowFixedIter.getSample(i, j, 0))) {
dirRandomIter.setSample(i, j, 0, flowFixedIter.getSample(i, j, 0));
}
}
pm.worked(1);
}
pm.done();
} finally {
dirRandomIter.done();
pitRandomIter.done();
modflowRandomIter.done();
flowFixedIter.done();
}
}
use of javax.media.jai.iterator.WritableRandomIter in project hortonmachine by TheHortonMachine.
the class OmsGc method createGCRaster.
private WritableRaster[] createGCRaster() {
// get rows and cols from the active region
int cols = regionMap.get(CoverageUtilities.COLS).intValue();
int rows = regionMap.get(CoverageUtilities.ROWS).intValue();
RandomIter slopeIter = CoverageUtilities.getRandomIterator(inSlope);
RandomIter netIter = CoverageUtilities.getRandomIterator(inNetwork);
RandomIter cp9Iter = CoverageUtilities.getRandomIterator(inCp9);
WritableRaster cpClassWR = CoverageUtilities.createWritableRaster(cols, rows, null, null, doubleNovalue);
WritableRandomIter cpClassIter = RandomIterFactory.createWritable(cpClassWR, null);
WritableRaster cpAggClassWR = CoverageUtilities.createWritableRaster(cols, rows, null, null, doubleNovalue);
WritableRandomIter cpAggClassIter = RandomIterFactory.createWritable(cpAggClassWR, null);
// calculate ...
pm.beginTask(msg.message("working") + "gc... (1/2)", rows);
for (int j = 0; j < rows; j++) {
for (int i = 0; i < cols; i++) {
// threshold
if (slopeIter.getSampleDouble(i, j, 0) >= pTh) {
cpClassIter.setSample(i, j, 0, 110);
} else // individuates the network
if (netIter.getSampleDouble(i, j, 0) == 2) {
cpClassIter.setSample(i, j, 0, 100);
} else {
cpClassIter.setSample(i, j, 0, cp9Iter.getSampleDouble(i, j, 0));
}
if (isNovalue(slopeIter.getSampleDouble(i, j, 0))) {
cpClassIter.setSample(i, j, 0, doubleNovalue);
}
}
pm.worked(1);
}
pm.done();
netIter = null;
slopeIter = null;
pm.beginTask(msg.message("working") + "gc... (2/2)", rows);
// 55 ? ravine sites (slope > critic value) (class 110).
for (int j = 0; j < rows; j++) {
for (int i = 0; i < cols; i++) {
if (cpClassIter.getSample(i, j, 0) == 70 || cpClassIter.getSampleDouble(i, j, 0) == 90 || cpClassIter.getSampleDouble(i, j, 0) == 30) {
cpAggClassIter.setSample(i, j, 0, 15);
} else if (cpClassIter.getSampleDouble(i, j, 0) == 10) {
cpAggClassIter.setSample(i, j, 0, 25);
} else if (cpClassIter.getSampleDouble(i, j, 0) == 100) {
cpAggClassIter.setSample(i, j, 0, 35);
} else if (cpClassIter.getSampleDouble(i, j, 0) == 110) {
cpAggClassIter.setSample(i, j, 0, 55);
} else if (!isNovalue(cpClassIter.getSampleDouble(i, j, 0))) {
cpAggClassIter.setSample(i, j, 0, 45);
} else if (isNovalue(cpClassIter.getSampleDouble(i, j, 0))) {
cpAggClassIter.setSample(i, j, 0, doubleNovalue);
}
}
pm.worked(1);
}
pm.done();
return new WritableRaster[] { cpClassWR, cpAggClassWR };
}
use of javax.media.jai.iterator.WritableRandomIter in project hortonmachine by TheHortonMachine.
the class OmsGeomorphonIM method processCell.
@Override
protected void processCell(int readCol, int readRow, int writeCol, int writeRow, int readCols, int readRows, int writeCols, int writeRows) {
try {
RandomIter elevIter = inRasterIterators.get(0);
double classification = OmsGeomorphon.calculateGeomorphon(elevIter, readGridGeometry, pRadius, pThreshold, diagonalDelta, readCol, readRow);
WritableRandomIter outDataIter = outRasterIterators.get(0);
outDataIter.setSample(writeCol, writeRow, 0, classification);
} catch (TransformException e) {
e.printStackTrace();
}
}
Aggregations