Search in sources :

Example 1 with TiledImageMock

use of org.apache.sis.image.TiledImageMock in project sis by apache.

the class CoverageCanvasApp method createImage.

/**
 * Creates a dummy image for testing purpose. Some tiles will
 * have artificial errors in order to see the error controls.
 */
private static GridCoverage2D createImage() {
    final Random random = new Random();
    final int width = TILE_WIDTH * 4;
    final int height = TILE_HEIGHT * 2;
    final TiledImageMock image = new TiledImageMock(DataBuffer.TYPE_BYTE, 1, // minX
    random.nextInt(50) - 25, // minY
    random.nextInt(50) - 25, width, height, TILE_WIDTH, TILE_HEIGHT, // minTileX
    random.nextInt(10) - 5, // minTileY
    random.nextInt(10) - 5, false);
    image.validate();
    final double sc = 500d / Math.max(width, height);
    final WritablePixelIterator it = WritablePixelIterator.create(image);
    while (it.next()) {
        final Point p = it.getPosition();
        final double d = Math.hypot(p.x - width / 2, p.y - height / 2);
        int value = 0;
        if ((Math.round(d) & 16) == 0) {
            value = Math.max(0, 255 - (int) (d * sc));
        }
        it.setSample(0, value);
    }
    image.failRandomly(random, false);
    return new GridCoverage2D(new GridGeometry(null, PixelInCell.CELL_CORNER, MathTransforms.identity(2), CommonCRS.Engineering.DISPLAY.crs()), null, image);
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) GridCoverage2D(org.apache.sis.coverage.grid.GridCoverage2D) Random(java.util.Random) WritablePixelIterator(org.apache.sis.image.WritablePixelIterator) TiledImageMock(org.apache.sis.image.TiledImageMock) Point(java.awt.Point) Point(java.awt.Point)

Example 2 with TiledImageMock

use of org.apache.sis.image.TiledImageMock in project sis by apache.

the class GridViewApp method createImage.

/**
 * Creates a dummy image for testing purpose. Some tiles will
 * have artificial errors in order to see the error controls.
 */
private static TiledImageMock createImage() {
    final TiledImageMock image = new TiledImageMock(DataBuffer.TYPE_USHORT, 1, // minX
    -50, // minY
    70, // width
    TILE_WIDTH * 30, // height
    TILE_HEIGHT * 25, TILE_WIDTH, TILE_HEIGHT, // minTileX
    3, // minTileY
    -5, false);
    image.validate();
    image.initializeAllTiles(0);
    image.failRandomly(new Random(), true);
    return image;
}
Also used : Random(java.util.Random) TiledImageMock(org.apache.sis.image.TiledImageMock)

Example 3 with TiledImageMock

use of org.apache.sis.image.TiledImageMock in project sis by apache.

the class ReshapedImageTest method testMultiTiles.

/**
 * Tests wrapping a {@link TiledImageMock}.
 */
