@Test public void testGenerateMissingMipmapFiles() throws Exception { final MipmapClient.Parameters parameters = new MipmapClient.Parameters(); parameters.mipmap.rootDirectory = mipmapRootDirectory.getAbsolutePath(); parameters.mipmap.maxLevel = 2; MipmapClient mipmapClient = new MipmapClient(parameters.renderWeb, parameters.mipmap); final ImageAndMask sourceImageAndMask = new ImageAndMask("src/test/resources/col0060_row0140_cam0.tif", "src/test/resources/mask.tif"); final TileSpec tileSpec = new TileSpec(); tileSpec.setTileId("test-mipmap-tile"); final ChannelSpec channelSpec = new ChannelSpec(); channelSpec.putMipmap(0, sourceImageAndMask); tileSpec.addChannel(channelSpec); tileSpec.setMipmapPathBuilder(mipmapClient.getMipmapPathBuilder()); mipmapClient.generateMissingMipmapFiles(tileSpec); ImageProcessor imageProcessor = MipmapClient.loadImageProcessor(sourceImageAndMask.getImageUrl()); int expectedWidth; int expectedHeight; Map.Entry<Integer, ImageAndMask> mipmapEntry = null; ImageAndMask imageAndMask = null; String url; int level; for (level = 1; level < 3; level++) { expectedWidth = imageProcessor.getWidth() / 2; expectedHeight = imageProcessor.getHeight() / 2; mipmapEntry = channelSpec.getFloorMipmapEntry(level); imageAndMask = mipmapEntry.getValue(); url = imageAndMask.getImageUrl(); imageProcessor = MipmapClient.loadImageProcessor(url); Assert.assertEquals("invalid width for level " + level + " image " + url, expectedWidth, imageProcessor.getWidth()); Assert.assertEquals("invalid height for level " + level + " image " + url, expectedHeight, imageProcessor.getHeight()); url = imageAndMask.getMaskUrl(); imageProcessor = MipmapClient.loadImageProcessor(url); Assert.assertEquals("invalid width for level " + level + " mask " + url, expectedWidth, imageProcessor.getWidth()); Assert.assertEquals("invalid height for level " + level + " mask " + url, expectedHeight, imageProcessor.getHeight()); } final Map.Entry<Integer, ImageAndMask> floor3Entry = channelSpec.getFloorMipmapEntry(level); Assert.assertEquals("invalid level returned for floor of non-existent level", mipmapEntry.getKey(), floor3Entry.getKey()); final File previouslyGeneratedImageFile = new File(imageAndMask.getImageFilePath()); final long expectedLastModified = previouslyGeneratedImageFile.lastModified(); parameters.mipmap.rootDirectory = mipmapRootDirectory.getAbsolutePath(); parameters.mipmap.maxLevel = level; mipmapClient = new MipmapClient(parameters.renderWeb, parameters.mipmap); tileSpec.setMipmapPathBuilder(mipmapClient.getMipmapPathBuilder()); mipmapClient.generateMissingMipmapFiles(tileSpec); expectedWidth = imageProcessor.getWidth() / 2; expectedHeight = imageProcessor.getHeight() / 2; mipmapEntry = channelSpec.getFloorMipmapEntry(level); imageAndMask = mipmapEntry.getValue(); url = imageAndMask.getImageUrl(); imageProcessor = MipmapClient.loadImageProcessor(url); Assert.assertEquals("invalid width for level " + level + " image " + url, expectedWidth, imageProcessor.getWidth()); Assert.assertEquals("invalid height for level " + level + " image " + url, expectedHeight, imageProcessor.getHeight()); url = imageAndMask.getMaskUrl(); imageProcessor = MipmapClient.loadImageProcessor(url); Assert.assertEquals("invalid width for level " + level + " mask " + url, expectedWidth, imageProcessor.getWidth()); Assert.assertEquals("invalid height for level " + level + " mask " + url, expectedHeight, imageProcessor.getHeight()); Assert.assertEquals("image file " + previouslyGeneratedImageFile.getAbsolutePath() + " should NOT have been regenerated", expectedLastModified, previouslyGeneratedImageFile.lastModified()); }
void generateMissingMipmapFiles(final TileSpec tileSpec) throws IllegalArgumentException, IOException { for (final ChannelSpec channelSpec : tileSpec.getAllChannels()) { final String channelName = channelSpec.getName(); final String context; if (channelName == null) { context = "tile '" + tileSpec.getTileId() + "'"; } else { context = "channel '" + channelName + "' in tile '" + tileSpec.getTileId() + "'"; } final Map.Entry<Integer, ImageAndMask> firstEntry = channelSpec.getFirstMipmapEntry(); if (firstEntry == null) { throw new IllegalArgumentException("first entry mipmap is missing from " + context); } final ImageAndMask sourceImageAndMask = firstEntry.getValue(); if ((sourceImageAndMask == null) || (!sourceImageAndMask.hasImage())) { throw new IllegalArgumentException("first entry mipmap image is missing from " + context); } if (parameters.forceGeneration || isMissingMipmaps(channelSpec, firstEntry, sourceImageAndMask.hasMask())) { ImageProcessor sourceImageProcessor = loadImageProcessor(sourceImageAndMask.getImageUrl()); ImageProcessor sourceMaskProcessor = null; if (sourceImageAndMask.hasMask()) { sourceMaskProcessor = loadImageProcessor(sourceImageAndMask.getMaskUrl()); } Map.Entry<Integer, ImageAndMask> derivedEntry; ImageAndMask derivedImageAndMask; File imageMipmapFile; File maskMipmapFile; for (int mipmapLevel = 1; mipmapLevel <= mipmapPathBuilder.getNumberOfLevels(); mipmapLevel++) { derivedEntry = mipmapPathBuilder.deriveImageAndMask(mipmapLevel, firstEntry, false); derivedImageAndMask = derivedEntry.getValue(); if (! channelSpec.hasMipmap(mipmapLevel)) { final boolean isMipmapLevelInRange = mipmapLevel >= parameters.minLevel; if (isMipmapLevelInRange) { createMissingDirectories(derivedImageAndMask.getImageUrl()); } imageMipmapFile = getFileForUrlString(derivedImageAndMask.getImageUrl()); sourceImageProcessor = generateMipmapFile(sourceImageProcessor, imageMipmapFile, channelSpec.getMinIntensity(), channelSpec.getMaxIntensity(), isMipmapLevelInRange); if (sourceImageAndMask.hasMask()) { if (isMipmapLevelInRange) { createMissingDirectories(derivedImageAndMask.getMaskUrl()); } maskMipmapFile = getFileForUrlString(derivedImageAndMask.getMaskUrl()); sourceMaskProcessor = generateMipmapFile(sourceMaskProcessor, maskMipmapFile, channelSpec.getMinIntensity(), channelSpec.getMaxIntensity(), isMipmapLevelInRange); } } } } else { LOG.info("generateMissingMipmapFiles: all mipmap files exist for ", context); } } }
MipmapClient { void generateMissingMipmapFiles(final TileSpec tileSpec) throws IllegalArgumentException, IOException { for (final ChannelSpec channelSpec : tileSpec.getAllChannels()) { final String channelName = channelSpec.getName(); final String context; if (channelName == null) { context = "tile '" + tileSpec.getTileId() + "'"; } else { context = "channel '" + channelName + "' in tile '" + tileSpec.getTileId() + "'"; } final Map.Entry<Integer, ImageAndMask> firstEntry = channelSpec.getFirstMipmapEntry(); if (firstEntry == null) { throw new IllegalArgumentException("first entry mipmap is missing from " + context); } final ImageAndMask sourceImageAndMask = firstEntry.getValue(); if ((sourceImageAndMask == null) || (!sourceImageAndMask.hasImage())) { throw new IllegalArgumentException("first entry mipmap image is missing from " + context); } if (parameters.forceGeneration || isMissingMipmaps(channelSpec, firstEntry, sourceImageAndMask.hasMask())) { ImageProcessor sourceImageProcessor = loadImageProcessor(sourceImageAndMask.getImageUrl()); ImageProcessor sourceMaskProcessor = null; if (sourceImageAndMask.hasMask()) { sourceMaskProcessor = loadImageProcessor(sourceImageAndMask.getMaskUrl()); } Map.Entry<Integer, ImageAndMask> derivedEntry; ImageAndMask derivedImageAndMask; File imageMipmapFile; File maskMipmapFile; for (int mipmapLevel = 1; mipmapLevel <= mipmapPathBuilder.getNumberOfLevels(); mipmapLevel++) { derivedEntry = mipmapPathBuilder.deriveImageAndMask(mipmapLevel, firstEntry, false); derivedImageAndMask = derivedEntry.getValue(); if (! channelSpec.hasMipmap(mipmapLevel)) { final boolean isMipmapLevelInRange = mipmapLevel >= parameters.minLevel; if (isMipmapLevelInRange) { createMissingDirectories(derivedImageAndMask.getImageUrl()); } imageMipmapFile = getFileForUrlString(derivedImageAndMask.getImageUrl()); sourceImageProcessor = generateMipmapFile(sourceImageProcessor, imageMipmapFile, channelSpec.getMinIntensity(), channelSpec.getMaxIntensity(), isMipmapLevelInRange); if (sourceImageAndMask.hasMask()) { if (isMipmapLevelInRange) { createMissingDirectories(derivedImageAndMask.getMaskUrl()); } maskMipmapFile = getFileForUrlString(derivedImageAndMask.getMaskUrl()); sourceMaskProcessor = generateMipmapFile(sourceMaskProcessor, maskMipmapFile, channelSpec.getMinIntensity(), channelSpec.getMaxIntensity(), isMipmapLevelInRange); } } } } else { LOG.info("generateMissingMipmapFiles: all mipmap files exist for ", context); } } } }
MipmapClient { void generateMissingMipmapFiles(final TileSpec tileSpec) throws IllegalArgumentException, IOException { for (final ChannelSpec channelSpec : tileSpec.getAllChannels()) { final String channelName = channelSpec.getName(); final String context; if (channelName == null) { context = "tile '" + tileSpec.getTileId() + "'"; } else { context = "channel '" + channelName + "' in tile '" + tileSpec.getTileId() + "'"; } final Map.Entry<Integer, ImageAndMask> firstEntry = channelSpec.getFirstMipmapEntry(); if (firstEntry == null) { throw new IllegalArgumentException("first entry mipmap is missing from " + context); } final ImageAndMask sourceImageAndMask = firstEntry.getValue(); if ((sourceImageAndMask == null) || (!sourceImageAndMask.hasImage())) { throw new IllegalArgumentException("first entry mipmap image is missing from " + context); } if (parameters.forceGeneration || isMissingMipmaps(channelSpec, firstEntry, sourceImageAndMask.hasMask())) { ImageProcessor sourceImageProcessor = loadImageProcessor(sourceImageAndMask.getImageUrl()); ImageProcessor sourceMaskProcessor = null; if (sourceImageAndMask.hasMask()) { sourceMaskProcessor = loadImageProcessor(sourceImageAndMask.getMaskUrl()); } Map.Entry<Integer, ImageAndMask> derivedEntry; ImageAndMask derivedImageAndMask; File imageMipmapFile; File maskMipmapFile; for (int mipmapLevel = 1; mipmapLevel <= mipmapPathBuilder.getNumberOfLevels(); mipmapLevel++) { derivedEntry = mipmapPathBuilder.deriveImageAndMask(mipmapLevel, firstEntry, false); derivedImageAndMask = derivedEntry.getValue(); if (! channelSpec.hasMipmap(mipmapLevel)) { final boolean isMipmapLevelInRange = mipmapLevel >= parameters.minLevel; if (isMipmapLevelInRange) { createMissingDirectories(derivedImageAndMask.getImageUrl()); } imageMipmapFile = getFileForUrlString(derivedImageAndMask.getImageUrl()); sourceImageProcessor = generateMipmapFile(sourceImageProcessor, imageMipmapFile, channelSpec.getMinIntensity(), channelSpec.getMaxIntensity(), isMipmapLevelInRange); if (sourceImageAndMask.hasMask()) { if (isMipmapLevelInRange) { createMissingDirectories(derivedImageAndMask.getMaskUrl()); } maskMipmapFile = getFileForUrlString(derivedImageAndMask.getMaskUrl()); sourceMaskProcessor = generateMipmapFile(sourceMaskProcessor, maskMipmapFile, channelSpec.getMinIntensity(), channelSpec.getMaxIntensity(), isMipmapLevelInRange); } } } } else { LOG.info("generateMissingMipmapFiles: all mipmap files exist for ", context); } } } MipmapClient(final RenderWebServiceParameters renderWebParameters,
                        final MipmapParameters parameters); }
