Search in sources :

Example 56 with RandomIter

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

the class OmsPeakflow method processWithTopIndex.

private void processWithTopIndex(WritableRaster supRescaledWR, WritableRaster subRescaledWR) throws Exception {
    double[][] topindexCb = doCb(inTopindex);
    // cumulate topindex
    for (int i = 0; i < topindexCb.length; i++) {
        if (i > 0) {
            topindexCb[i][1] = topindexCb[i][1] + topindexCb[i - 1][1];
        }
    }
    double max = topindexCb[topindexCb.length - 1][1];
    // normalize
    for (int i = 0; i < topindexCb.length; i++) {
        topindexCb[i][1] = topindexCb[i][1] / max;
    }
    List<Double> meanValueList = new ArrayList<Double>();
    List<Double> cumulatedValueList = new ArrayList<Double>();
    for (int i = 0; i < topindexCb.length; i++) {
        meanValueList.add(topindexCb[i][0]);
        cumulatedValueList.add(topindexCb[i][1]);
    }
    LinearListInterpolator interpolator = new LinearListInterpolator(meanValueList, cumulatedValueList);
    double topindexThreshold = interpolator.linearInterpolateX(1 - pSat / 100);
    RenderedImage topindexRI = inTopindex.getRenderedImage();
    RandomIter topindexIter = RandomIterFactory.create(topindexRI, null);
    for (int r = 0; r < rows; r++) {
        for (int c = 0; c < cols; c++) {
            double topindex = topindexIter.getSampleDouble(c, r, 0);
            if (topindex >= topindexThreshold) {
                if (subRescaledWR != null) {
                    subRescaledWR.setSample(c, r, 0, doubleNovalue);
                }
            } else {
                supRescaledWR.setSample(c, r, 0, doubleNovalue);
            }
        }
    }
}
Also used : LinearListInterpolator(org.hortonmachine.gears.utils.math.interpolation.LinearListInterpolator) ArrayList(java.util.ArrayList) RandomIter(javax.media.jai.iterator.RandomIter) RenderedImage(java.awt.image.RenderedImage)

Example 57 with RandomIter

use of javax.media.jai.iterator.RandomIter in project geowave by locationtech.

the class WarpNearestOpImage method computeRectShort.