@Test
public void testMultiTiles() {
    final Random random = TestUtilities.createRandomNumberGenerator(219970242558564L);
    final int dataMinX, dataMinY;
    dataMinX = random.nextInt(20) - 10;
    dataMinY = random.nextInt(20) - 10;
    minTileX = random.nextInt(20) - 10;
    minTileY = random.nextInt(20) - 10;
    numXTiles = 5;
    numYTiles = 4;
    width = numXTiles * TILE_WIDTH;
    height = numYTiles * TILE_HEIGHT;
    final TiledImageMock data = new TiledImageMock(DataBuffer.TYPE_USHORT, 1, dataMinX, dataMinY, width, height, TILE_WIDTH, TILE_HEIGHT, minTileX, minTileY, // Banded or interleaved sample model
    random.nextBoolean());
    data.validate();
    data.initializeAllTiles(0);
    /*
         * Apply only a translation, keep all tiles.
         */
    tileXOffset = (minX = 7) - minTileX * TILE_WIDTH;
    tileYOffset = (minY = 13) - minTileY * TILE_HEIGHT;
    ReshapedImage image = new ReshapedImage(data, dataMinX - 7, dataMinY - 13, 100, 100);
    verifyLayout(image);
    assertValuesEqual(image.getData(), 0, new int[][] { { 100, 101, 102, 200, 201, 202, 300, 301, 302, 400, 401, 402, 500, 501, 502 }, { 110, 111, 112, 210, 211, 212, 310, 311, 312, 410, 411, 412, 510, 511, 512 }, { 600, 601, 602, 700, 701, 702, 800, 801, 802, 900, 901, 902, 1000, 1001, 1002 }, { 610, 611, 612, 710, 711, 712, 810, 811, 812, 910, 911, 912, 1010, 1011, 1012 }, { 1100, 1101, 1102, 1200, 1201, 1202, 1300, 1301, 1302, 1400, 1401, 1402, 1500, 1501, 1502 }, { 1110, 1111, 1112, 1210, 1211, 1212, 1310, 1311, 1312, 1410, 1411, 1412, 1510, 1511, 1512 }, { 1600, 1601, 1602, 1700, 1701, 1702, 1800, 1801, 1802, 1900, 1901, 1902, 2000, 2001, 2002 }, { 1610, 1611, 1612, 1710, 1711, 1712, 1810, 1811, 1812, 1910, 1911, 1912, 2010, 2011, 2012 } });
    /*
         * Ask for a subregion of the image. The subregion starts at (5,3) and ends at (9,5) inclusive.
         * ReshapedImageTest shall expand to an integer number of tiles, which result in (3,2) - (11,5).
         * This is 3×2 tiles.
         */
    // Skip one tile on the left.
    minTileX++;
    // Skip one tile on the bottom.
    minTileY++;
    width = (numXTiles = 3) * TILE_WIDTH;
    height = (numYTiles = 2) * TILE_HEIGHT;
    tileXOffset = (minX = -2) - minTileX * TILE_WIDTH;
    tileYOffset = (minY = -1) - minTileY * TILE_HEIGHT;
    image = new ReshapedImage(data, dataMinX + 5, dataMinY + 3, dataMinX + 9, dataMinY + 5);
    verifyLayout(image);
    assertValuesEqual(image.getData(), 0, new int[][] { { 700, 701, 702, 800, 801, 802, 900, 901, 902 }, { 710, 711, 712, 810, 811, 812, 910, 911, 912 }, { 1200, 1201, 1202, 1300, 1301, 1302, 1400, 1401, 1402 }, { 1210, 1211, 1212, 1310, 1311, 1312, 1410, 1411, 1412 } });
}
Also used : Random(java.util.Random) TiledImageMock(org.apache.sis.image.TiledImageMock) Test(org.junit.Test)

Example 4 with TiledImageMock

use of org.apache.sis.image.TiledImageMock in project sis by apache.

the class ResampledGridCoverageTest method createCoverage2D.

/**
 * Creates a small grid coverage with arbitrary data. The rendered image will
 * have only one tile since testing tiling is not the purpose of this class.
 * This simple coverage is two-dimensional.
 */
private GridCoverage2D createCoverage2D() {
    random = TestUtilities.createRandomNumberGenerator();
    final int width = random.nextInt(8) + 3;
    final int height = random.nextInt(8) + 3;
    final TiledImageMock image = new TiledImageMock(// dataType and numBands
    DataBuffer.TYPE_USHORT, // dataType and numBands
    2, // minX (no effect on tests)
    random.nextInt(32) - 10, // minY (no effect on tests)
    random.nextInt(32) - 10, // Image size
    width, // Image size
    height, // Tile size
    width, // Tile size
    height, // minTileX
    random.nextInt(32) - 10, // minTileY
    random.nextInt(32) - 10, // Banded or interleaved sample model
    random.nextBoolean());
    image.validate();
    image.initializeAllTiles(0);
    final int x = random.nextInt(32) - 10;
    final int y = random.nextInt(32) - 10;
    final GridGeometry gg = new GridGeometry(new GridExtent(null, new long[] { x, y }, new long[] { x + width, y + height }, false), new Envelope2D(HardCodedCRS.WGS84, 20, 15, 60, 62), GridOrientation.HOMOTHETY);
    return new GridCoverage2D(gg, null, image);
}
Also used : TiledImageMock(org.apache.sis.image.TiledImageMock) Envelope2D(org.apache.sis.geometry.Envelope2D)

Aggregations

TiledImageMock (org.apache.sis.image.TiledImageMock)4 Random (java.util.Random)3 Point (java.awt.Point)1 GridCoverage2D (org.apache.sis.coverage.grid.GridCoverage2D)1 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)1 Envelope2D (org.apache.sis.geometry.Envelope2D)1 WritablePixelIterator (org.apache.sis.image.WritablePixelIterator)1 Test (org.junit.Test)1