/** * Returns this value's data type String. */ public String getTypeString() { return getTypeString(getType()); }
/** * Gets the element size of an element of this product data in bytes. * * @return the size of a single element in bytes */ public int getElemSize() { return getElemSize(getType()); }
public int getNewBandsDataType() { return ProductData.getType(_paramDataType.getValueAsText()); }
/** * Checks if the data that should be used to access the data is compatible with the data this node can hold. * * @param data the data to be checked for compatibility * @throws IllegalArgumentException if data is invalid. */ protected void checkDataCompatibility(ProductData data) throws IllegalArgumentException { Debug.assertNotNull(data); if (data.getType() != getDataType()) { throw new IllegalArgumentException("illegal data for data node '" + getName() + "', type " + ProductData.getTypeString(getDataType()) + " expected"); } if (data.getNumElems() != getNumDataElems()) { throw new IllegalArgumentException("illegal number of data elements for data node '" + getName() + "', " + getNumDataElems() + " elements expected"); } }
public DataNode(String name, ProductData data, boolean readOnly) { super(name); Guardian.assertNotNull("data", data); this.dataType = data.getType(); this.numElems = data.getNumElems(); this.data = data; this.readOnly = readOnly; }
/** * Tests whether the given parameters specify a compatible raster or not. * * @param rasterData the raster data * @param w the raster width * @param h the raster height * @return {@code true} if so */ public boolean isCompatibleRasterData(ProductData rasterData, int w, int h) { return rasterData != null && rasterData.getType() == getDataType() && rasterData.getNumElems() == w * h; }
public void testStaticGetType() { assertEquals(ProductData.TYPE_ASCII, ProductData.getType(ProductData.TYPESTRING_ASCII)); assertEquals(ProductData.TYPE_FLOAT32, ProductData.getType(ProductData.TYPESTRING_FLOAT32)); assertEquals(ProductData.TYPE_FLOAT64, ProductData.getType(ProductData.TYPESTRING_FLOAT64)); assertEquals(ProductData.TYPE_INT16, ProductData.getType(ProductData.TYPESTRING_INT16)); assertEquals(ProductData.TYPE_INT32, ProductData.getType(ProductData.TYPESTRING_INT32)); assertEquals(ProductData.TYPE_INT8, ProductData.getType(ProductData.TYPESTRING_INT8)); assertEquals(ProductData.TYPE_UINT16, ProductData.getType(ProductData.TYPESTRING_UINT16)); assertEquals(ProductData.TYPE_UINT32, ProductData.getType(ProductData.TYPESTRING_UINT32)); assertEquals(ProductData.TYPE_UINT8, ProductData.getType(ProductData.TYPESTRING_UINT8)); assertEquals(ProductData.TYPE_UTC, ProductData.getType(ProductData.TYPESTRING_UTC)); assertEquals(ProductData.TYPE_UNDEFINED, ProductData.getType("any other string")); }
public void testDataTypeInconsistency() { ProductData instance = ProductData.createInstance(ProductData.TYPE_ASCII); assertTrue( "OK! After all we've managed to remove this inconsistency. This is not a real failure, it had to be done one day!", ProductData.TYPE_ASCII != instance.getType()); assertEquals(ProductData.TYPE_INT8, instance.getType()); }
private Namespace createNamespace() { WritableNamespace namespace = BandArithmetic.createDefaultNamespace(sourceProducts, 0, new SourceProductPrefixProvider()); if (variables != null) { for (Variable variable : variables) { if (ProductData.isFloatingPointType(ProductData.getType(variable.type))) { Symbol symbol = SymbolFactory.createConstant(variable.name, Double.parseDouble(variable.value)); namespace.registerSymbol(symbol); } else if (ProductData.isIntType(ProductData.getType(variable.type))) { Symbol symbol = SymbolFactory.createConstant(variable.name, Long.parseLong(variable.value)); namespace.registerSymbol(symbol); } else if ("boolean".equals(variable.type)) { Symbol symbol = SymbolFactory.createConstant(variable.name, Boolean.parseBoolean(variable.value)); namespace.registerSymbol(symbol); } } } return namespace; }
private void writeTileRow(Band band, Tile[] cacheLine) throws IOException { Tile firstTile = cacheLine[0]; int sceneWidth = targetProduct.getSceneRasterWidth(); Rectangle lineBounds = new Rectangle(0, firstTile.getMinY(), sceneWidth, firstTile.getHeight()); ProductData[] rawSampleOFLine = new ProductData[cacheLine.length]; int[] tileWidth = new int[cacheLine.length]; for (int tileX = 0; tileX < cacheLine.length; tileX++) { Tile tile = cacheLine[tileX]; rawSampleOFLine[tileX] = tile.getRawSamples(); tileWidth[tileX] = tile.getRectangle().width; } ProductData sampleLine = ProductData.createInstance(rawSampleOFLine[0].getType(), sceneWidth); synchronized (productWriter) { for (int y = lineBounds.y; y < lineBounds.y + lineBounds.height; y++) { int targetPos = 0; for (int tileX = 0; tileX < cacheLine.length; tileX++) { Object rawSamples = rawSampleOFLine[tileX].getElems(); int width = tileWidth[tileX]; int srcPos = (y - lineBounds.y) * width; System.arraycopy(rawSamples, srcPos, sampleLine.getElems(), targetPos, width); targetPos += width; } productWriter.writeBandRasterData(band, 0, y, sceneWidth, 1, sampleLine, ProgressMonitor.NULL); } } }
@Override public synchronized void setRawSamples(ProductData rawSamples) { if (target) { if (rawSamples != this.dataBuffer) { Assert.notNull(rawSamples, "rawSamples"); Assert.argument(rawSamples.getType() == dataBuffer.getType(), "rawSamples.getType() == dataBuffer.getType()"); Assert.argument(rawSamples.getNumElems() == dataBuffer.getNumElems(), "rawSamples.getNumElems() == dataBuffer.getNumElems()"); dataBuffer.setElems(rawSamples.getElems()); } } }
private void readBandRasterDataSubSampling(Band sourceBand, int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, ProductData destBuffer, int destWidth, ProgressMonitor pm) throws IOException { final int sourceMinY = sourceOffsetY; final int sourceMaxY = sourceOffsetY + sourceHeight - 1; ProductData lineBuffer = ProductData.createInstance(destBuffer.getType(), sourceWidth); int destPos = 0; try { pm.beginTask("Reading sub sampled raster data...", 2 * (sourceMaxY - sourceMinY)); for (int sourceY = sourceMinY; sourceY <= sourceMaxY; sourceY += sourceStepY) { sourceBand.readRasterData(sourceOffsetX, sourceY, sourceWidth, 1, lineBuffer, SubProgressMonitor.create(pm, 1)); if (sourceStepX == 1) { copyData(lineBuffer, 0, destBuffer, destPos, destWidth); } else { copyLine(lineBuffer, 0, sourceWidth, sourceStepX, destBuffer, destPos); } pm.worked(1); destPos += destWidth; } } finally { pm.done(); } }
} else { final ProductData data = getRawSamples(); if (!scaled && data.getType() == ProductData.TYPE_FLOAT32) { return (float[]) data.getElems();
public static RenderedImage createRenderedImage(int width, int height, ProductData data) { final int dataBufferType = ImageManager.getDataBufferType(data.getType()); DataBuffer db; if (dataBufferType == DataBuffer.TYPE_BYTE) { db = new DataBufferByte((byte[]) data.getElems(), data.getNumElems()); } else if (dataBufferType == DataBuffer.TYPE_USHORT) { db = new DataBufferUShort((short[]) data.getElems(), data.getNumElems()); } else if (dataBufferType == DataBuffer.TYPE_SHORT) { db = new DataBufferShort((short[]) data.getElems(), data.getNumElems()); } else if (dataBufferType == DataBuffer.TYPE_INT) { db = new DataBufferInt((int[]) data.getElems(), data.getNumElems()); } else if (dataBufferType == DataBuffer.TYPE_FLOAT) { db = new DataBufferFloat((float[]) data.getElems(), data.getNumElems()); } else if (dataBufferType == DataBuffer.TYPE_DOUBLE) { db = new DataBufferDouble((double[]) data.getElems(), data.getNumElems()); } else { throw new IllegalStateException("illegal image data buffer type: " + dataBufferType); } SampleModel sampleModel = createSingleBandedSampleModel(dataBufferType, width, height); final ColorModel colorModel = PlanarImage.createColorModel(sampleModel); final WritableRaster raster = WritableRaster.createWritableRaster(sampleModel, db, new Point(0, 0)); // final TiledImage image = new TiledImage(0, 0, width, height, 512, 512, sampleModel, colorModel); // final BufferedImage image = new BufferedImage(colorModel, raster, false, null); // image. return new MyRenderedImage(raster, colorModel); }
public void testUInt32Array() { final long intMax = Integer.MAX_VALUE; final ProductData data = ProductData.createInstance(new long[]{ 1L, intMax / 2, intMax + 1L, intMax + intMax / 2, }); assertEquals(ProductData.TYPE_UINT32, data.getType()); assertEquals(1L, data.getElemUIntAt(0)); assertEquals(intMax / 2, data.getElemUIntAt(1)); assertEquals(intMax + 1L, data.getElemUIntAt(2)); assertEquals(intMax + intMax / 2, data.getElemUIntAt(3)); }
} else { final ProductData data = getRawSamples(); if (!scaled && data.getType() == ProductData.TYPE_FLOAT32) { return (double[]) data.getElems();
instance.setElems(new byte[]{127}); assertEquals(ProductData.TYPE_INT8, instance.getType()); assertEquals(127, instance.getElemInt()); assertEquals(127L, instance.getElemUInt());