Package javax.media.jai.iterator

Examples of javax.media.jai.iterator.RandomIter


        int height = renderedImage.getHeight();
        int width = renderedImage.getWidth();
        // FIXME here I want to exploit tiling, not have the whole image loaded,
        // but when I do, I get an
        RandomIter iterator = RandomIterFactory.create(renderedImage,
                new Rectangle(0, 0, width, height));
        // NewWritableFileRandomIter iterator =
        // NewFileImageRandomIterFactory.createWritableFileRandomIter((FileImage) renderedImage,
        // new Rectangle(0, 0, width, height));
        int k = 0;
        monitor.started();
        monitor.setTask(new SimpleInternationalString("Writing map to disk: " + mapName));
        float progress = 0;
        for( int i = 0; i < dataWindowRows; i++ ) {
            for( int j = 0; j < dataWindowCols; j++ ) {
                double value = iterator.getSampleDouble(j,i,0);

                if (Double.isNaN(value) || value == novalue) {
                    // put in the map the placeholder = 0.0 ...
                    if (numberofbytes == 8) {
                        rowAsByteBuffer.putDouble(0.0);
View Full Code Here


        Pixel px1 = new Pixel();
        Pixel px2 = new Pixel();

        final int width = image1.getWidth();
        final int height = image1.getHeight();
        RandomIter it1 = RandomIterFactory.create(image1, null);
        RandomIter it2 = RandomIterFactory.create(image2, null);
        Pixel cursor = new Pixel();
        try {
            for (int r = 0; r < height; r++) {
                for (int c = 0; c < width; c++) {
                    it1.getPixel(c, r, components);
                    px1.init(components);
                    it2.getPixel(c, r, components);
                    px2.init(components);

                    if (mode == Mode.IgnoreColors) {
                        if (!px1.isBrightnessSimilar(px2)) {
                            mismatchCount++;
                        }
                    } else if (!px1.isSimilar(px2)) {
                        if (mode == Mode.IgnoreAntialiasing) {
                            if (isAntialised(px1, it1, r, c, width, height, components, cursor)
                                    || isAntialised(px2, it2, r, c, width, height, components,
                                            cursor)) {
                                if (!px1.isBrightnessSimilar(px2)) {
                                    mismatchCount++;
                                }
                            } else {
                                mismatchCount++;
                            }
                        } else {
                            mismatchCount++;
                        }
                    }
                }
            }
        } finally {
            it1.done();
            it2.done();
        }

    }
View Full Code Here

    }

    private RoiAccessor buildRoiAccessor(ROI sourceROI) {
        if (sourceROI != null) {
            final PlanarImage roiImage = sourceROI.getAsImage();
            final RandomIter roiIter = RandomIterFactory.create(roiImage, null);
            final int minRoiX = roiImage.getMinX();
            final int minRoiY = roiImage.getMinY();
            final int roiW = roiImage.getWidth();
            final int roiH = roiImage.getHeight();
            return new RoiAccessor(roiIter, sourceROI, roiImage, minRoiX, minRoiY, roiW, roiH);
View Full Code Here

        byte[][] dstdata = (byte[][]) dimd.data;

        int dstPixelStride = dimd.pixelStride;
        int dstLineStride = dimd.lineStride;

        RandomIter iter;
        // Source and Destination Point2D objects
        Point2D ptSrc = new Point2D.Double(0, 0);
        Point2D ptDst = new Point2D.Double(0, 0);
        // Destination object initial position
        final int minX = destRect.x;
        final int minY = destRect.y;

        int db = 0;

        // Only valid data
        if (caseA) {
            // Cycle on all the sources
            for (int sindex = 0; sindex < nSrcs; sindex++) {
                // Random Iterator for cycling on the sources
                iter = RandomIterFactory.create(sources[sindex], sources[sindex].getBounds());
                // Affine transformation for the selected source
                AffineTransform trans = transforms.get(sindex);
                TRANSFORM transObj = transformObj.get(sindex);
                // Source corners
                final int srcMinX = sources[sindex].getMinX();
                final int srcMinY = sources[sindex].getMinY();
                final int srcMaxX = sources[sindex].getMaxX();
                final int srcMaxY = sources[sindex].getMaxY();
                // Destination Line and Pixel offset initialization
                int dstLineOffset = 0;
                int dstPixelOffset = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++) {
                    dstPixelOffset = dstLineOffset;
                    // Cycle on the x-axis
                    for (int x = 0; x < destRect.width; x++) {
                        // Set the x,y destination pixel location
                        ptDst.setLocation(x + minX, y + minY);
                        // Map destination pixel to source pixel
                        transObj.transform(trans, ptDst, ptSrc);
                        // Source pixel indexes
                        int srcX = round(ptSrc.getX());
                        int srcY = round(ptSrc.getY());
                        // Check if the pixel is inside the source dimension
                        if (srcX < srcMinX || srcX >= srcMaxX || srcY < srcMinY || srcY >= srcMaxY) {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }
                                // Setting the no data value
                                dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataByte;
                            }
                        } else {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }
                                // Setting the value
                                dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = (byte) (iter
                                        .getSample(srcX, srcY, sb) & 0xFF);
                            }
                        }
                        dstPixelOffset += dstPixelStride;
                    }
                    dstLineOffset += dstLineStride;
                }
                db += snbands[sindex];
            }
            // Only ROI
        } else if (caseB) {
            // Cycle on all the sources
            for (int sindex = 0; sindex < nSrcs; sindex++) {
                // Random Iterator for cycling on the sources
                iter = RandomIterFactory.create(sources[sindex], sources[sindex].getBounds());
                // Affine transformation for the selected source
                AffineTransform trans = transforms.get(sindex);
                TRANSFORM transObj = transformObj.get(sindex);
                // Source corners
                final int srcMinX = sources[sindex].getMinX();
                final int srcMinY = sources[sindex].getMinY();
                final int srcMaxX = sources[sindex].getMaxX();
                final int srcMaxY = sources[sindex].getMaxY();
                // Destination Line and Pixel offset initialization
                int dstLineOffset = 0;
                int dstPixelOffset = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++) {
                    dstPixelOffset = dstLineOffset;
                    // Cycle on the x-axis
                    for (int x = 0; x < destRect.width; x++) {
                        // ROI check
                        int dstX = x + minX;
                        int dstY = y + minY;
                        if (roiTile.contains(dstX, dstY)) {
                            // Set the x,y destination pixel location
                            ptDst.setLocation(dstX, dstY);
                            // Map destination pixel to source pixel
                            transObj.transform(trans, ptDst, ptSrc);
                            // Source pixel indexes
                            int srcX = round(ptSrc.getX());
                            int srcY = round(ptSrc.getY());
                            // Check if the pixel is inside the source dimension
                            if (srcX < srcMinX || srcX >= srcMaxX || srcY < srcMinY
                                    || srcY >= srcMaxY) {
                                // Cycle on the bands
                                for (int sb = 0; sb < snbands[sindex]; sb++) {
                                    if (db >= dnbands) {
                                        // exceeding destNumBands; should not have happened
                                        break;
                                    }
                                    // Setting the no data value
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataByte;
                                }
                            } else {
                                // Cycle on the bands
                                for (int sb = 0; sb < snbands[sindex]; sb++) {
                                    if (db >= dnbands) {
                                        // exceeding destNumBands; should not have happened
                                        break;
                                    }
                                    // Setting the value
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = (byte) (iter
                                            .getSample(srcX, srcY, sb) & 0xFF);
                                }
                            }
                        } else {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                // Setting the no data value
                                dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataByte;
                            }
                        }
                        dstPixelOffset += dstPixelStride;
                    }
                    dstLineOffset += dstLineStride;
                }
                db += snbands[sindex];
            }
            // Only NoData
        } else if (caseC) {

            // Cycle on all the sources
            for (int sindex = 0; sindex < nSrcs; sindex++) {

                // Random Iterator for cycling on the sources
                iter = RandomIterFactory.create(sources[sindex], sources[sindex].getBounds());
                // Affine transformation for the selected source
                AffineTransform trans = transforms.get(sindex);
                TRANSFORM transObj = transformObj.get(sindex);
                // Source corners
                final int srcMinX = sources[sindex].getMinX();
                final int srcMinY = sources[sindex].getMinY();
                final int srcMaxX = sources[sindex].getMaxX();
                final int srcMaxY = sources[sindex].getMaxY();
                // Destination Line and Pixel offset initialization
                int dstLineOffset = 0;
                int dstPixelOffset = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++) {
                    dstPixelOffset = dstLineOffset;
                    // Cycle on the x-axis
                    for (int x = 0; x < destRect.width; x++) {
                        // Set the x,y destination pixel location
                        ptDst.setLocation(x + minX, y + minY);
                        // Map destination pixel to source pixel
                        transObj.transform(trans, ptDst, ptSrc);
                        // Source pixel indexes
                        int srcX = round(ptSrc.getX());
                        int srcY = round(ptSrc.getY());
                        // Check if the pixel is inside the source dimension
                        if (srcX < srcMinX || srcX >= srcMaxX || srcY < srcMinY || srcY >= srcMaxY) {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }
                                // Setting the no data value
                                dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataByte;
                            }
                        } else {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }
                                // No Data control
                                byte pixelValue = (byte) (iter.getSample(srcX, srcY, sb) & 0xFF);
                                if (noData[sindex].contains(pixelValue)) {
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataByte;
                                } else {
                                    // Setting the value
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = pixelValue;
                                }
                            }
                        }
                        dstPixelOffset += dstPixelStride;
                    }
                    dstLineOffset += dstLineStride;
                }
                db += snbands[sindex];
            }
            // NoData and ROI
        } else {
            // Cycle on all the sources
            for (int sindex = 0; sindex < nSrcs; sindex++) {
                // Random Iterator for cycling on the sources
                iter = RandomIterFactory.create(sources[sindex], sources[sindex].getBounds());
                // Affine transformation for the selected source
                AffineTransform trans = transforms.get(sindex);
                TRANSFORM transObj = transformObj.get(sindex);
                // Source corners
                final int srcMinX = sources[sindex].getMinX();
                final int srcMinY = sources[sindex].getMinY();
                final int srcMaxX = sources[sindex].getMaxX();
                final int srcMaxY = sources[sindex].getMaxY();
                // Destination Line and Pixel offset initialization
                int dstLineOffset = 0;
                int dstPixelOffset = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++) {
                    dstPixelOffset = dstLineOffset;
                    // Cycle on the x-axis
                    for (int x = 0; x < destRect.width; x++) {
                        // ROI check
                        int dstX = x + minX;
                        int dstY = y + minY;
                        if (roiTile.contains(dstX, dstY)) {
                            // Set the x,y destination pixel location
                            ptDst.setLocation(dstX, dstY);
                            // Map destination pixel to source pixel
                            transObj.transform(trans, ptDst, ptSrc);
                            // Source pixel indexes
                            int srcX = round(ptSrc.getX());
                            int srcY = round(ptSrc.getY());
                            // Check if the pixel is inside the source dimension
                            if (srcX < srcMinX || srcX >= srcMaxX || srcY < srcMinY
                                    || srcY >= srcMaxY) {
                                // Cycle on the bands
                                for (int sb = 0; sb < snbands[sindex]; sb++) {
                                    if (db >= dnbands) {
                                        // exceeding destNumBands; should not have happened
                                        break;
                                    }
                                    // Setting the no data value
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataByte;
                                }
                            } else {
                                // Cycle on the bands
                                for (int sb = 0; sb < snbands[sindex]; sb++) {
                                    if (db >= dnbands) {
                                        // exceeding destNumBands; should not have happened
                                        break;
                                    }
                                    // No Data control
                                    byte pixelValue = (byte) (iter.getSample(srcX, srcY, sb) & 0xFF);
                                    if (noData[sindex].contains(pixelValue)) {
                                        dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataByte;
                                    } else {
                                        // Setting the value
                                        dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = pixelValue;
View Full Code Here

        short[][] dstdata = (short[][]) dimd.data;

        int dstPixelStride = dimd.pixelStride;
        int dstLineStride = dimd.lineStride;

        RandomIter iter;
        // Source and Destination Point2D objects
        Point2D ptSrc = new Point2D.Double(0, 0);
        Point2D ptDst = new Point2D.Double(0, 0);
        // Destination object initial position
        final int minX = destRect.x;
        final int minY = destRect.y;

        int db = 0;

        // Only valid data
        if (caseA) {
            // Cycle on all the sources
            for (int sindex = 0; sindex < nSrcs; sindex++) {
                // Random Iterator for cycling on the sources
                iter = RandomIterFactory.create(sources[sindex], sources[sindex].getBounds());
                // Affine transformation for the selected source
                AffineTransform trans = transforms.get(sindex);
                TRANSFORM transObj = transformObj.get(sindex);
                // Source corners
                final int srcMinX = sources[sindex].getMinX();
                final int srcMinY = sources[sindex].getMinY();
                final int srcMaxX = sources[sindex].getMaxX();
                final int srcMaxY = sources[sindex].getMaxY();
                // Destination Line and Pixel offset initialization
                int dstLineOffset = 0;
                int dstPixelOffset = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++) {
                    dstPixelOffset = dstLineOffset;
                    // Cycle on the x-axis
                    for (int x = 0; x < destRect.width; x++) {
                        // Set the x,y destination pixel location
                        ptDst.setLocation(x + minX, y + minY);
                        // Map destination pixel to source pixel
                        transObj.transform(trans, ptDst, ptSrc);
                        // Source pixel indexes
                        int srcX = round(ptSrc.getX());
                        int srcY = round(ptSrc.getY());
                        // Check if the pixel is inside the source dimension
                        if (srcX < srcMinX || srcX >= srcMaxX || srcY < srcMinY || srcY >= srcMaxY) {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }
                                // Setting the no data value
                                dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataShort;
                            }
                        } else {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }
                                // Setting the value
                                dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = (short) (iter
                                        .getSample(srcX, srcY, sb));
                            }
                        }
                        dstPixelOffset += dstPixelStride;
                    }
                    dstLineOffset += dstLineStride;
                }
                db += snbands[sindex];
            }
            // Only ROI
        } else if (caseB) {
            // Cycle on all the sources
            for (int sindex = 0; sindex < nSrcs; sindex++) {
                // Random Iterator for cycling on the sources
                iter = RandomIterFactory.create(sources[sindex], sources[sindex].getBounds());
                // Affine transformation for the selected source
                AffineTransform trans = transforms.get(sindex);
                TRANSFORM transObj = transformObj.get(sindex);
                // Source corners
                final int srcMinX = sources[sindex].getMinX();
                final int srcMinY = sources[sindex].getMinY();
                final int srcMaxX = sources[sindex].getMaxX();
                final int srcMaxY = sources[sindex].getMaxY();
                // Destination Line and Pixel offset initialization
                int dstLineOffset = 0;
                int dstPixelOffset = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++) {
                    dstPixelOffset = dstLineOffset;
                    // Cycle on the x-axis
                    for (int x = 0; x < destRect.width; x++) {
                        // ROI check
                        int dstX = x + minX;
                        int dstY = y + minY;
                        if (roiTile.contains(dstX, dstY)) {
                            // Set the x,y destination pixel location
                            ptDst.setLocation(dstX, dstY);
                            // Map destination pixel to source pixel
                            transObj.transform(trans, ptDst, ptSrc);
                            // Source pixel indexes
                            int srcX = round(ptSrc.getX());
                            int srcY = round(ptSrc.getY());
                            // Check if the pixel is inside the source dimension
                            if (srcX < srcMinX || srcX >= srcMaxX || srcY < srcMinY
                                    || srcY >= srcMaxY) {
                                // Cycle on the bands
                                for (int sb = 0; sb < snbands[sindex]; sb++) {
                                    if (db >= dnbands) {
                                        // exceeding destNumBands; should not have happened
                                        break;
                                    }
                                    // Setting the no data value
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataShort;
                                }
                            } else {
                                // Cycle on the bands
                                for (int sb = 0; sb < snbands[sindex]; sb++) {
                                    if (db >= dnbands) {
                                        // exceeding destNumBands; should not have happened
                                        break;
                                    }
                                    // Setting the value
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = (short) (iter
                                            .getSample(srcX, srcY, sb));
                                }
                            }
                        } else {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                // Setting the no data value
                                dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataShort;
                            }
                        }
                        dstPixelOffset += dstPixelStride;
                    }
                    dstLineOffset += dstLineStride;
                }
                db += snbands[sindex];
            }
            // Only NoData
        } else if (caseC) {

            // Cycle on all the sources
            for (int sindex = 0; sindex < nSrcs; sindex++) {

                // Random Iterator for cycling on the sources
                iter = RandomIterFactory.create(sources[sindex], sources[sindex].getBounds());
                // Affine transformation for the selected source
                AffineTransform trans = transforms.get(sindex);
                TRANSFORM transObj = transformObj.get(sindex);
                // Source corners
                final int srcMinX = sources[sindex].getMinX();
                final int srcMinY = sources[sindex].getMinY();
                final int srcMaxX = sources[sindex].getMaxX();
                final int srcMaxY = sources[sindex].getMaxY();
                // Destination Line and Pixel offset initialization
                int dstLineOffset = 0;
                int dstPixelOffset = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++) {
                    dstPixelOffset = dstLineOffset;
                    // Cycle on the x-axis
                    for (int x = 0; x < destRect.width; x++) {
                        // Set the x,y destination pixel location
                        ptDst.setLocation(x + minX, y + minY);
                        // Map destination pixel to source pixel
                        transObj.transform(trans, ptDst, ptSrc);
                        // Source pixel indexes
                        int srcX = round(ptSrc.getX());
                        int srcY = round(ptSrc.getY());
                        // Check if the pixel is inside the source dimension
                        if (srcX < srcMinX || srcX >= srcMaxX || srcY < srcMinY || srcY >= srcMaxY) {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }
                                // Setting the no data value
                                dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataShort;
                            }
                        } else {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }
                                // No Data control
                                short pixelValue = (short) (iter.getSample(srcX, srcY, sb));
                                if (noData[sindex].contains(pixelValue)) {
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataShort;
                                } else {
                                    // Setting the value
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = pixelValue;
                                }
                            }
                        }
                        dstPixelOffset += dstPixelStride;
                    }
                    dstLineOffset += dstLineStride;
                }
                db += snbands[sindex];
            }
            // NoData and ROI
        } else {
            // Cycle on all the sources
            for (int sindex = 0; sindex < nSrcs; sindex++) {
                // Random Iterator for cycling on the sources
                iter = RandomIterFactory.create(sources[sindex], sources[sindex].getBounds());
                // Affine transformation for the selected source
                AffineTransform trans = transforms.get(sindex);
                TRANSFORM transObj = transformObj.get(sindex);
                // Source corners
                final int srcMinX = sources[sindex].getMinX();
                final int srcMinY = sources[sindex].getMinY();
                final int srcMaxX = sources[sindex].getMaxX();
                final int srcMaxY = sources[sindex].getMaxY();
                // Destination Line and Pixel offset initialization
                int dstLineOffset = 0;
                int dstPixelOffset = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++) {
                    dstPixelOffset = dstLineOffset;
                    // Cycle on the x-axis
                    for (int x = 0; x < destRect.width; x++) {
                        // ROI check
                        int dstX = x + minX;
                        int dstY = y + minY;
                        if (roiTile.contains(dstX, dstY)) {
                            // Set the x,y destination pixel location
                            ptDst.setLocation(dstX, dstY);
                            // Map destination pixel to source pixel
                            transObj.transform(trans, ptDst, ptSrc);
                            // Source pixel indexes
                            int srcX = round(ptSrc.getX());
                            int srcY = round(ptSrc.getY());
                            // Check if the pixel is inside the source dimension
                            if (srcX < srcMinX || srcX >= srcMaxX || srcY < srcMinY
                                    || srcY >= srcMaxY) {
                                // Cycle on the bands
                                for (int sb = 0; sb < snbands[sindex]; sb++) {
                                    if (db >= dnbands) {
                                        // exceeding destNumBands; should not have happened
                                        break;
                                    }
                                    // Setting the no data value
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataShort;
                                }
                            } else {
                                // Cycle on the bands
                                for (int sb = 0; sb < snbands[sindex]; sb++) {
                                    if (db >= dnbands) {
                                        // exceeding destNumBands; should not have happened
                                        break;
                                    }
                                    // No Data control
                                    short pixelValue = (short) (iter.getSample(srcX, srcY, sb));
                                    if (noData[sindex].contains(pixelValue)) {
                                        dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataShort;
                                    } else {
                                        // Setting the value
                                        dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = pixelValue;
View Full Code Here

        int[][] dstdata = (int[][]) dimd.data;

        int dstPixelStride = dimd.pixelStride;
        int dstLineStride = dimd.lineStride;

        RandomIter iter;
        // Source and Destination Point2D objects
        Point2D ptSrc = new Point2D.Double(0, 0);
        Point2D ptDst = new Point2D.Double(0, 0);
        // Destination object initial position
        final int minX = destRect.x;
        final int minY = destRect.y;

        int db = 0;

        // Only valid data
        if (caseA) {
            // Cycle on all the sources
            for (int sindex = 0; sindex < nSrcs; sindex++) {
                // Random Iterator for cycling on the sources
                iter = RandomIterFactory.create(sources[sindex], sources[sindex].getBounds());
                // Affine transformation for the selected source
                AffineTransform trans = transforms.get(sindex);
                TRANSFORM transObj = transformObj.get(sindex);
                // Source corners
                final int srcMinX = sources[sindex].getMinX();
                final int srcMinY = sources[sindex].getMinY();
                final int srcMaxX = sources[sindex].getMaxX();
                final int srcMaxY = sources[sindex].getMaxY();
                // Destination Line and Pixel offset initialization
                int dstLineOffset = 0;
                int dstPixelOffset = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++) {
                    dstPixelOffset = dstLineOffset;
                    // Cycle on the x-axis
                    for (int x = 0; x < destRect.width; x++) {
                        // Set the x,y destination pixel location
                        ptDst.setLocation(x + minX, y + minY);
                        // Map destination pixel to source pixel
                        transObj.transform(trans, ptDst, ptSrc);
                        // Source pixel indexes
                        int srcX = round(ptSrc.getX());
                        int srcY = round(ptSrc.getY());
                        // Check if the pixel is inside the source dimension
                        if (srcX < srcMinX || srcX >= srcMaxX || srcY < srcMinY || srcY >= srcMaxY) {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }
                                // Setting the no data value
                                dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataInt;
                            }
                        } else {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }
                                // Setting the value
                                dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = (iter
                                        .getSample(srcX, srcY, sb));
                            }
                        }
                        dstPixelOffset += dstPixelStride;
                    }
                    dstLineOffset += dstLineStride;
                }
                db += snbands[sindex];
            }
            // Only ROI
        } else if (caseB) {
            // Cycle on all the sources
            for (int sindex = 0; sindex < nSrcs; sindex++) {
                // Random Iterator for cycling on the sources
                iter = RandomIterFactory.create(sources[sindex], sources[sindex].getBounds());
                // Affine transformation for the selected source
                AffineTransform trans = transforms.get(sindex);
                TRANSFORM transObj = transformObj.get(sindex);
                // Source corners
                final int srcMinX = sources[sindex].getMinX();
                final int srcMinY = sources[sindex].getMinY();
                final int srcMaxX = sources[sindex].getMaxX();
                final int srcMaxY = sources[sindex].getMaxY();
                // Destination Line and Pixel offset initialization
                int dstLineOffset = 0;
                int dstPixelOffset = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++) {
                    dstPixelOffset = dstLineOffset;
                    // Cycle on the x-axis
                    for (int x = 0; x < destRect.width; x++) {
                        // ROI check
                        int dstX = x + minX;
                        int dstY = y + minY;
                        if (roiTile.contains(dstX, dstY)) {
                            // Set the x,y destination pixel location
                            ptDst.setLocation(dstX, dstY);
                            // Map destination pixel to source pixel
                            transObj.transform(trans, ptDst, ptSrc);
                            // Source pixel indexes
                            int srcX = round(ptSrc.getX());
                            int srcY = round(ptSrc.getY());
                            // Check if the pixel is inside the source dimension
                            if (srcX < srcMinX || srcX >= srcMaxX || srcY < srcMinY
                                    || srcY >= srcMaxY) {
                                // Cycle on the bands
                                for (int sb = 0; sb < snbands[sindex]; sb++) {
                                    if (db >= dnbands) {
                                        // exceeding destNumBands; should not have happened
                                        break;
                                    }
                                    // Setting the no data value
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataInt;
                                }
                            } else {
                                // Cycle on the bands
                                for (int sb = 0; sb < snbands[sindex]; sb++) {
                                    if (db >= dnbands) {
                                        // exceeding destNumBands; should not have happened
                                        break;
                                    }
                                    // Setting the value
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = (iter
                                            .getSample(srcX, srcY, sb));
                                }
                            }
                        } else {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                // Setting the no data value
                                dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataInt;
                            }
                        }
                        dstPixelOffset += dstPixelStride;
                    }
                    dstLineOffset += dstLineStride;
                }
                db += snbands[sindex];
            }
            // Only NoData
        } else if (caseC) {

            // Cycle on all the sources
            for (int sindex = 0; sindex < nSrcs; sindex++) {

                // Random Iterator for cycling on the sources
                iter = RandomIterFactory.create(sources[sindex], sources[sindex].getBounds());
                // Affine transformation for the selected source
                AffineTransform trans = transforms.get(sindex);
                TRANSFORM transObj = transformObj.get(sindex);
                // Source corners
                final int srcMinX = sources[sindex].getMinX();
                final int srcMinY = sources[sindex].getMinY();
                final int srcMaxX = sources[sindex].getMaxX();
                final int srcMaxY = sources[sindex].getMaxY();
                // Destination Line and Pixel offset initialization
                int dstLineOffset = 0;
                int dstPixelOffset = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++) {
                    dstPixelOffset = dstLineOffset;
                    // Cycle on the x-axis
                    for (int x = 0; x < destRect.width; x++) {
                        // Set the x,y destination pixel location
                        ptDst.setLocation(x + minX, y + minY);
                        // Map destination pixel to source pixel
                        transObj.transform(trans, ptDst, ptSrc);
                        // Source pixel indexes
                        int srcX = round(ptSrc.getX());
                        int srcY = round(ptSrc.getY());
                        // Check if the pixel is inside the source dimension
                        if (srcX < srcMinX || srcX >= srcMaxX || srcY < srcMinY || srcY >= srcMaxY) {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }
                                // Setting the no data value
                                dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataInt;
                            }
                        } else {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }
                                // No Data control
                                int pixelValue = (iter.getSample(srcX, srcY, sb));
                                if (noData[sindex].contains(pixelValue)) {
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataInt;
                                } else {
                                    // Setting the value
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = pixelValue;
                                }
                            }
                        }
                        dstPixelOffset += dstPixelStride;
                    }
                    dstLineOffset += dstLineStride;
                }
                db += snbands[sindex];
            }
            // NoData and ROI
        } else {
            // Cycle on all the sources
            for (int sindex = 0; sindex < nSrcs; sindex++) {
                // Random Iterator for cycling on the sources
                iter = RandomIterFactory.create(sources[sindex], sources[sindex].getBounds());
                // Affine transformation for the selected source
                AffineTransform trans = transforms.get(sindex);
                TRANSFORM transObj = transformObj.get(sindex);
                // Source corners
                final int srcMinX = sources[sindex].getMinX();
                final int srcMinY = sources[sindex].getMinY();
                final int srcMaxX = sources[sindex].getMaxX();
                final int srcMaxY = sources[sindex].getMaxY();
                // Destination Line and Pixel offset initialization
                int dstLineOffset = 0;
                int dstPixelOffset = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++) {
                    dstPixelOffset = dstLineOffset;
                    // Cycle on the x-axis
                    for (int x = 0; x < destRect.width; x++) {
                        // ROI check
                        int dstX = x + minX;
                        int dstY = y + minY;
                        if (roiTile.contains(dstX, dstY)) {
                            // Set the x,y destination pixel location
                            ptDst.setLocation(dstX, dstY);
                            // Map destination pixel to source pixel
                            transObj.transform(trans, ptDst, ptSrc);
                            // Source pixel indexes
                            int srcX = round(ptSrc.getX());
                            int srcY = round(ptSrc.getY());
                            // Check if the pixel is inside the source dimension
                            if (srcX < srcMinX || srcX >= srcMaxX || srcY < srcMinY
                                    || srcY >= srcMaxY) {
                                // Cycle on the bands
                                for (int sb = 0; sb < snbands[sindex]; sb++) {
                                    if (db >= dnbands) {
                                        // exceeding destNumBands; should not have happened
                                        break;
                                    }
                                    // Setting the no data value
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataInt;
                                }
                            } else {
                                // Cycle on the bands
                                for (int sb = 0; sb < snbands[sindex]; sb++) {
                                    if (db >= dnbands) {
                                        // exceeding destNumBands; should not have happened
                                        break;
                                    }
                                    // No Data control
                                    int pixelValue = (iter.getSample(srcX, srcY, sb));
                                    if (noData[sindex].contains(pixelValue)) {
                                        dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataInt;
                                    } else {
                                        // Setting the value
                                        dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = pixelValue;
View Full Code Here

        float[][] dstdata = (float[][]) dimd.data;

        int dstPixelStride = dimd.pixelStride;
        int dstLineStride = dimd.lineStride;

        RandomIter iter;
        // Source and Destination Point2D objects
        Point2D ptSrc = new Point2D.Double(0, 0);
        Point2D ptDst = new Point2D.Double(0, 0);
        // Destination object initial position
        final int minX = destRect.x;
        final int minY = destRect.y;

        int db = 0;

        // Only valid data
        if (caseA) {
            // Cycle on all the sources
            for (int sindex = 0; sindex < nSrcs; sindex++) {
                // Random Iterator for cycling on the sources
                iter = RandomIterFactory.create(sources[sindex], sources[sindex].getBounds());
                // Affine transformation for the selected source
                AffineTransform trans = transforms.get(sindex);
                TRANSFORM transObj = transformObj.get(sindex);
                // Source corners
                final int srcMinX = sources[sindex].getMinX();
                final int srcMinY = sources[sindex].getMinY();
                final int srcMaxX = sources[sindex].getMaxX();
                final int srcMaxY = sources[sindex].getMaxY();
                // Destination Line and Pixel offset initialization
                int dstLineOffset = 0;
                int dstPixelOffset = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++) {
                    dstPixelOffset = dstLineOffset;
                    // Cycle on the x-axis
                    for (int x = 0; x < destRect.width; x++) {
                        // Set the x,y destination pixel location
                        ptDst.setLocation(x + minX, y + minY);
                        // Map destination pixel to source pixel
                        transObj.transform(trans, ptDst, ptSrc);
                        // Source pixel indexes
                        int srcX = round(ptSrc.getX());
                        int srcY = round(ptSrc.getY());
                        // Check if the pixel is inside the source dimension
                        if (srcX < srcMinX || srcX >= srcMaxX || srcY < srcMinY || srcY >= srcMaxY) {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }
                                // Setting the no data value
                                dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataFloat;
                            }
                        } else {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }
                                // Setting the value
                                dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = (iter
                                        .getSampleFloat(srcX, srcY, sb));
                            }
                        }
                        dstPixelOffset += dstPixelStride;
                    }
                    dstLineOffset += dstLineStride;
                }
                db += snbands[sindex];
            }
            // Only ROI
        } else if (caseB) {
            // Cycle on all the sources
            for (int sindex = 0; sindex < nSrcs; sindex++) {
                // Random Iterator for cycling on the sources
                iter = RandomIterFactory.create(sources[sindex], sources[sindex].getBounds());
                // Affine transformation for the selected source
                AffineTransform trans = transforms.get(sindex);
                TRANSFORM transObj = transformObj.get(sindex);
                // Source corners
                final int srcMinX = sources[sindex].getMinX();
                final int srcMinY = sources[sindex].getMinY();
                final int srcMaxX = sources[sindex].getMaxX();
                final int srcMaxY = sources[sindex].getMaxY();
                // Destination Line and Pixel offset initialization
                int dstLineOffset = 0;
                int dstPixelOffset = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++) {
                    dstPixelOffset = dstLineOffset;
                    // Cycle on the x-axis
                    for (int x = 0; x < destRect.width; x++) {
                        // ROI check
                        int dstX = x + minX;
                        int dstY = y + minY;
                        if (roiTile.contains(dstX, dstY)) {
                            // Set the x,y destination pixel location
                            ptDst.setLocation(dstX, dstY);
                            // Map destination pixel to source pixel
                            transObj.transform(trans, ptDst, ptSrc);
                            // Source pixel indexes
                            int srcX = round(ptSrc.getX());
                            int srcY = round(ptSrc.getY());
                            // Check if the pixel is inside the source dimension
                            if (srcX < srcMinX || srcX >= srcMaxX || srcY < srcMinY
                                    || srcY >= srcMaxY) {
                                // Cycle on the bands
                                for (int sb = 0; sb < snbands[sindex]; sb++) {
                                    if (db >= dnbands) {
                                        // exceeding destNumBands; should not have happened
                                        break;
                                    }
                                    // Setting the no data value
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataFloat;
                                }
                            } else {
                                // Cycle on the bands
                                for (int sb = 0; sb < snbands[sindex]; sb++) {
                                    if (db >= dnbands) {
                                        // exceeding destNumBands; should not have happened
                                        break;
                                    }
                                    // Setting the value
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = (iter
                                            .getSampleFloat(srcX, srcY, sb));
                                }
                            }
                        } else {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                // Setting the no data value
                                dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataFloat;
                            }
                        }
                        dstPixelOffset += dstPixelStride;
                    }
                    dstLineOffset += dstLineStride;
                }
                db += snbands[sindex];
            }
            // Only NoData
        } else if (caseC) {

            // Cycle on all the sources
            for (int sindex = 0; sindex < nSrcs; sindex++) {

                // Random Iterator for cycling on the sources
                iter = RandomIterFactory.create(sources[sindex], sources[sindex].getBounds());
                // Affine transformation for the selected source
                AffineTransform trans = transforms.get(sindex);
                TRANSFORM transObj = transformObj.get(sindex);
                // Source corners
                final int srcMinX = sources[sindex].getMinX();
                final int srcMinY = sources[sindex].getMinY();
                final int srcMaxX = sources[sindex].getMaxX();
                final int srcMaxY = sources[sindex].getMaxY();
                // Destination Line and Pixel offset initialization
                int dstLineOffset = 0;
                int dstPixelOffset = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++) {
                    dstPixelOffset = dstLineOffset;
                    // Cycle on the x-axis
                    for (int x = 0; x < destRect.width; x++) {
                        // Set the x,y destination pixel location
                        ptDst.setLocation(x + minX, y + minY);
                        // Map destination pixel to source pixel
                        transObj.transform(trans, ptDst, ptSrc);
                        // Source pixel indexes
                        int srcX = round(ptSrc.getX());
                        int srcY = round(ptSrc.getY());
                        // Check if the pixel is inside the source dimension
                        if (srcX < srcMinX || srcX >= srcMaxX || srcY < srcMinY || srcY >= srcMaxY) {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }
                                // Setting the no data value
                                dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataFloat;
                            }
                        } else {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }
                                // No Data control
                                float pixelValue = (iter.getSampleFloat(srcX, srcY, sb));
                                if (noData[sindex].contains(pixelValue)) {
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataFloat;
                                } else {
                                    // Setting the value
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = pixelValue;
                                }
                            }
                        }
                        dstPixelOffset += dstPixelStride;
                    }
                    dstLineOffset += dstLineStride;
                }
                db += snbands[sindex];
            }
            // NoData and ROI
        } else {
            // Cycle on all the sources
            for (int sindex = 0; sindex < nSrcs; sindex++) {
                // Random Iterator for cycling on the sources
                iter = RandomIterFactory.create(sources[sindex], sources[sindex].getBounds());
                // Affine transformation for the selected source
                AffineTransform trans = transforms.get(sindex);
                TRANSFORM transObj = transformObj.get(sindex);
                // Source corners
                final int srcMinX = sources[sindex].getMinX();
                final int srcMinY = sources[sindex].getMinY();
                final int srcMaxX = sources[sindex].getMaxX();
                final int srcMaxY = sources[sindex].getMaxY();
                // Destination Line and Pixel offset initialization
                int dstLineOffset = 0;
                int dstPixelOffset = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++) {
                    dstPixelOffset = dstLineOffset;
                    // Cycle on the x-axis
                    for (int x = 0; x < destRect.width; x++) {
                        // ROI check
                        int dstX = x + minX;
                        int dstY = y + minY;
                        if (roiTile.contains(dstX, dstY)) {
                            // Set the x,y destination pixel location
                            ptDst.setLocation(dstX, dstY);
                            // Map destination pixel to source pixel
                            transObj.transform(trans, ptDst, ptSrc);
                            // Source pixel indexes
                            int srcX = round(ptSrc.getX());
                            int srcY = round(ptSrc.getY());
                            // Check if the pixel is inside the source dimension
                            if (srcX < srcMinX || srcX >= srcMaxX || srcY < srcMinY
                                    || srcY >= srcMaxY) {
                                // Cycle on the bands
                                for (int sb = 0; sb < snbands[sindex]; sb++) {
                                    if (db >= dnbands) {
                                        // exceeding destNumBands; should not have happened
                                        break;
                                    }
                                    // Setting the no data value
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataFloat;
                                }
                            } else {
                                // Cycle on the bands
                                for (int sb = 0; sb < snbands[sindex]; sb++) {
                                    if (db >= dnbands) {
                                        // exceeding destNumBands; should not have happened
                                        break;
                                    }
                                    // No Data control
                                    float pixelValue = (iter.getSampleFloat(srcX, srcY, sb));
                                    if (noData[sindex].contains(pixelValue)) {
                                        dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataFloat;
                                    } else {
                                        // Setting the value
                                        dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = pixelValue;
View Full Code Here

        double[][] dstdata = (double[][]) dimd.data;

        int dstPixelStride = dimd.pixelStride;
        int dstLineStride = dimd.lineStride;

        RandomIter iter;
        // Source and Destination Point2D objects
        Point2D ptSrc = new Point2D.Double(0, 0);
        Point2D ptDst = new Point2D.Double(0, 0);
        // Destination object initial position
        final int minX = destRect.x;
        final int minY = destRect.y;

        int db = 0;

        // Only valid data
        if (caseA) {
            // Cycle on all the sources
            for (int sindex = 0; sindex < nSrcs; sindex++) {
                // Random Iterator for cycling on the sources
                iter = RandomIterFactory.create(sources[sindex], sources[sindex].getBounds());
                // Affine transformation for the selected source
                AffineTransform trans = transforms.get(sindex);
                TRANSFORM transObj = transformObj.get(sindex);
                // Source corners
                final int srcMinX = sources[sindex].getMinX();
                final int srcMinY = sources[sindex].getMinY();
                final int srcMaxX = sources[sindex].getMaxX();
                final int srcMaxY = sources[sindex].getMaxY();
                // Destination Line and Pixel offset initialization
                int dstLineOffset = 0;
                int dstPixelOffset = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++) {
                    dstPixelOffset = dstLineOffset;
                    // Cycle on the x-axis
                    for (int x = 0; x < destRect.width; x++) {
                        // Set the x,y destination pixel location
                        ptDst.setLocation(x + minX, y + minY);
                        // Map destination pixel to source pixel
                        transObj.transform(trans, ptDst, ptSrc);
                        // Source pixel indexes
                        int srcX = round(ptSrc.getX());
                        int srcY = round(ptSrc.getY());
                        // Check if the pixel is inside the source dimension
                        if (srcX < srcMinX || srcX >= srcMaxX || srcY < srcMinY || srcY >= srcMaxY) {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }
                                // Setting the no data value
                                dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataDouble;
                            }
                        } else {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }
                                // Setting the value
                                dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = (iter
                                        .getSampleDouble(srcX, srcY, sb));
                            }
                        }
                        dstPixelOffset += dstPixelStride;
                    }
                    dstLineOffset += dstLineStride;
                }
                db += snbands[sindex];
            }
            // Only ROI
        } else if (caseB) {
            // Cycle on all the sources
            for (int sindex = 0; sindex < nSrcs; sindex++) {
                // Random Iterator for cycling on the sources
                iter = RandomIterFactory.create(sources[sindex], sources[sindex].getBounds());
                // Affine transformation for the selected source
                AffineTransform trans = transforms.get(sindex);
                TRANSFORM transObj = transformObj.get(sindex);
                // Source corners
                final int srcMinX = sources[sindex].getMinX();
                final int srcMinY = sources[sindex].getMinY();
                final int srcMaxX = sources[sindex].getMaxX();
                final int srcMaxY = sources[sindex].getMaxY();
                // Destination Line and Pixel offset initialization
                int dstLineOffset = 0;
                int dstPixelOffset = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++) {
                    dstPixelOffset = dstLineOffset;
                    // Cycle on the x-axis
                    for (int x = 0; x < destRect.width; x++) {
                        // ROI check
                        int dstX = x + minX;
                        int dstY = y + minY;
                        if (roiTile.contains(dstX, dstY)) {
                            // Set the x,y destination pixel location
                            ptDst.setLocation(dstX, dstY);
                            // Map destination pixel to source pixel
                            transObj.transform(trans, ptDst, ptSrc);
                            // Source pixel indexes
                            int srcX = round(ptSrc.getX());
                            int srcY = round(ptSrc.getY());
                            // Check if the pixel is inside the source dimension
                            if (srcX < srcMinX || srcX >= srcMaxX || srcY < srcMinY
                                    || srcY >= srcMaxY) {
                                // Cycle on the bands
                                for (int sb = 0; sb < snbands[sindex]; sb++) {
                                    if (db >= dnbands) {
                                        // exceeding destNumBands; should not have happened
                                        break;
                                    }
                                    // Setting the no data value
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataDouble;
                                }
                            } else {
                                // Cycle on the bands
                                for (int sb = 0; sb < snbands[sindex]; sb++) {
                                    if (db >= dnbands) {
                                        // exceeding destNumBands; should not have happened
                                        break;
                                    }
                                    // Setting the value
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = (iter
                                            .getSampleDouble(srcX, srcY, sb));
                                }
                            }
                        } else {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                // Setting the no data value
                                dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataDouble;
                            }
                        }
                        dstPixelOffset += dstPixelStride;
                    }
                    dstLineOffset += dstLineStride;
                }
                db += snbands[sindex];
            }
            // Only NoData
        } else if (caseC) {

            // Cycle on all the sources
            for (int sindex = 0; sindex < nSrcs; sindex++) {

                // Random Iterator for cycling on the sources
                iter = RandomIterFactory.create(sources[sindex], sources[sindex].getBounds());
                // Affine transformation for the selected source
                AffineTransform trans = transforms.get(sindex);
                TRANSFORM transObj = transformObj.get(sindex);
                // Source corners
                final int srcMinX = sources[sindex].getMinX();
                final int srcMinY = sources[sindex].getMinY();
                final int srcMaxX = sources[sindex].getMaxX();
                final int srcMaxY = sources[sindex].getMaxY();
                // Destination Line and Pixel offset initialization
                int dstLineOffset = 0;
                int dstPixelOffset = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++) {
                    dstPixelOffset = dstLineOffset;
                    // Cycle on the x-axis
                    for (int x = 0; x < destRect.width; x++) {
                        // Set the x,y destination pixel location
                        ptDst.setLocation(x + minX, y + minY);
                        // Map destination pixel to source pixel
                        transObj.transform(trans, ptDst, ptSrc);
                        // Source pixel indexes
                        int srcX = round(ptSrc.getX());
                        int srcY = round(ptSrc.getY());
                        // Check if the pixel is inside the source dimension
                        if (srcX < srcMinX || srcX >= srcMaxX || srcY < srcMinY || srcY >= srcMaxY) {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }
                                // Setting the no data value
                                dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataDouble;
                            }
                        } else {
                            // Cycle on the bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }
                                // No Data control
                                double pixelValue = (iter.getSampleDouble(srcX, srcY, sb));
                                if (noData[sindex].contains(pixelValue)) {
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataDouble;
                                } else {
                                    // Setting the value
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = pixelValue;
                                }
                            }
                        }
                        dstPixelOffset += dstPixelStride;
                    }
                    dstLineOffset += dstLineStride;
                }
                db += snbands[sindex];
            }
            // NoData and ROI
        } else {
            // Cycle on all the sources
            for (int sindex = 0; sindex < nSrcs; sindex++) {
                // Random Iterator for cycling on the sources
                iter = RandomIterFactory.create(sources[sindex], sources[sindex].getBounds());
                // Affine transformation for the selected source
                AffineTransform trans = transforms.get(sindex);
                TRANSFORM transObj = transformObj.get(sindex);
                // Source corners
                final int srcMinX = sources[sindex].getMinX();
                final int srcMinY = sources[sindex].getMinY();
                final int srcMaxX = sources[sindex].getMaxX();
                final int srcMaxY = sources[sindex].getMaxY();
                // Destination Line and Pixel offset initialization
                int dstLineOffset = 0;
                int dstPixelOffset = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++) {
                    dstPixelOffset = dstLineOffset;
                    // Cycle on the x-axis
                    for (int x = 0; x < destRect.width; x++) {
                        // ROI check
                        int dstX = x + minX;
                        int dstY = y + minY;
                        if (roiTile.contains(dstX, dstY)) {
                            // Set the x,y destination pixel location
                            ptDst.setLocation(dstX, dstY);
                            // Map destination pixel to source pixel
                            transObj.transform(trans, ptDst, ptSrc);
                            // Source pixel indexes
                            int srcX = round(ptSrc.getX());
                            int srcY = round(ptSrc.getY());
                            // Check if the pixel is inside the source dimension
                            if (srcX < srcMinX || srcX >= srcMaxX || srcY < srcMinY
                                    || srcY >= srcMaxY) {
                                // Cycle on the bands
                                for (int sb = 0; sb < snbands[sindex]; sb++) {
                                    if (db >= dnbands) {
                                        // exceeding destNumBands; should not have happened
                                        break;
                                    }
                                    // Setting the no data value
                                    dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataDouble;
                                }
                            } else {
                                // Cycle on the bands
                                for (int sb = 0; sb < snbands[sindex]; sb++) {
                                    if (db >= dnbands) {
                                        // exceeding destNumBands; should not have happened
                                        break;
                                    }
                                    // No Data control
                                    double pixelValue = (iter.getSampleDouble(srcX, srcY, sb));
                                    if (noData[sindex].contains(pixelValue)) {
                                        dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = destNoDataDouble;
                                    } else {
                                        // Setting the value
                                        dstdata[db + sb][dstPixelOffset + dimd.getOffset(db + sb)] = pixelValue;
View Full Code Here

        Point2D ptDst = new Point2D.Double(0, 0);
        Point2D ptSrc = new Point2D.Double(0, 0);

        // Cycle on all the tile Bands
        for (int b = 0; b < BAND_NUMBER; b++) {
            RandomIter iter = RandomIterFactory.create(translated[b], null);

            // Source corners
            final int srcMinX = translated[b].getMinX();
            final int srcMinY = translated[b].getMinY();
            final int srcMaxX = translated[b].getMaxX();
            final int srcMaxY = translated[b].getMaxY();

            // Cycle on the y-axis
            for (int x = minX; x < maxX; x++) {
                // Cycle on the x-axis
                for (int y = minY; y < maxY; y++) {
                    // Calculated value
                    double value = upperLeftTile.getSampleDouble(x, y, b);
                    // If the tile pixels are outside the image bounds, then no data is set.
                    if (x < dstMinX || x >= dstMaxX || y < dstMinY || y >= dstMaxY) {
                        value = destNoData;
                    }

                    // Set the x,y destination pixel location
                    ptDst.setLocation(x, y);
                    // Map destination pixel to source pixel
                    transform.get(b).transform(ptDst, ptSrc);
                    // Source pixel indexes
                    int srcX = round(ptSrc.getX());
                    int srcY = round(ptSrc.getY());

                    double valueOld = destNoData;

                    // Check if the pixel is inside the source bounds
                    if (!(srcX < srcMinX || srcX >= srcMaxX || srcY < srcMinY || srcY >= srcMaxY)) {
                        // Old band value
                        valueOld = iter.getSampleDouble(srcX, srcY, 0);
                    }

                    // ROI CHECK
                    boolean contained = true;
                    if (roiUsed) {
View Full Code Here

        } else {
            lpad = rpad = tpad = bpad = 0;
        }

        int minX, maxX, minY, maxY;
        RandomIter iter;
        if (extender != null) {
            minX = src.getMinX();
            maxX = src.getMaxX();
            minY = src.getMinY();
            maxY = src.getMaxY();
            iter = getRandomIterator(src, lpad, rpad, tpad, bpad, extender);
        } else {
            minX = src.getMinX() + lpad;
            maxX = src.getMaxX() - rpad;
            minY = src.getMinY() + tpad;
            maxY = src.getMaxY() - bpad;
            iter = getRandomIterator(src);
        }

        int kwidth = interp.getWidth();
        int kheight = interp.getHeight();

        int dstWidth = dst.getWidth();
        int dstHeight = dst.getHeight();
        int dstBands = dst.getNumBands();

        int lineStride = dst.getScanlineStride();
        int pixelStride = dst.getPixelStride();
        int[] bandOffsets = dst.getBandOffsets();
        byte[][] data = dst.getByteDataArrays();

        int precH = 1 << interp.getSubsampleBitsH();
        int precV = 1 << interp.getSubsampleBitsV();

        float[] warpData = new float[2 * dstWidth];

        int[][] samples = new int[kheight][kwidth];

        int lineOffset = 0;

        byte[] backgroundByte = new byte[dstBands];
        for (int i = 0; i < dstBands; i++) {
            backgroundByte[i] = (byte) backgroundValues[i];
        }

        if (ctable == null) { // source does not have IndexColorModel
            for (int h = 0; h < dstHeight; h++) {
                int pixelOffset = lineOffset;
                lineOffset += lineStride;

                // warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
                warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);

                int count = 0;
                for (int w = 0; w < dstWidth; w++) {
                    float sx = warpData[count++];
                    float sy = warpData[count++];

                    int xint = floor(sx);
                    int yint = floor(sy);
                    int xfrac = (int) ((sx - xint) * precH);
                    int yfrac = (int) ((sy - yint) * precV);

                    if (xint < minX || xint >= maxX || yint < minY || yint >= maxY) {
                        /* Fill with a background color. */
                        if (setBackground) {
                            for (int b = 0; b < dstBands; b++) {
                                data[b][pixelOffset + bandOffsets[b]] = backgroundByte[b];
                            }
                        }
                    } else {
                        xint -= lpad;
                        yint -= tpad;

                        for (int b = 0; b < dstBands; b++) {
                            for (int j = 0; j < kheight; j++) {
                                for (int i = 0; i < kwidth; i++) {
                                    samples[j][i] = iter.getSample(xint + i, yint + j, b) & 0xFF;
                                }
                            }

                            data[b][pixelOffset + bandOffsets[b]] = ImageUtil.clampByte(interp
                                    .interpolate(samples, xfrac, yfrac));
                        }
                    }

                    pixelOffset += pixelStride;
                }
            }
        } else { // source has IndexColorModel
            for (int h = 0; h < dstHeight; h++) {
                int pixelOffset = lineOffset;
                lineOffset += lineStride;

                // warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
                warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);

                int count = 0;
                for (int w = 0; w < dstWidth; w++) {
                    float sx = warpData[count++];
                    float sy = warpData[count++];

                    int xint = floor(sx);
                    int yint = floor(sy);
                    int xfrac = (int) ((sx - xint) * precH);
                    int yfrac = (int) ((sy - yint) * precV);

                    if (xint < minX || xint >= maxX || yint < minY || yint >= maxY) {
                        /* Fill with a background color. */
                        if (setBackground) {
                            for (int b = 0; b < dstBands; b++) {
                                data[b][pixelOffset + bandOffsets[b]] = backgroundByte[b];
                            }
                        }
                    } else {
                        xint -= lpad;
                        yint -= tpad;

                        for (int b = 0; b < dstBands; b++) {
                            byte[] t = ctable[b];

                            for (int j = 0; j < kheight; j++) {
                                for (int i = 0; i < kwidth; i++) {
                                    samples[j][i] = t[iter.getSample(xint + i, yint + j, 0) & 0xFF] & 0xFF;
                                }
                            }

                            data[b][pixelOffset + bandOffsets[b]] = ImageUtil.clampByte(interp
                                    .interpolate(samples, xfrac, yfrac));
View Full Code Here

TOP

Related Classes of javax.media.jai.iterator.RandomIter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.