use of org.geotoolkit.storage.coverage.DefaultImageTile in project geotoolkit by Geomatys.
the class PyramidalModelStoreNDTest method getCoverageStore.
private DataStore getCoverageStore() throws Exception {
if (store != null) {
return store;
}
// create a small pyramid
store = createStore();
final WritableAggregate agg = (WritableAggregate) store;
final CoordinateReferenceSystem horizontal = CommonCRS.WGS84.normalizedGeographic();
final CoordinateReferenceSystem vertical = CommonCRS.Vertical.ELLIPSOIDAL.crs();
crs = new GeodeticObjectBuilder().addName("3dcrs").createCompoundCRS(horizontal, vertical);
final GenericName name = NamesExt.create("test");
ref = (T) agg.add(new DefiningGridCoverageResource(name));
// prepare expected colors
int color = 0;
for (int v = 0; v < CORNER_V.length; v++) {
colors[v][0] = new int[2][2];
colors[v][1] = new int[4][3];
colors[v][0][0][0] = color++;
colors[v][0][1][0] = color++;
colors[v][0][0][1] = color++;
colors[v][0][1][1] = color++;
colors[v][1][0][0] = color++;
colors[v][1][1][0] = color++;
colors[v][1][2][0] = color++;
colors[v][1][3][0] = color++;
colors[v][1][0][1] = color++;
colors[v][1][1][1] = color++;
colors[v][1][2][1] = color++;
colors[v][1][3][1] = color++;
colors[v][1][0][2] = color++;
colors[v][1][1][2] = color++;
colors[v][1][2][2] = color++;
colors[v][1][3][2] = color++;
}
final TileMatrixSet pyramid = (TileMatrixSet) ref.createTileMatrixSet(new DefiningTileMatrixSet(crs));
for (int v = 0; v < CORNER_V.length; v++) {
final TileMatrix mosaic_s0 = pyramid.createTileMatrix(new DefiningTileMatrix(null, createCorner(CORNER_LONG, CORNER_LAT, CORNER_V[v]), 1, new Dimension(10, 10), new Dimension(2, 2)));
final TileMatrix mosaic_s1 = pyramid.createTileMatrix(new DefiningTileMatrix(null, createCorner(CORNER_LONG, CORNER_LAT, CORNER_V[v]), 0.5, new Dimension(10, 10), new Dimension(4, 3)));
// insert tiles
mosaic_s0.writeTiles(Stream.of(new DefaultImageTile(createImage(colors[v][0][0][0]), 0, 0), new DefaultImageTile(createImage(colors[v][0][1][0]), 1, 0), new DefaultImageTile(createImage(colors[v][0][0][1]), 0, 1), new DefaultImageTile(createImage(colors[v][0][1][1]), 1, 1)), null);
mosaic_s1.writeTiles(Stream.of(new DefaultImageTile(createImage(colors[v][1][0][0]), 0, 0), new DefaultImageTile(createImage(colors[v][1][1][0]), 1, 0), new DefaultImageTile(createImage(colors[v][1][2][0]), 2, 0), new DefaultImageTile(createImage(colors[v][1][3][0]), 3, 0), new DefaultImageTile(createImage(colors[v][1][0][1]), 0, 1), new DefaultImageTile(createImage(colors[v][1][1][1]), 1, 1), new DefaultImageTile(createImage(colors[v][1][2][1]), 2, 1), new DefaultImageTile(createImage(colors[v][1][3][1]), 3, 1), new DefaultImageTile(createImage(colors[v][1][0][2]), 0, 2), new DefaultImageTile(createImage(colors[v][1][1][2]), 1, 2), new DefaultImageTile(createImage(colors[v][1][2][2]), 2, 2), new DefaultImageTile(createImage(colors[v][1][3][2]), 3, 2)), null);
}
crs = pyramid.getCoordinateReferenceSystem();
return store;
}
use of org.geotoolkit.storage.coverage.DefaultImageTile in project geotoolkit by Geomatys.
the class CachedTiledGridCoverageResourceTest method testNoBlockingCache.
/**
* Test cache do not ask for the same tile twice in none blocking mode.
*/
@Test
public void testNoBlockingCache() throws DataStoreException, InterruptedException {
final MockTiledGridCoverageResource parent = new MockTiledGridCoverageResource(Names.createLocalName(null, null, "test"));
final TileMatrixSet tileMatrixSet = (TileMatrixSet) parent.createTileMatrixSet(TileMatrices.createWorldWGS84Template(0));
final TileMatrix tileMatrix = tileMatrixSet.getTileMatrices().iterator().next();
final ImageTile it0 = new DefaultImageTile(new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB), 0, 0);
final ImageTile it1 = new DefaultImageTile(new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB), 1, 0);
tileMatrix.writeTiles(Stream.of(it0, it1), null);
Assert.assertEquals(4, parent.localEvents.size());
Assert.assertEquals(MockTiledGridCoverageResource.EventType.TILE_MATRIX_SET_CREATED, parent.localEvents.get(0).type);
Assert.assertEquals(MockTiledGridCoverageResource.EventType.TILE_MATRIX_CREATED, parent.localEvents.get(1).type);
Assert.assertEquals(MockTiledGridCoverageResource.EventType.TILE_SET, parent.localEvents.get(2).type);
Assert.assertEquals(MockTiledGridCoverageResource.EventType.TILE_SET, parent.localEvents.get(3).type);
parent.localEvents.clear();
final CachedTiledGridCoverageResource r = new CachedTiledGridCoverageResource(parent, 30, 60, true, true);
final TileMatrixSet cacheTms = (TileMatrixSet) r.getTileMatrixSets().iterator().next();
final TileMatrix cacheTm = cacheTms.getTileMatrices().iterator().next();
// get tile a first time, should put in a queue to returned later
cacheTm.getTile(0, 0);
Assert.assertEquals(0, parent.localEvents.size());
// wait a little for the non blocking queue
Thread.sleep(1000);
Assert.assertEquals(1, parent.localEvents.size());
// acces tile again, must be in cache
cacheTm.getTile(0, 0);
Assert.assertEquals(1, parent.localEvents.size());
// get another tile, should put in a queue and returned later
cacheTm.getTile(1, 0);
cacheTm.getTile(1, 0);
cacheTm.getTile(1, 0);
Assert.assertEquals(1, parent.localEvents.size());
// wait a little for the non blocking queue
Thread.sleep(1000);
Assert.assertEquals(2, parent.localEvents.size());
// acces tiles again, must be in cache
cacheTm.getTile(0, 0);
cacheTm.getTile(1, 0);
Assert.assertEquals(2, parent.localEvents.size());
}
use of org.geotoolkit.storage.coverage.DefaultImageTile in project geotoolkit by Geomatys.
the class CachedTiledGridCoverageResourceTest method testUpdate.
/**
* Test cache pyramid updates it's structure and clear it's cache on parent update.
*/
@Test
public void testUpdate() throws DataStoreException {
final InMemoryTiledGridCoverageResource parent = new InMemoryTiledGridCoverageResource(Names.createLocalName(null, null, "test"));
final CachedTiledGridCoverageResource r = new CachedTiledGridCoverageResource(parent, 30, 60, true);
final List<StoreEvent> events = new ArrayList<>();
r.addListener(StoreEvent.class, new StoreListener<StoreEvent>() {
@Override
public void eventOccured(StoreEvent event) {
events.add(event);
}
});
// change parent structure
final TileMatrixSet tileMatrixSet = (TileMatrixSet) parent.createTileMatrixSet(TileMatrices.createWorldWGS84Template(1));
Assert.assertEquals(1, events.size());
events.clear();
// write a new tile
final TileMatrix tileMatrix = tileMatrixSet.getTileMatrices().iterator().next();
final ImageTile it = new DefaultImageTile(new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB), 0, 0);
tileMatrix.writeTiles(Stream.of(it), null);
Assert.assertEquals(1, events.size());
events.clear();
// update existing tile
final ImageTile it2 = new DefaultImageTile(new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB), 0, 0);
tileMatrix.writeTiles(Stream.of(it2), null);
Assert.assertEquals(1, events.size());
events.clear();
}
use of org.geotoolkit.storage.coverage.DefaultImageTile in project geotoolkit by Geomatys.
the class CachedTiledGridCoverageResourceTest method testBlockingCache.
/**
* Test cache do not ask for the same tile twice.
*/
@Test
public void testBlockingCache() throws DataStoreException {
final MockTiledGridCoverageResource parent = new MockTiledGridCoverageResource(Names.createLocalName(null, null, "test"));
final TileMatrixSet tileMatrixSet = (TileMatrixSet) parent.createTileMatrixSet(TileMatrices.createWorldWGS84Template(0));
final TileMatrix tileMatrix = tileMatrixSet.getTileMatrices().iterator().next();
final ImageTile it0 = new DefaultImageTile(new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB), 0, 0);
final ImageTile it1 = new DefaultImageTile(new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB), 1, 0);
tileMatrix.writeTiles(Stream.of(it0, it1), null);
Assert.assertEquals(4, parent.localEvents.size());
Assert.assertEquals(MockTiledGridCoverageResource.EventType.TILE_MATRIX_SET_CREATED, parent.localEvents.get(0).type);
Assert.assertEquals(MockTiledGridCoverageResource.EventType.TILE_MATRIX_CREATED, parent.localEvents.get(1).type);
Assert.assertEquals(MockTiledGridCoverageResource.EventType.TILE_SET, parent.localEvents.get(2).type);
Assert.assertEquals(MockTiledGridCoverageResource.EventType.TILE_SET, parent.localEvents.get(3).type);
parent.localEvents.clear();
final CachedTiledGridCoverageResource r = new CachedTiledGridCoverageResource(parent, 30, 60, true);
final TileMatrixSet cacheTms = (TileMatrixSet) r.getTileMatrixSets().iterator().next();
final TileMatrix cacheTm = cacheTms.getTileMatrices().iterator().next();
// get tile a first time, should be grabbed from the main resource
cacheTm.getTile(0, 0);
Assert.assertEquals(1, parent.localEvents.size());
// acces tile again, must be in cache
cacheTm.getTile(0, 0);
Assert.assertEquals(1, parent.localEvents.size());
// get tile a first time, should be grabbed from the main resource
cacheTm.getTile(1, 0);
Assert.assertEquals(2, parent.localEvents.size());
// acces tiles again, must be in cache
cacheTm.getTile(0, 0);
cacheTm.getTile(1, 0);
Assert.assertEquals(2, parent.localEvents.size());
}
use of org.geotoolkit.storage.coverage.DefaultImageTile in project geotoolkit by Geomatys.
the class PGPyramidTest method testInsertUpdateDelete.
@Test
public void testInsertUpdateDelete() throws DataStoreException, VersioningException, IOException {
reload();
final GeneralDirectPosition upperLeft = new GeneralDirectPosition(CommonCRS.WGS84.geographic());
final Dimension dimension = new Dimension(20, 20);
upperLeft.setOrdinate(0, -90);
upperLeft.setOrdinate(1, +180);
PyramidalCoverageResource cref;
Pyramid pyramid;
Mosaic mosaic;
RenderedImage image;
final GenericName name = NamesExt.create(null, "versLayer");
store.add(new DefiningCoverageResource(name));
// create version 1 -----------------------------------------------------
cref = (PyramidalCoverageResource) store.findResource(name.toString());
assertNotNull(cref);
// test create pyramid
pyramid = (Pyramid) cref.createModel(new DefiningPyramid(CommonCRS.WGS84.geographic()));
assertEquals(1, cref.getModels().size());
// test create mosaic
mosaic = pyramid.createMosaic(new DefiningMosaic(null, upperLeft, 1, dimension, new Dimension(1, 4)));
pyramid = Pyramids.getPyramid(cref, pyramid.getIdentifier());
assertEquals(1, pyramid.getMosaics().size());
// test insert tile
mosaic.writeTiles(Stream.of(new DefaultImageTile(createImage(dimension, Color.RED), new Point(0, 0)), new DefaultImageTile(createImage(dimension, Color.GREEN), new Point(0, 1)), new DefaultImageTile(createImage(dimension, Color.BLUE), new Point(0, 2)), new DefaultImageTile(createImage(dimension, Color.YELLOW), new Point(0, 3))), null);
image = ((ImageTile) mosaic.getTile(0, 0)).getImage();
assertImageColor(image, Color.RED);
image = ((ImageTile) mosaic.getTile(0, 1)).getImage();
assertImageColor(image, Color.GREEN);
image = ((ImageTile) mosaic.getTile(0, 2)).getImage();
assertImageColor(image, Color.BLUE);
image = ((ImageTile) mosaic.getTile(0, 3)).getImage();
assertImageColor(image, Color.YELLOW);
// test delete tile
mosaic.deleteTile(0, 1);
assertNotNull(((ImageTile) mosaic.getTile(0, 2)).getInput());
mosaic.deleteTile(0, 2);
assertNull(((ImageTile) mosaic.getTile(0, 2)).getInput());
// test update tile
mosaic.writeTiles(Stream.of(new DefaultImageTile(createImage(dimension, Color.PINK), new Point(0, 3))), null);
image = ((ImageTile) mosaic.getTile(0, 3)).getImageReader().read(3);
assertImageColor(image, Color.PINK);
// test delete mosaic
pyramid.deleteMosaic(mosaic.getIdentifier());
pyramid = Pyramids.getPyramid(cref, pyramid.getIdentifier());
assertTrue(pyramid.getMosaics().isEmpty());
// test delete pyramid
cref.removeModel(pyramid.getIdentifier());
assertTrue(cref.getModels().isEmpty());
}
Aggregations