/** * Creates a byte-packed bitmask as array of bytes. * <p> * This method is used to provide backward API compatibility with BEAM versions prior 4.1. * Its use is discouraged.</p> * * @return an array of bytes of size {@link #getBytePackedBitmaskRasterWidth()}<code> * </code>{@link #getHeight()} * @see #getBytePackedBitmaskRasterWidth() */ public byte[] createBytePackedBitmaskRasterData() { int packedWidth = getBytePackedBitmaskRasterWidth(); byte[] bytes = new byte[packedWidth * getHeight()]; for (int y = 0; y < getHeight(); y++) { for (int x = 0; x < getWidth(); x++) { bytes[(y * packedWidth + x)] |= (1 << (x % 8)); } } return bytes; }
@Override public boolean validateIndex(final int pixelIndex) { return validMask.isSet(pixelOffset + pixelIndex); } }
final int size = width * height; BitRaster bitRaster = new BitRaster(width, height); assertEquals(width, bitRaster.getWidth()); assertEquals(height, bitRaster.getHeight()); assertEquals("i=" + i, false, bitRaster.isSet(i)); bitRaster.set(x, y, true); assertEquals("i=" + i, true, bitRaster.isSet(i)); bitRaster.set(i, false); assertEquals("x=" + x + ",y=" + y, false, bitRaster.isSet(x, y));
private void testAccessors(BitRaster bitRaster, int x, int y) { assertEquals(false, bitRaster.isSet(x, y)); assertEquals(false, bitRaster.isSet(x + y * bitRaster.getWidth())); bitRaster.set(x, y, true); assertEquals(true, bitRaster.isSet(x, y)); assertEquals(true, bitRaster.isSet(x + y * bitRaster.getWidth())); bitRaster.set(x, y, false); assertEquals(false, bitRaster.isSet(x, y)); assertEquals(false, bitRaster.isSet(x + y * bitRaster.getWidth())); }
/** * Sets a valid-mask for the given ID. * * @param id the ID * @param validMask the pixel mask * * @see #createValidMask(String, com.bc.ceres.core.ProgressMonitor) * @deprecated since BEAM 4.7, use {@link #getMaskGroup()} instead */ @Deprecated public void setValidMask(final String id, final BitRaster validMask) { if (validMask != null) { Guardian.assertEquals("validMask", validMask.getWidth(), getSceneRasterWidth()); Guardian.assertEquals("validMask", validMask.getHeight(), getSceneRasterHeight()); if (validMasks == null) { validMasks = new HashMap<>(); } validMasks.put(id, validMask); } else { if (validMasks != null) { validMasks.remove(id); } } }
public void set(int x, int y, boolean value) { set(y * width + x, value); }
/** * Gets the width of this raster in byte-packed form * <p> * This method is used to provide backward API compatibility with BEAM versions prior 4.1. * Its use is discouraged.</p> * * @return the width of this raster in byte-packed form * @see #createBytePackedBitmaskRasterData() */ public final int getBytePackedBitmaskRasterWidth() { int bytePackedBitmaskRasterWidth = getWidth() / 8; if (getWidth() % 8 != 0) { bytePackedBitmaskRasterWidth++; } return bytePackedBitmaskRasterWidth; } }
final int productWidth = getSceneRasterWidth(); final int productHeight = getSceneRasterHeight(); final BitRaster validMask = new BitRaster(productWidth, productHeight);
@Override public void eval(final RasterDataEvalEnv env, final int pixelIndex) { if (term.evalB(env)) { validMask.set(pixelIndex); } } }, "Computing valid-mask..."); /*I18N*/
public boolean isSet(int x, int y) { return isSet(y * width + x); }
@Test public void testEnsureValidMask() throws ParseException, IOException { final Product product = new Product("n", "t", 18, 2); final Band flagsBand = product.addBand("flags", ProductData.TYPE_INT8); final FlagCoding flagCoding = new FlagCoding("fc"); final int f1Mask = 1; flagCoding.addFlag("f1", f1Mask, ""); flagsBand.setSampleCoding(flagCoding); product.getFlagCodingGroup().add(flagCoding); final byte[] elems = new byte[]{ 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, }; flagsBand.setDataElems(elems); product.setModified(false); final Term term = product.parseExpression("flags.f1"); final BitRaster validMask = product.createValidMask(term, ProgressMonitor.NULL); for (int i = 0; i < elems.length; i++) { assertEquals(elems[i] == 1, validMask.isSet(i)); } }