@Override
protected void computeRectShort(final PlanarImage src, final RasterAccessor dst, final RandomIter roiIter, final boolean roiContainsTile) {
    // Random Iterator on the source image bounds
    final RandomIter iter = RandomIterFactory.create(src, src.getBounds(), TILE_CACHED, ARRAY_CALC);
    // Initial settings
    final int minX = src.getMinX();
    final int maxX = src.getMaxX();
    final int minY = src.getMinY();
    final int maxY = src.getMaxY();
    final int dstWidth = dst.getWidth();
    final int dstHeight = dst.getHeight();
    final int dstBands = dst.getNumBands();
    final int lineStride = dst.getScanlineStride();
    final int pixelStride = dst.getPixelStride();
    final int[] bandOffsets = dst.getBandOffsets();
    final short[][] data = dst.getShortDataArrays();
    final float[] warpData = new float[2 * dstWidth];
    int lineOffset = 0;
    // NO ROI AND NODATA
    if (caseA || (caseB && roiContainsTile)) {
        for (int h = 0; h < dstHeight; h++) {
            int pixelOffset = lineOffset;
            lineOffset += lineStride;
            // Calculation of the warp for the selected row
            warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
            int count = 0;
            for (int w = 0; w < dstWidth; w++) {
                /*
           * The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
           * to get the nearest neighbor. This is different from the standard nearest
           * implementation.
           */
                final int sx = round(warpData[count++]);
                final int sy = round(warpData[count++]);
                // If the pixel is outside the input image bounds
                if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
                    /* Fill with a background color. */
                    if (setBackground) {
                        for (int b = 0; b < dstBands; b++) {
                            data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
                        }
                    }
                } else {
                    // Nearest interpolation
                    for (int b = 0; b < dstBands; b++) {
                        data[b][pixelOffset + bandOffsets[b]] = (short) iter.getSample(sx, sy, b);
                    }
                }
                pixelOffset += pixelStride;
            }
        }
    // ONLY ROI
    } else if (caseB) {
        for (int h = 0; h < dstHeight; h++) {
            int pixelOffset = lineOffset;
            lineOffset += lineStride;
            // Calculation of the warp for the selected row
            warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
            int count = 0;
            for (int w = 0; w < dstWidth; w++) {
                /*
           * The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
           * to get the nearest neighbor. This is different from the standard nearest
           * implementation.
           */
                final int sx = round(warpData[count++]);
                final int sy = round(warpData[count++]);
                if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
                    /* Fill with a background color. */
                    if (setBackground) {
                        for (int b = 0; b < dstBands; b++) {
                            data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
                        }
                    }
                } else {
                    // value
                    if (!(roiBounds.contains(sx, sy) && (roiIter.getSample(sx, sy, 0) > 0))) {
                        /* Fill with a background color. */
                        if (setBackground) {
                            for (int b = 0; b < dstBands; b++) {
                                data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
                            }
                        }
                    } else {
                        // Else the related source pixel is set
                        for (int b = 0; b < dstBands; b++) {
                            data[b][pixelOffset + bandOffsets[b]] = (short) iter.getSample(sx, sy, b);
                        }
                    }
                }
                pixelOffset += pixelStride;
            }
        }
    // ONLY NODATA
    } else if (caseC || (hasROI && hasNoData && roiContainsTile)) {
        short inputValue = 0;
        for (int h = 0; h < dstHeight; h++) {
            int pixelOffset = lineOffset;
            lineOffset += lineStride;
            // Calculation of the warp for the selected row
            warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
            int count = 0;
            for (int w = 0; w < dstWidth; w++) {
                /*
           * The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
           * to get the nearest neighbor. This is different from the standard nearest
           * implementation.
           */
                final int sx = round(warpData[count++]);
                final int sy = round(warpData[count++]);
                if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
                    /* Fill with a background color. */
                    if (setBackground) {
                        for (int b = 0; b < dstBands; b++) {
                            data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
                        }
                    }
                } else {
                    // The related source pixel is set if it isn't a nodata
                    for (int b = 0; b < dstBands; b++) {
                        // Input value selected
                        inputValue = (short) iter.getSample(sx, sy, b);
                        if (noDataRange.contains(inputValue)) {
                            data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
                        } else {
                            data[b][pixelOffset + bandOffsets[b]] = inputValue;
                        }
                    }
                }
                pixelOffset += pixelStride;
            }
        }
    // BOTH ROI AND NODATA
    } else {
        short inputValue = 0;
        for (int h = 0; h < dstHeight; h++) {
            int pixelOffset = lineOffset;
            lineOffset += lineStride;
            // Calculation of the warp for the selected row
            warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
            int count = 0;
            for (int w = 0; w < dstWidth; w++) {
                /*
           * The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
           * to get the nearest neighbor. This is different from the standard nearest
           * implementation.
           */
                final int sx = round(warpData[count++]);
                final int sy = round(warpData[count++]);
                if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
                    /* Fill with a background color. */
                    if (setBackground) {
                        for (int b = 0; b < dstBands; b++) {
                            data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
                        }
                    }
                } else {
                    // value
                    if (!(roiBounds.contains(sx, sy) && (roiIter.getSample(sx, sy, 0) > 0))) {
                        /* Fill with a background color. */
                        if (setBackground) {
                            for (int b = 0; b < dstBands; b++) {
                                data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
                            }
                        }
                    } else {
                        // nodata
                        for (int b = 0; b < dstBands; b++) {
                            // Input value selected
                            inputValue = (short) iter.getSample(sx, sy, b);
                            if (noDataRange.contains(inputValue)) {
                                data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
                            } else {
                                data[b][pixelOffset + bandOffsets[b]] = inputValue;
                            }
                        }
                    }
                }
                pixelOffset += pixelStride;
            }
        }
    }
    iter.done();
}
Also used : RandomIter(javax.media.jai.iterator.RandomIter)

