Search in sources :

Example 96 with RandomIter

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);
            }
        }
    }
}
Also used : RandomIter(javax.media.jai.iterator.RandomIter)

Example 97 with RandomIter

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();
    }
}
Also used : WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) WritableRaster(java.awt.image.WritableRaster) FlowNode(org.hortonmachine.gears.libs.modules.FlowNode) Node(org.hortonmachine.gears.libs.modules.Node) RandomIter(javax.media.jai.iterator.RandomIter) WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) FlowNode(org.hortonmachine.gears.libs.modules.FlowNode)

Example 98 with RandomIter

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();
    }
}
Also used : WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) WritableRaster(java.awt.image.WritableRaster) RandomIter(javax.media.jai.iterator.RandomIter) WritableRandomIter(javax.media.jai.iterator.WritableRandomIter)

Example 99 with RandomIter

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();
    }
}
Also used : WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) WritableRaster(java.awt.image.WritableRaster) FlowNode(org.hortonmachine.gears.libs.modules.FlowNode) Node(org.hortonmachine.gears.libs.modules.Node) RandomIter(javax.media.jai.iterator.RandomIter) WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) FlowNode(org.hortonmachine.gears.libs.modules.FlowNode)

Example 100 with RandomIter

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());
    }
}
Also used : WritableRaster(java.awt.image.WritableRaster) RandomIter(javax.media.jai.iterator.RandomIter) RenderedImage(java.awt.image.RenderedImage) Execute(oms3.annotations.Execute)

Aggregations

RandomIter (javax.media.jai.iterator.RandomIter)126 WritableRandomIter (javax.media.jai.iterator.WritableRandomIter)79 WritableRaster (java.awt.image.WritableRaster)71 RegionMap (org.hortonmachine.gears.utils.RegionMap)62 Execute (oms3.annotations.Execute)57 RenderedImage (java.awt.image.RenderedImage)29 GridGeometry2D (org.geotools.coverage.grid.GridGeometry2D)29 Coordinate (org.locationtech.jts.geom.Coordinate)26 GridCoverage2D (org.geotools.coverage.grid.GridCoverage2D)22 Point (java.awt.Point)17 ArrayList (java.util.ArrayList)17 ModelsIllegalargumentException (org.hortonmachine.gears.libs.exceptions.ModelsIllegalargumentException)16 SimpleFeature (org.opengis.feature.simple.SimpleFeature)16 DefaultFeatureCollection (org.geotools.feature.DefaultFeatureCollection)15 Geometry (org.locationtech.jts.geom.Geometry)15 Point (org.locationtech.jts.geom.Point)14 GridCoordinates2D (org.geotools.coverage.grid.GridCoordinates2D)12 GridNode (org.hortonmachine.gears.libs.modules.GridNode)12 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)10 FlowNode (org.hortonmachine.gears.libs.modules.FlowNode)9