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; }
public synchronized void readBandData( Band destBand, int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, ProductData destBuffer, ProgressMonitor pm) throws IOException, InvalidRangeException { if (mustFlipY) { sourceOffsetY = destBand.getSceneRasterHeight() - (sourceOffsetY + sourceHeight); } if (mustFlipX) { sourceOffsetX = destBand.getSceneRasterWidth() - (sourceOffsetX + sourceWidth); } sourceOffsetY += leadLineSkip; start[0] = sourceOffsetY; start[1] = sourceOffsetX; stride[0] = sourceStepY; stride[1] = sourceStepX; count[0] = sourceHeight; count[1] = sourceWidth; Object buffer = destBuffer.getElems(); Variable variable = variableMap.get(destBand); pm.beginTask("Reading band '" + variable.getShortName() + "'...", sourceHeight); try { Section section = new Section(start, count, stride); Array array; int[] newshape = {sourceHeight, sourceWidth}; array = variable.read(section); if (array.getRank() == 3) { array = array.reshapeNoCopy(newshape); } Object storage; if (mustFlipX && !mustFlipY) { storage = array.flip(1).copyTo1DJavaArray(); } else if (!mustFlipX && mustFlipY) { storage = array.flip(0).copyTo1DJavaArray(); } else if (mustFlipX && mustFlipY) { storage = array.flip(0).flip(1).copyTo1DJavaArray(); } else { storage = array.copyTo1DJavaArray(); } arraycopy(storage, 0, buffer, 0, destBuffer.getNumElems()); } finally { pm.done(); } }
/** * 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"); } }
private void checkBufferSize(int sourceWidth, int sourceHeight, ProductData sourceBuffer) { int expectedBufferSize = sourceWidth * sourceHeight; int actualBufferSize = sourceBuffer.getNumElems(); Guardian.assertEquals("wrong sourceBuffer size", actualBufferSize, expectedBufferSize); }