Example 58 with RandomIter

use of javax.media.jai.iterator.RandomIter in project geowave by locationtech.

the class WarpNearestOpImage method computeRectUShort.

@Override
protected void computeRectUShort(final PlanarImage src, final RasterAccessor dst, final RandomIter roiIter, final boolean roiContainsTile) {
    // Random Iterator on the source image bounds
    final RandomIter iter = RandomIterFactory.create(src, src.getBounds(), TILE_CACHED, ARRAY_CALC);
    // Initial settings
    final int minX = src.getMinX();
    final int maxX = src.getMaxX();
    final int minY = src.getMinY();
    final int maxY = src.getMaxY();
    final int dstWidth = dst.getWidth();
    final int dstHeight = dst.getHeight();
    final int dstBands = dst.getNumBands();
    final int lineStride = dst.getScanlineStride();
    final int pixelStride = dst.getPixelStride();
    final int[] bandOffsets = dst.getBandOffsets();
    final short[][] data = dst.getShortDataArrays();
    final float[] warpData = new float[2 * dstWidth];
    int lineOffset = 0;
    // NO ROI AND NODATA
    if (caseA || (caseB && roiContainsTile)) {
        for (int h = 0; h < dstHeight; h++) {
            int pixelOffset = lineOffset;
            lineOffset += lineStride;
            // Calculation of the warp for the selected row
            warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
            int count = 0;
            for (int w = 0; w < dstWidth; w++) {
                /*
           * The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
           * to get the nearest neighbor. This is different from the standard nearest
           * implementation.
           */
                final int sx = round(warpData[count++]);
                final int sy = round(warpData[count++]);
                // If the pixel is outside the input image bounds
                if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
                    /* Fill with a background color. */
                    if (setBackground) {
                        for (int b = 0; b < dstBands; b++) {
                            data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
                        }
                    }
                } else {
                    // Nearest interpolation
                    for (int b = 0; b < dstBands; b++) {
                        data[b][pixelOffset + bandOffsets[b]] = (short) (iter.getSample(sx, sy, b) & 0xFFFF);
                    }
                }
                pixelOffset += pixelStride;
            }
        }
    // ONLY ROI
    } else if (caseB) {
        for (int h = 0; h < dstHeight; h++) {
            int pixelOffset = lineOffset;
            lineOffset += lineStride;
            // Calculation of the warp for the selected row
            warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
            int count = 0;
            for (int w = 0; w < dstWidth; w++) {
                /*
           * The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
           * to get the nearest neighbor. This is different from the standard nearest
           * implementation.
           */
                final int sx = round(warpData[count++]);
                final int sy = round(warpData[count++]);
                if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
                    /* Fill with a background color. */
                    if (setBackground) {
                        for (int b = 0; b < dstBands; b++) {
                            data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
                        }
                    }
                } else {
                    // value
                    if (!(roiBounds.contains(sx, sy) && roiBounds.contains(sx, sy) && (roiIter.getSample(sx, sy, 0) > 0))) {
                        /* Fill with a background color. */
                        if (setBackground) {
                            for (int b = 0; b < dstBands; b++) {
                                data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
                            }
                        }
                    } else {
                        // Else the related source pixel is set
                        for (int b = 0; b < dstBands; b++) {
                            data[b][pixelOffset + bandOffsets[b]] = (short) (iter.getSample(sx, sy, b) & 0xFFFF);
                        }
                    }
                }
                pixelOffset += pixelStride;
            }
        }
    // ONLY NODATA
    } else if (caseC || (hasROI && hasNoData && roiContainsTile)) {
        short inputValue = 0;
        for (int h = 0; h < dstHeight; h++) {
            int pixelOffset = lineOffset;
            lineOffset += lineStride;
            // Calculation of the warp for the selected row
            warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
            int count = 0;
            for (int w = 0; w < dstWidth; w++) {
                /*
           * The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
           * to get the nearest neighbor. This is different from the standard nearest
           * implementation.
           */
                final int sx = round(warpData[count++]);
                final int sy = round(warpData[count++]);
                if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
                    /* Fill with a background color. */
                    if (setBackground) {
                        for (int b = 0; b < dstBands; b++) {
                            data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
                        }
                    }
                } else {
                    // The related source pixel is set if it isn't a nodata
                    for (int b = 0; b < dstBands; b++) {
                        // Input value selected
                        inputValue = (short) (iter.getSample(sx, sy, b) & 0xFFFF);
                        if (noDataRange.contains(inputValue)) {
                            data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
                        } else {
                            data[b][pixelOffset + bandOffsets[b]] = inputValue;
                        }
                    }
                }
                pixelOffset += pixelStride;
            }
        }
    // BOTH ROI AND NODATA
    } else {
        short inputValue = 0;
        for (int h = 0; h < dstHeight; h++) {
            int pixelOffset = lineOffset;
            lineOffset += lineStride;
            // Calculation of the warp for the selected row
            warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
            int count = 0;
            for (int w = 0; w < dstWidth; w++) {
                /*
           * The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
           * to get the nearest neighbor. This is different from the standard nearest
           * implementation.
           */
                final int sx = round(warpData[count++]);
                final int sy = round(warpData[count++]);
                if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
                    /* Fill with a background color. */
                    if (setBackground) {
                        for (int b = 0; b < dstBands; b++) {
                            data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
                        }
                    }
                } else {
                    // value
                    if (!(roiBounds.contains(sx, sy) && (roiIter.getSample(sx, sy, 0) > 0))) {
                        /* Fill with a background color. */
                        if (setBackground) {
                            for (int b = 0; b < dstBands; b++) {
                                data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
                            }
                        }
                    } else {
                        // nodata
                        for (int b = 0; b < dstBands; b++) {
                            // Input value selected
                            inputValue = (short) (iter.getSample(sx, sy, b) & 0xFFFF);
                            if (noDataRange.contains(inputValue)) {
                                data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
                            } else {
                                data[b][pixelOffset + bandOffsets[b]] = inputValue;
                            }
                        }
                    }
                }
                pixelOffset += pixelStride;
            }
        }
    }
    iter.done();
}
Also used : RandomIter(javax.media.jai.iterator.RandomIter)