MipmapClient { void generateMissingMipmapFiles(final TileSpec tileSpec) throws IllegalArgumentException, IOException { for (final ChannelSpec channelSpec : tileSpec.getAllChannels()) { final String channelName = channelSpec.getName(); final String context; if (channelName == null) { context = "tile '" + tileSpec.getTileId() + "'"; } else { context = "channel '" + channelName + "' in tile '" + tileSpec.getTileId() + "'"; } final Map.Entry<Integer, ImageAndMask> firstEntry = channelSpec.getFirstMipmapEntry(); if (firstEntry == null) { throw new IllegalArgumentException("first entry mipmap is missing from " + context); } final ImageAndMask sourceImageAndMask = firstEntry.getValue(); if ((sourceImageAndMask == null) || (!sourceImageAndMask.hasImage())) { throw new IllegalArgumentException("first entry mipmap image is missing from " + context); } if (parameters.forceGeneration || isMissingMipmaps(channelSpec, firstEntry, sourceImageAndMask.hasMask())) { ImageProcessor sourceImageProcessor = loadImageProcessor(sourceImageAndMask.getImageUrl()); ImageProcessor sourceMaskProcessor = null; if (sourceImageAndMask.hasMask()) { sourceMaskProcessor = loadImageProcessor(sourceImageAndMask.getMaskUrl()); } Map.Entry<Integer, ImageAndMask> derivedEntry; ImageAndMask derivedImageAndMask; File imageMipmapFile; File maskMipmapFile; for (int mipmapLevel = 1; mipmapLevel <= mipmapPathBuilder.getNumberOfLevels(); mipmapLevel++) { derivedEntry = mipmapPathBuilder.deriveImageAndMask(mipmapLevel, firstEntry, false); derivedImageAndMask = derivedEntry.getValue(); if (! channelSpec.hasMipmap(mipmapLevel)) { final boolean isMipmapLevelInRange = mipmapLevel >= parameters.minLevel; if (isMipmapLevelInRange) { createMissingDirectories(derivedImageAndMask.getImageUrl()); } imageMipmapFile = getFileForUrlString(derivedImageAndMask.getImageUrl()); sourceImageProcessor = generateMipmapFile(sourceImageProcessor, imageMipmapFile, channelSpec.getMinIntensity(), channelSpec.getMaxIntensity(), isMipmapLevelInRange); if (sourceImageAndMask.hasMask()) { if (isMipmapLevelInRange) { createMissingDirectories(derivedImageAndMask.getMaskUrl()); } maskMipmapFile = getFileForUrlString(derivedImageAndMask.getMaskUrl()); sourceMaskProcessor = generateMipmapFile(sourceMaskProcessor, maskMipmapFile, channelSpec.getMinIntensity(), channelSpec.getMaxIntensity(), isMipmapLevelInRange); } } } } else { LOG.info("generateMissingMipmapFiles: all mipmap files exist for ", context); } } } MipmapClient(final RenderWebServiceParameters renderWebParameters,
                        final MipmapParameters parameters); static void main(final String[] args); void updateMipmapPathBuilderForStack(); int processMipmapsForZ(final Double z); }
