private List<List<RenderedImage>> createSourceImages() { final List<List<RenderedImage>> sourceImageList = new ArrayList<List<RenderedImage>>(variables.length); for (final Variable variable : variables) { final List<RenderedImage> renderedImageList = new ArrayList<RenderedImage>(reprojectedProducts.length); sourceImageList.add(renderedImageList); for (final Product product : reprojectedProducts) { renderedImageList.add(createExpressionImage(variable.getExpression(), product)); } if (isUpdateMode()) { renderedImageList.add(updateProduct.getBand(variable.getName()).getSourceImage()); } } return sourceImageList; }
private RenderedImage getImageWithTargetDataType(int targetDataType, Band subsetBand) { RenderedImage sourceImage = subsetBand.getSourceImage(); final int actualTargetBandDataType = sourceImage.getSampleModel().getDataType(); if (actualTargetBandDataType != targetDataType) { sourceImage = FormatDescriptor.create(sourceImage, targetDataType, null); } return sourceImage; }
boolean isComputingImageOf(Band band) { if (band.isSourceImageSet()) { RenderedImage sourceImage = band.getSourceImage().getImage(0); OperatorImage targetImage = getTargetImage(band); //noinspection ObjectEquality return targetImage == sourceImage; } else { return false; } }
private boolean isProductReaderDirectlyUsable() { final ProductReader productReader = getProductReader(); if (productReader != null) { if (isSourceImageSet() && getSourceImage().getImage(0) instanceof BandOpImage) { final BandOpImage bandOpImage = (BandOpImage) getSourceImage().getImage(0); if (bandOpImage.getBand().getProductReader() == productReader) { return true; } } } return false; }
private void setSourceImages() { for (Band destBand : tsProduct.getBands()) { final Band raster = getSourceBand(destBand.getName()); if (raster != null) { destBand.setSourceImage(raster.getSourceImage()); } } }
private PlanarImage createExpressionImage(final String expression, Product product) { final MultiLevelImage sourceImage = product.getBandAt(0).getSourceImage(); final ResolutionLevel resolutionLevel = ResolutionLevel.create(sourceImage.getModel(), 0); final float fillValue = 0.0f; return VirtualBandOpImage.create(expression, ProductData.TYPE_FLOAT32, fillValue, product, resolutionLevel); }
private static TileImpl createTile(Band band) { return new TileImpl(band, band.getSourceImage().getData()); }
private void updateTilingParameter() { if (writeParam.getTilingMode() != TIFFImageWriteParam.MODE_EXPLICIT) { final Product sourceProduct = getSourceProduct(); final MultiLevelImage firstSourceImage = sourceProduct.getBandAt(0).getSourceImage(); final int tileWidth = firstSourceImage.getTileWidth(); final int tileHeight = firstSourceImage.getTileHeight(); writeParam.setTilingMode(TIFFImageWriteParam.MODE_EXPLICIT); writeParam.setTiling(tileWidth, tileHeight, 0, 0); } }
private void reopenProduct(Product product, File newFile) throws IOException { DimapProductReader productReader = (DimapProductReader) ProductIO.getProductReader( DimapProductConstants.DIMAP_FORMAT_NAME); productReader.bindProduct(newFile, product); product.setProductReader(productReader); Band[] bands = product.getBands(); for (Band band : bands) { if (band.isSourceImageSet() && band.getSourceImage().getImage(0) instanceof BandOpImage) { band.setSourceImage(null); } } }
private void removeCachedImageData() { if (isSourceImageSet()) { getSourceImage().reset(); } if (isGeophysicalImageSet()) { getGeophysicalImage().reset(); } if (isValidMaskImageSet()) { getValidMaskImage().reset(); } }
private void assertSampleValuesFloat(Band b1Band, GeoPos[] geoPositions, float[] expectedValues) { GeoCoding geoCoding = b1Band.getGeoCoding(); final Raster b1Raster = b1Band.getSourceImage().getData(); for (int i = 0; i < geoPositions.length; i++) { PixelPos pp = geoCoding.getPixelPos(geoPositions[i], null); final float expectedValue = expectedValues[i]; final float actualValue = b1Raster.getSampleFloat((int) pp.x, (int) pp.y, 0); final String message = String.format("At <%d>:", i); assertEquals(message, expectedValue, actualValue, 1.0e-6); } }
private void assertSampleValuesInt(Band b1Band, GeoPos[] geoPositions, int[] expectedValues) { GeoCoding geoCoding = b1Band.getGeoCoding(); final Raster b1Raster = b1Band.getSourceImage().getData(); for (int i = 0; i < geoPositions.length; i++) { PixelPos pp = geoCoding.getPixelPos(geoPositions[i], null); final int expectedValue = expectedValues[i]; final int actualValue = b1Raster.getSample((int) pp.x, (int) pp.y, 0); final String message = String.format("At <%d>:", i); assertEquals(message, expectedValue, actualValue); } }
@Test public void testGeophysicalSameAsSourceImage() { Product p = new Product("p", "pt", 256, 128); Band band; band = addBand(p, "b1", ProductData.TYPE_UINT16, null, 1.0); assertNotNull(band.getSourceImage()); assertEquals(DataBuffer.TYPE_USHORT, band.getSourceImage().getSampleModel().getDataType()); assertSame(band.getGeophysicalImage(), band.getSourceImage()); assertNull(band.getValidMaskImage()); band = addBand(p, "b2", ProductData.TYPE_FLOAT32, null, 1.0); assertNotNull(band.getSourceImage()); assertEquals(DataBuffer.TYPE_FLOAT, band.getSourceImage().getSampleModel().getDataType()); assertSame(band.getGeophysicalImage(), band.getSourceImage()); assertNull(band.getValidMaskImage()); }
@Test public void testComputationOnLevel0() { final RenderedImage image = band.getSourceImage().getImage(0); assertEquals(1024, image.getWidth()); assertEquals(1024, image.getHeight()); final Raster data = image.getData(); final int sample = data.getSample(1023, 1023, 0); assertEquals(1048575, sample); // 1023 }
@Test public void testComputationOnHigherLevel() { final RenderedImage image = band.getSourceImage().getImage(1); assertEquals(512, image.getWidth()); assertEquals(512, image.getHeight()); final Raster data = image.getData(); final int sample = data.getSample(511, 511, 0); assertEquals(1047550, sample); // (511*2) * 1024 + (511*2) }
private void testThat(ProductReader reader) throws IOException { Product product = reader.readProductNodes(null, null); testThat(product.getBand("B1").getSourceImage(), product.getBand("B2").getSourceImage()); testThat(product.getBand("B1").getGeophysicalImage(), product.getBand("B2").getGeophysicalImage()); }
@Test public void testValidMaskImage() { Product p = new Product("p", "pt", 256, 128); Band band; band = addBand(p, "b1", ProductData.TYPE_UINT16, -999.0, 1.0); assertNotNull(band.getSourceImage()); assertEquals(DataBuffer.TYPE_USHORT, band.getSourceImage().getSampleModel().getDataType()); assertSame(band.getGeophysicalImage(), band.getSourceImage()); assertNotNull(band.getValidMaskImage()); assertEquals(DataBuffer.TYPE_BYTE, band.getValidMaskImage().getSampleModel().getDataType()); }
@Override public void initialize() throws OperatorException { Product targetProduct = new Product("target", "target", 100, 100); for (Band srcBand : source.getBands()) { Band band = targetProduct.addBand(srcBand.getName(), srcBand.getDataType()); band.setSourceImage(srcBand.getSourceImage()); } setTargetProduct(targetProduct); }
private OpImage createOpImage() { SubsetOp subsetOp = new SubsetOp(); Product sourceProduct = new Product("name", "type", 16, 16); sourceProduct.addBand("x", ProductData.TYPE_INT32); subsetOp.setSourceProduct(sourceProduct); Product targetProduct = subsetOp.getTargetProduct(); RenderedImage image = targetProduct.getBand("x").getSourceImage().getImage(0); assertTrue(image instanceof OpImage); return (OpImage) image; } }
@Test public void testTileSetSamples() throws Exception { ImageLayout value = new ImageLayout(); value.setTileWidth(200); value.setTileHeight(200); Product p = new Product("N", "T", 1121, 705); p.setPreferredTileSize(200, 200); Band b = p.addBand("b", "0"); RenderedImage image = b.getSourceImage().getImage(0); Raster raster = image.getTile(3, 0); TileImpl tile = new TileImpl(b, raster); tile.setSamples(new float[200*200]); } }