Example 59 with RandomIter

use of javax.media.jai.iterator.RandomIter in project geowave by locationtech.

the class WarpNearestOpImage method computeRectDouble.

@Override
protected void computeRectDouble(final PlanarImage src, final RasterAccessor dst, final RandomIter roiIter, final boolean roiContainsTile) {
    // Random Iterator on the source image bounds
    final RandomIter iter = RandomIterFactory.create(src, src.getBounds(), TILE_CACHED, ARRAY_CALC);
    // Initial settings
    final int minX = src.getMinX();
    final int maxX = src.getMaxX();
    final int minY = src.getMinY();
    final int maxY = src.getMaxY();
    final int dstWidth = dst.getWidth();
    final int dstHeight = dst.getHeight();
    final int dstBands = dst.getNumBands();
    final int lineStride = dst.getScanlineStride();
    final int pixelStride = dst.getPixelStride();
    final int[] bandOffsets = dst.getBandOffsets();
    final double[][] data = dst.getDoubleDataArrays();
    final float[] warpData = new float[2 * dstWidth];
    int lineOffset = 0;
    // NO ROI AND NODATA
    if (caseA || (caseB && roiContainsTile)) {
        for (int h = 0; h < dstHeight; h++) {
            int pixelOffset = lineOffset;
            lineOffset += lineStride;
            // Calculation of the warp for the selected row
            warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
            int count = 0;
            for (int w = 0; w < dstWidth; w++) {
                /*
           * The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
           * to get the nearest neighbor. This is different from the standard nearest
           * implementation.
           */
                final int sx = round(warpData[count++]);
                final int sy = round(warpData[count++]);
                // If the pixel is outside the input image bounds
                if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
                    /* Fill with a background color. */
                    if (setBackground) {
                        for (int b = 0; b < dstBands; b++) {
                            data[b][pixelOffset + bandOffsets[b]] = backgroundValues[b];
                        }
                    }
                } else {
                    // Nearest interpolation
                    for (int b = 0; b < dstBands; b++) {
                        data[b][pixelOffset + bandOffsets[b]] = iter.getSampleDouble(sx, sy, b);
                    }
                }
                pixelOffset += pixelStride;
            }
        }
    // ONLY ROI
    } else if (caseB) {
        for (int h = 0; h < dstHeight; h++) {
            int pixelOffset = lineOffset;
            lineOffset += lineStride;
            // Calculation of the warp for the selected row
            warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
            int count = 0;
            for (int w = 0; w < dstWidth; w++) {
                /*
           * The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
           * to get the nearest neighbor. This is different from the standard nearest
           * implementation.
           */
                final int sx = round(warpData[count++]);
                final int sy = round(warpData[count++]);
                if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
                    /* Fill with a background color. */
                    if (setBackground) {
                        for (int b = 0; b < dstBands; b++) {
                            data[b][pixelOffset + bandOffsets[b]] = backgroundValues[b];
                        }
                    }
                } else {
                    // value
                    if (!(roiBounds.contains(sx, sy) && (roiIter.getSample(sx, sy, 0) > 0))) {
                        /* Fill with a background color. */
                        if (setBackground) {
                            for (int b = 0; b < dstBands; b++) {
                                data[b][pixelOffset + bandOffsets[b]] = backgroundValues[b];
                            }
                        }
                    } else {
                        // Else the related source pixel is set
                        for (int b = 0; b < dstBands; b++) {
                            data[b][pixelOffset + bandOffsets[b]] = iter.getSampleDouble(sx, sy, b);
                        }
                    }
                }
                pixelOffset += pixelStride;
            }
        }
    // ONLY NODATA
    } else if (caseC || (hasROI && hasNoData && roiContainsTile)) {
        double inputValue = 0;
        for (int h = 0; h < dstHeight; h++) {
            int pixelOffset = lineOffset;
            lineOffset += lineStride;
            // Calculation of the warp for the selected row
            warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
            int count = 0;
            for (int w = 0; w < dstWidth; w++) {
                /*
           * The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
           * to get the nearest neighbor. This is different from the standard nearest
           * implementation.
           */
                final int sx = round(warpData[count++]);
                final int sy = round(warpData[count++]);
                if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
                    /* Fill with a background color. */
                    if (setBackground) {
                        for (int b = 0; b < dstBands; b++) {
                            data[b][pixelOffset + bandOffsets[b]] = backgroundValues[b];
                        }
                    }
                } else {
                    // The related source pixel is set if it isn't a nodata
                    for (int b = 0; b < dstBands; b++) {
                        // Input value selected
                        inputValue = iter.getSampleDouble(sx, sy, b);
                        if (noDataRange.contains(inputValue)) {
                            data[b][pixelOffset + bandOffsets[b]] = backgroundValues[b];
                        } else {
                            data[b][pixelOffset + bandOffsets[b]] = inputValue;
                        }
                    }
                }
                pixelOffset += pixelStride;
            }
        }
    // BOTH ROI AND NODATA
    } else {
        double inputValue = 0;
        for (int h = 0; h < dstHeight; h++) {
            int pixelOffset = lineOffset;
            lineOffset += lineStride;
            // Calculation of the warp for the selected row
            warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
            int count = 0;
            for (int w = 0; w < dstWidth; w++) {
                /*
           * The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
           * to get the nearest neighbor. This is different from the standard nearest
           * implementation.
           */
                final int sx = round(warpData[count++]);
                final int sy = round(warpData[count++]);
                if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
                    /* Fill with a background color. */
                    if (setBackground) {
                        for (int b = 0; b < dstBands; b++) {
                            data[b][pixelOffset + bandOffsets[b]] = backgroundValues[b];
                        }
                    }
                } else {
                    // value
                    if (!(roiBounds.contains(sx, sy) && (roiIter.getSample(sx, sy, 0) > 0))) {
                        /* Fill with a background color. */
                        if (setBackground) {
                            for (int b = 0; b < dstBands; b++) {
                                data[b][pixelOffset + bandOffsets[b]] = backgroundValues[b];
                            }
                        }
                    } else {
                        // nodata
                        for (int b = 0; b < dstBands; b++) {
                            // Input value selected
                            inputValue = iter.getSampleDouble(sx, sy, b);
                            if (noDataRange.contains(inputValue)) {
                                data[b][pixelOffset + bandOffsets[b]] = backgroundValues[b];
                            } else {
                                data[b][pixelOffset + bandOffsets[b]] = inputValue;
                            }
                        }
                    }
                }
                pixelOffset += pixelStride;
            }
        }
    }
    iter.done();
}
Also used : RandomIter(javax.media.jai.iterator.RandomIter)