MipmapClient { void generateMissingMipmapFiles(final TileSpec tileSpec) throws IllegalArgumentException, IOException { for (final ChannelSpec channelSpec : tileSpec.getAllChannels()) { final String channelName = channelSpec.getName(); final String context; if (channelName == null) { context = "tile '" + tileSpec.getTileId() + "'"; } else { context = "channel '" + channelName + "' in tile '" + tileSpec.getTileId() + "'"; } final Map.Entry<Integer, ImageAndMask> firstEntry = channelSpec.getFirstMipmapEntry(); if (firstEntry == null) { throw new IllegalArgumentException("first entry mipmap is missing from " + context); } final ImageAndMask sourceImageAndMask = firstEntry.getValue(); if ((sourceImageAndMask == null) || (!sourceImageAndMask.hasImage())) { throw new IllegalArgumentException("first entry mipmap image is missing from " + context); } if (parameters.forceGeneration || isMissingMipmaps(channelSpec, firstEntry, sourceImageAndMask.hasMask())) { ImageProcessor sourceImageProcessor = loadImageProcessor(sourceImageAndMask.getImageUrl()); ImageProcessor sourceMaskProcessor = null; if (sourceImageAndMask.hasMask()) { sourceMaskProcessor = loadImageProcessor(sourceImageAndMask.getMaskUrl()); } Map.Entry<Integer, ImageAndMask> derivedEntry; ImageAndMask derivedImageAndMask; File imageMipmapFile; File maskMipmapFile; for (int mipmapLevel = 1; mipmapLevel <= mipmapPathBuilder.getNumberOfLevels(); mipmapLevel++) { derivedEntry = mipmapPathBuilder.deriveImageAndMask(mipmapLevel, firstEntry, false); derivedImageAndMask = derivedEntry.getValue(); if (! channelSpec.hasMipmap(mipmapLevel)) { final boolean isMipmapLevelInRange = mipmapLevel >= parameters.minLevel; if (isMipmapLevelInRange) { createMissingDirectories(derivedImageAndMask.getImageUrl()); } imageMipmapFile = getFileForUrlString(derivedImageAndMask.getImageUrl()); sourceImageProcessor = generateMipmapFile(sourceImageProcessor, imageMipmapFile, channelSpec.getMinIntensity(), channelSpec.getMaxIntensity(), isMipmapLevelInRange); if (sourceImageAndMask.hasMask()) { if (isMipmapLevelInRange) { createMissingDirectories(derivedImageAndMask.getMaskUrl()); } maskMipmapFile = getFileForUrlString(derivedImageAndMask.getMaskUrl()); sourceMaskProcessor = generateMipmapFile(sourceMaskProcessor, maskMipmapFile, channelSpec.getMinIntensity(), channelSpec.getMaxIntensity(), isMipmapLevelInRange); } } } } else { LOG.info("generateMissingMipmapFiles: all mipmap files exist for ", context); } } } MipmapClient(final RenderWebServiceParameters renderWebParameters,
                        final MipmapParameters parameters); static void main(final String[] args); void updateMipmapPathBuilderForStack(); int processMipmapsForZ(final Double z);  }