Search in sources :

Example 16 with RandomIter

use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.

the class HoughCircles method run.

public void run(BufferedImage circleImage) {
    offx = 0;
    offy = 0;
    width = raster.getWidth();
    height = raster.getHeight();
    offset = width;
    imageValues = new byte[width * height];
    int count = 0;
    RandomIter renderedImageIterator = RandomIterFactory.create(raster, null);
    for (int r = 0; r < height; r++) {
        for (int c = 0; c < width; c++) {
            int sample = renderedImageIterator.getSample(c, r, 0);
            imageValues[count++] = (byte) sample;
        }
    }
    renderedImageIterator.done();
    double[][][] houghValues = houghTransform();
    // Create image View for Hough Transform.
    // ImageProcessor newip = new ByteProcessor(width, height);
    // byte[] newpixels = (byte[]) newip.getPixels();
    // createHoughPixels(houghValues, newpixels);
    // 
    // // Create image View for Marked Circles.
    // ImageProcessor circlesip = new ByteProcessor(width, height);
    // byte[] circlespixels = (byte[]) circlesip.getPixels();
    // Mark the center of the found circles in a new image
    // if (useThreshold)
    // getCenterPointsByThreshold(threshold);
    // else
    Coordinate[] centerPoints = getCenterPoints(houghValues, maxCircles);
    // drawCircles(houghValues, circlespixels);
    Graphics2D g2d;
    if (circleImage != null) {
        g2d = (Graphics2D) circleImage.getGraphics();
    } else {
        g2d = (Graphics2D) raster.getGraphics();
    }
    g2d.setColor(Color.red);
    g2d.setStroke(new BasicStroke(2));
    for (Coordinate point : centerPoints) {
        int size = (int) point.z * 2;
        g2d.drawOval((int) point.x - size / 2, (int) point.y + -size / 2, size, size);
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Coordinate(org.locationtech.jts.geom.Coordinate) RandomIter(javax.media.jai.iterator.RandomIter) Graphics2D(java.awt.Graphics2D)

Example 17 with RandomIter

use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.

the class OmsAb method process.

@Execute
public void process() throws Exception {
    if (!concatOr(outAb == null, doReset)) {
        return;
    }
    checkNull(inTca, inPlan);
    RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inTca);
    int nCols = regionMap.getCols();
    int nRows = regionMap.getRows();
    double xRes = regionMap.getXres();
    RandomIter tcaIter = CoverageUtilities.getRandomIterator(inTca);
    RandomIter planIter = CoverageUtilities.getRandomIterator(inPlan);
    WritableRaster alungWR = CoverageUtilities.createWritableRaster(nCols, nRows, null, null, null);
    WritableRandomIter alungIter = RandomIterFactory.createWritable(alungWR, null);
    WritableRaster bWR = CoverageUtilities.createWritableRaster(nCols, nRows, null, null, null);
    WritableRandomIter bIter = RandomIterFactory.createWritable(bWR, null);
    try {
        pm.beginTask(msg.message("ab.calculating"), nRows * nCols);
        processGrid(nCols, nRows, (c, r) -> {
            if (pm.isCanceled()) {
                return;
            }
            double planSample = planIter.getSampleDouble(c, r, 0);
            if (!isNovalue(planSample) && planSample != 0.0) {
                if (xRes > 1 / planSample && planSample >= 0.0) {
                    bIter.setSample(c, r, 0, 0.1 * xRes);
                } else if (xRes > Math.abs(1 / planSample) && planSample < 0.0) {
                    bIter.setSample(c, r, 0, xRes + 0.9 * xRes);
                } else {
                    double bSample = 2 * Math.asin(xRes / (2 * (1 / planSample))) * (1 / planSample - xRes);
                    bIter.setSample(c, r, 0, bSample);
                    if (planSample >= 0.0 && bSample < 0.1 * xRes) {
                        bIter.setSample(c, r, 0, 0.1 * xRes);
                    }
                    if (planSample < 0.0 && bSample > (xRes + 0.9 * xRes)) {
                        bIter.setSample(c, r, 0, xRes + 0.9 * xRes);
                    }
                }
            }
            if (planSample == 0.0) {
                bIter.setSample(c, r, 0, xRes);
            }
            alungIter.setSample(c, r, 0, tcaIter.getSample(c, r, 0) * xRes * xRes / bIter.getSampleDouble(c, r, 0));
            if (isNovalue(planSample)) {
                alungIter.setSample(c, r, 0, doubleNovalue);
                bIter.setSample(c, r, 0, doubleNovalue);
            }
            pm.worked(1);
        });
        pm.done();
    } finally {
        tcaIter.done();
        planIter.done();
        alungIter.done();
        bIter.done();
    }
    outAb = CoverageUtilities.buildCoverage("alung", alungWR, regionMap, inTca.getCoordinateReferenceSystem());
    outB = CoverageUtilities.buildCoverage("b", bWR, regionMap, inTca.getCoordinateReferenceSystem());
}
Also used : WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) WritableRaster(java.awt.image.WritableRaster) RegionMap(org.hortonmachine.gears.utils.RegionMap) RandomIter(javax.media.jai.iterator.RandomIter) WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) Execute(oms3.annotations.Execute)