Example 60 with RandomIter

use of javax.media.jai.iterator.RandomIter in project geowave by locationtech.

the class WarpOpImage method computeRect.

/**
 * Warps a rectangle. If ROI is present, the intersection between ROI and tile bounds is
 * calculated; The result ROI will be used for calculations inside the computeRect() method.
 */
@Override
protected void computeRect(final PlanarImage[] sources, final WritableRaster dest, final Rectangle destRect) {
    // Retrieve format tags.
    final RasterFormatTag[] formatTags = getFormatTags();
    final RasterAccessor dst = new RasterAccessor(dest, destRect, formatTags[1], getColorModel());
    RandomIter roiIter = null;
    boolean roiContainsTile = false;
    boolean roiDisjointTile = false;
    // tile bounds is taken.
    if (hasROI) {
        final Rectangle srcRectExpanded = mapDestRect(destRect, 0);
        // The tile dimension is extended for avoiding border errors
        srcRectExpanded.setRect(srcRectExpanded.getMinX() - leftPad, srcRectExpanded.getMinY() - topPad, srcRectExpanded.getWidth() + rightPad + leftPad, srcRectExpanded.getHeight() + bottomPad + topPad);
        if (!roiBounds.intersects(srcRectExpanded)) {
            roiDisjointTile = true;
        } else {
            roiContainsTile = roi.contains(srcRectExpanded);
            if (!roiContainsTile) {
                if (!roi.intersects(srcRectExpanded)) {
                    roiDisjointTile = true;
                } else {
                    final PlanarImage roiIMG = getImage();
                    roiIter = RandomIterFactory.create(roiIMG, null, TILE_CACHED, ARRAY_CALC);
                }
            }
        }
    }
    if (!hasROI || !roiDisjointTile) {
        switch(dst.getDataType()) {
            case DataBuffer.TYPE_BYTE:
                computeRectByte(sources[0], dst, roiIter, roiContainsTile);
                break;
            case DataBuffer.TYPE_USHORT:
                computeRectUShort(sources[0], dst, roiIter, roiContainsTile);
                break;
            case DataBuffer.TYPE_SHORT:
                computeRectShort(sources[0], dst, roiIter, roiContainsTile);
                break;
            case DataBuffer.TYPE_INT:
                computeRectInt(sources[0], dst, roiIter, roiContainsTile);
                break;
            case DataBuffer.TYPE_FLOAT:
                computeRectFloat(sources[0], dst, roiIter, roiContainsTile);
                break;
            case DataBuffer.TYPE_DOUBLE:
                computeRectDouble(sources[0], dst, roiIter, roiContainsTile);
                break;
        }
        // WritableRaster
        if (dst.isDataCopy()) {
            dst.clampDataArrays();
            dst.copyDataToRaster();
        }
    } else {
        // set to backgroundValues
        if (setBackground) {
            ImageUtil.fillBackground(dest, destRect, backgroundValues);
        }
    }
}
Also used : RasterFormatTag(javax.media.jai.RasterFormatTag) Rectangle(java.awt.Rectangle) RandomIter(javax.media.jai.iterator.RandomIter) PlanarImage(javax.media.jai.PlanarImage) RasterAccessor(javax.media.jai.RasterAccessor)

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