use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.
the class HMTestCase method checkMatrixEqual.
protected void checkMatrixEqual(Raster image, double[][] matrix) {
assertEquals("different dimension", image.getHeight(), matrix.length);
assertEquals("different dimension", image.getWidth(), matrix[0].length);
RandomIter randomIter = RandomIterFactory.create(image, null);
int minX = image.getMinX();
int minY = image.getMinY();
for (int j = minY; j < minY + image.getHeight(); j++) {
for (int i = minX; i < minX + image.getWidth(); i++) {
double expectedResult = matrix[i - minX][j - minY];
double value = randomIter.getSampleDouble(i, j, 0);
if (isNovalue(value)) {
assertTrue("Difference at position: " + i + " " + j, isNovalue(expectedResult));
} else {
assertEquals("Difference at position: " + i + " " + j, expectedResult, value);
}
}
}
}
use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.
the class OmsExtractNetwork method extractNetMode2.
/**
* this method the network is extracted by considering only concave points
* as being part of the channel network.
* @throws Exception
*/
private WritableRaster extractNetMode2(RenderedImage flowRI, int novalue, RenderedImage tcaRI, RenderedImage classRI, RenderedImage slopeRI) throws Exception {
RandomIter flowRandomIter = RandomIterFactory.create(flowRI, null);
RandomIter tcaRandomIter = RandomIterFactory.create(tcaRI, null);
RandomIter classRandomIter = RandomIterFactory.create(classRI, null);
RandomIter slopeRandomIter = RandomIterFactory.create(slopeRI, null);
WritableRaster netImage = CoverageUtilities.createWritableRaster(cols, rows, Short.class, null, shortNovalue);
// try the operation!!
WritableRandomIter netRandomIter = RandomIterFactory.createWritable(netImage, null);
try {
// $NON-NLS-1$
pm.beginTask(msg.message("extractnetwork.extracting"), rows * cols);
processGrid(cols, rows, false, (c, r) -> {
if (pm.isCanceled()) {
return;
}
double tcaValue = tcaRandomIter.getSample(c, r, 0);
double slopeValue = slopeRandomIter.getSampleDouble(c, r, 0);
if (!isNovalue(tcaValue) && !isNovalue(slopeValue)) {
tcaValue = pow(tcaValue, pExp) * slopeValue;
if (tcaValue >= pThres && classRandomIter.getSample(c, r, 0) == 15) {
netRandomIter.setSample(c, r, 0, NETVALUE);
FlowNode flowNode = new FlowNode(flowRandomIter, cols, rows, c, r, novalue);
FlowNode runningNode = flowNode;
while ((runningNode = runningNode.goDownstream()) != null) {
int rCol = runningNode.col;
int rRow = runningNode.row;
short tmpNetValue = (short) netRandomIter.getSample(rCol, rRow, 0);
if (!isNovalue(tmpNetValue)) {
break;
}
if (runningNode.isMarkedAsOutlet()) {
netRandomIter.setSample(rCol, rRow, 0, NETVALUE);
break;
} else if (runningNode.touchesBound()) {
Node goDownstream = runningNode.goDownstream();
if (goDownstream == null || !goDownstream.isValid()) {
netRandomIter.setSample(rCol, rRow, 0, NETVALUE);
break;
}
}
netRandomIter.setSample(rCol, rRow, 0, NETVALUE);
}
}
}
pm.worked(1);
});
pm.done();
return netImage;
} finally {
flowRandomIter.done();
tcaRandomIter.done();
classRandomIter.done();
slopeRandomIter.done();
netRandomIter.done();
}
}
use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.
the class OmsExtractNetwork method extractNetTcaThreshold.
/**
* this method calculates the network using a threshold value on the
* contributing areas or on magnitudo
* @throws Exception
*/
private WritableRaster extractNetTcaThreshold(RenderedImage tcaRI) throws Exception {
RandomIter tcaIter = RandomIterFactory.create(tcaRI, null);
WritableRaster netWR = CoverageUtilities.createWritableRaster(cols, rows, Short.class, null, shortNovalue);
WritableRandomIter netIter = RandomIterFactory.createWritable(netWR, null);
try {
// $NON-NLS-1$
pm.beginTask(msg.message("extractnetwork.extracting"), rows * cols);
processGrid(cols, rows, false, (c, r) -> {
if (pm.isCanceled()) {
return;
}
int tcaValue = tcaIter.getSample(c, r, 0);
if (!isNovalue(tcaValue)) {
if (tcaValue >= pThres) {
// FIXME needs power here?
netIter.setSample(c, r, 0, NETVALUE);
}
}
pm.worked(1);
});
pm.done();
return netWR;
} finally {
netIter.done();
tcaIter.done();
}
}
use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.
the class OmsExtractNetwork method extractNetMode1.
/**
* this method calculates the network imposing a threshold value on the
* product of two quantities, for example the contributing area and the
* slope.
* @throws Exception
*/
private WritableRaster extractNetMode1(RenderedImage flowRI, int novalue, RenderedImage tcaRI, RenderedImage slopeRI) throws Exception {
RandomIter flowRandomIter = RandomIterFactory.create(flowRI, null);
RandomIter tcaRandomIter = RandomIterFactory.create(tcaRI, null);
RandomIter slopeRandomIter = RandomIterFactory.create(slopeRI, null);
// create new RasterData for the network matrix
WritableRaster networkWR = CoverageUtilities.createWritableRaster(cols, rows, Short.class, null, shortNovalue);
WritableRandomIter netRandomIter = RandomIterFactory.createWritable(networkWR, null);
try {
// $NON-NLS-1$
pm.beginTask(msg.message("extractnetwork.extracting"), rows * cols);
processGrid(cols, rows, false, (c, r) -> {
if (pm.isCanceled()) {
return;
}
double tcaValue = tcaRandomIter.getSample(c, r, 0);
double slopeValue = slopeRandomIter.getSampleDouble(c, r, 0);
if (!isNovalue(tcaValue) && !isNovalue(slopeValue)) {
tcaValue = pow(tcaValue, pExp);
if (tcaValue * slopeValue >= pThres) {
netRandomIter.setSample(c, r, 0, NETVALUE);
FlowNode flowNode = new FlowNode(flowRandomIter, cols, rows, c, r, novalue);
FlowNode runningNode = flowNode;
while ((runningNode = runningNode.goDownstream()) != null) {
int rCol = runningNode.col;
int rRow = runningNode.row;
int tmpNetValue = netRandomIter.getSample(rCol, rRow, 0);
if (!isNovalue(tmpNetValue)) {
break;
}
if (runningNode.isMarkedAsOutlet()) {
netRandomIter.setSample(rCol, rRow, 0, NETVALUE);
break;
} else if (runningNode.touchesBound()) {
Node goDownstream = runningNode.goDownstream();
if (goDownstream == null || !goDownstream.isValid()) {
netRandomIter.setSample(rCol, rRow, 0, NETVALUE);
break;
}
}
netRandomIter.setSample(rCol, rRow, 0, NETVALUE);
}
}
} else {
netRandomIter.setSample(c, r, 0, shortNovalue);
}
pm.worked(1);
});
pm.done();
return networkWR;
} finally {
flowRandomIter.done();
tcaRandomIter.done();
slopeRandomIter.done();
netRandomIter.done();
}
}
use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.
the class OmsMagnitudo method process.
@Execute
public void process() throws Exception {
if (!concatOr(outMag == null, doReset)) {
return;
}
checkNull(inFlow);
HashMap<String, Double> regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inFlow);
int cols = regionMap.get(CoverageUtilities.COLS).intValue();
int rows = regionMap.get(CoverageUtilities.ROWS).intValue();
RenderedImage flowRI = inFlow.getRenderedImage();
RandomIter flowIter = RandomIterFactory.create(flowRI, null);
WritableRaster magWR = CoverageUtilities.createWritableRaster(cols, rows, null, null, 0.0);
if (magWR == null) {
return;
} else {
magnitudo(flowIter, cols, rows, magWR);
outMag = CoverageUtilities.buildCoverage("mag", magWR, regionMap, inFlow.getCoordinateReferenceSystem());
}
}
Aggregations