Example 18 with RandomIter

use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.

the class OmsAspectIM method processCell.

@Override
protected void processCell(int readCol, int readRow, int writeCol, int writeRow, int readCols, int readRows, int writeCols, int writeRows) {
    RandomIter elevIter = inRasterIterators.get(0);
    Double novalue = inRasterNovalues.get(0);
    GridNode node = new GridNode(elevIter, readCols, readRows, xRes, yRes, readCol, readRow, novalue);
    double aspect = OmsAspect.calculateAspect(node, radtodeg, doRound);
    WritableRandomIter outDataIter = outRasterIterators.get(0);
    outDataIter.setSample(writeCol, writeRow, 0, aspect);
}
Also used : WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) GridNode(org.hortonmachine.gears.libs.modules.GridNode) RandomIter(javax.media.jai.iterator.RandomIter) WritableRandomIter(javax.media.jai.iterator.WritableRandomIter)

Example 19 with RandomIter

use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.

the class OmsCurvaturesIM method processCell.

@Override
protected void processCell(int readCol, int readRow, int writeCol, int writeRow, int readCols, int readRows, int writeCols, int writeRows) {
    RandomIter elevIter = inRasterIterators.get(0);
    Double novalue = inRasterNovalues.get(0);
    GridNode node = new GridNode(elevIter, readCols, readRows, xRes, yRes, readCol, readRow, novalue);
    OmsCurvatures.calculateCurvatures2(node, planTangProf);
    if (outPlan != null)
        outRasterIterators.get(0).setSample(writeCol, writeRow, 0, planTangProf[0]);
    if (outTang != null)
        outRasterIterators.get(1).setSample(writeCol, writeRow, 0, planTangProf[1]);
    if (outProf != null)
        outRasterIterators.get(2).setSample(writeCol, writeRow, 0, planTangProf[2]);
}
Also used : GridNode(org.hortonmachine.gears.libs.modules.GridNode) RandomIter(javax.media.jai.iterator.RandomIter)

Example 20 with RandomIter

use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.

the class OmsGeomorphon method process.

@Execute
public void process() throws Exception {
    checkNull(inElev);
    if (pRadius <= 0) {
        throw new ModelsIllegalargumentException("The search radius has to be > 0.", this, pm);
    }
    final double diagonalDelta = pRadius / sqrt(2.0);
    final RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inElev);
    int cols = regionMap.getCols();
    final int rows = regionMap.getRows();
    final RandomIter elevIter = CoverageUtilities.getRandomIterator(inElev);
    final GridGeometry2D gridGeometry = inElev.getGridGeometry();
    WritableRaster[] outWRHolder = new WritableRaster[1];
    outRaster = CoverageUtilities.createCoverageFromTemplate(inElev, HMConstants.doubleNovalue, outWRHolder);
    final WritableRandomIter outIter = CoverageUtilities.getWritableRandomIterator(outWRHolder[0]);
    pm.beginTask("Calculate classes...", cols);
    for (int r = 0; r < rows; r++) {
        for (int c = 0; c < cols; c++) {
            try {
                double classification = calculateGeomorphon(elevIter, gridGeometry, pRadius, pThreshold, diagonalDelta, c, r);
                outIter.setSample(c, r, 0, classification);
            } catch (TransformException e) {
                e.printStackTrace();
            }
        }
        pm.worked(1);
    }
    pm.done();
}
Also used : ModelsIllegalargumentException(org.hortonmachine.gears.libs.exceptions.ModelsIllegalargumentException) GridGeometry2D(org.geotools.coverage.grid.GridGeometry2D) WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) WritableRaster(java.awt.image.WritableRaster) RegionMap(org.hortonmachine.gears.utils.RegionMap) TransformException(org.opengis.referencing.operation.TransformException) RandomIter(javax.media.jai.iterator.RandomIter) WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) ProfilePoint(org.hortonmachine.gears.utils.coverage.ProfilePoint) 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