TileImpl implements Tile { @Override public float[] getSamplesFloat() { if (getRasterDataNode().isValidMaskUsed()) { final int size = width * height; final float[] samples = new float[size]; int i = 0; for (int y = minY; y <= maxY; y++) { for (int x = minX; x <= maxX; x++) { samples[i++] = isSampleValid(x, y) ? getSampleFloat(x, y) : Float.NaN; } } return samples; } else { final ProductData data = getRawSamples(); if (!scaled && data.getType() == ProductData.TYPE_FLOAT32) { return (float[]) data.getElems(); } final int size = data.getNumElems(); final float[] samples = new float[size]; if (scaled) { for (int i = 0; i < size; i++) { samples[i] = toGeoPhysical(data.getElemFloatAt(i)); } } else { for (int i = 0; i < size; i++) { samples[i] = data.getElemFloatAt(i); } } return samples; } } TileImpl(RasterDataNode rasterDataNode, Raster raster);  TileImpl(RasterDataNode rasterDataNode, WritableRaster raster, Rectangle rectangle);  TileImpl(RasterDataNode rasterDataNode, Raster raster, Rectangle rectangle, boolean target); @Override float toGeoPhysical(float sample); @Override double toGeoPhysical(double sample); @Override float toRaw(float sample); @Override double toRaw(double sample); @Override final boolean isTarget(); @Override boolean isSampleValid(int x, int y); @Override final Rectangle getRectangle(); @Override final int getMinX(); @Override final int getMaxX(); @Override final int getMinY(); @Override final int getMaxY(); @Override final int getWidth(); @Override final int getHeight(); @Override final RasterDataNode getRasterDataNode(); @Override int getDataBufferIndex(int x, int y); @Override synchronized ProductData getDataBuffer(); @Override final byte[] getDataBufferByte(); @Override final short[] getDataBufferShort(); @Override final int[] getDataBufferInt(); @Override final float[] getDataBufferFloat(); @Override final double[] getDataBufferDouble(); @Override final int getScanlineOffset(); @Override final int getScanlineStride(); @Override synchronized ProductData getRawSamples(); @Override synchronized void setRawSamples(ProductData rawSamples); @Override byte[] getSamplesByte(); @Override short[] getSamplesShort(); @Override int[] getSamplesInt(); @Override float[] getSamplesFloat(); @Override double[] getSamplesDouble(); @Override void setSamples(byte[] samples); @Override void setSamples(short[] samples); @Override void setSamples(int[] samples); @Override void setSamples(float[] samples); @Override void setSamples(double[] samples); @Override boolean getSampleBoolean(int x, int y); @Override void setSample(int x, int y, boolean sample); @Override int getSampleInt(int x, int y); @Override void setSample(int x, int y, int sample); @Override float getSampleFloat(int x, int y); @Override void setSample(int x, int y, float sample); @Override double getSampleDouble(int x, int y); @Override void setSample(int x, int y, double sample); @Override boolean getSampleBit(int x, int y, int bitIndex); @Override void setSample(int x, int y, int bitIndex, boolean sample); @Override Iterator<Pos> iterator();  }
@Test public void testGetSamplesFloat() { Tile tile; float[] samples; tile = createRawTile(ProductData.TYPE_FLOAT32); assertNotNull(tile.getDataBufferFloat()); assertNull(tile.getDataBufferDouble()); samples = tile.getSamplesFloat(); assertSame(samples, tile.getDataBufferFloat()); assertEquals(N, samples.length); assertEquals(1.1F, samples[0], 1.0e-5F); assertEquals(2.1F, samples[1], 1.0e-5F); assertEquals(3.1F, samples[2], 1.0e-5F); assertEquals(128.1F, samples[N - 1], 1.0e-5F); tile = createRawTile(ProductData.TYPE_FLOAT64); assertNull(tile.getDataBufferFloat()); assertNotNull(tile.getDataBufferDouble()); samples = tile.getSamplesFloat(); assertNotNull(samples); assertEquals(N, samples.length); assertEquals(1.1F, samples[0], 1.0e-5F); assertEquals(2.1F, samples[1], 1.0e-5F); assertEquals(3.1F, samples[2], 1.0e-5F); assertEquals(128.1F, samples[N - 1], 1.0e-5F); tile = createScaledTile(ProductData.TYPE_UINT16, 2.5); assertNull(tile.getDataBufferDouble()); samples = tile.getSamplesFloat(); assertNotNull(samples); assertEquals(N, samples.length); assertEquals(2.5F, samples[0], 1.0e-5F); assertEquals(5.0F, samples[1], 1.0e-5F); assertEquals(7.5F, samples[2], 1.0e-5F); assertEquals(320.0F, samples[N - 1], 1.0e-5F); tile = createScaledTileWithNaNs(ProductData.TYPE_UINT16, 2.5, 7.5); assertNull(tile.getDataBufferDouble()); samples = tile.getSamplesFloat(); assertNotNull(samples); assertEquals(N, samples.length); assertEquals(2.5F, samples[0], 1.0e-5F); assertEquals(5.0F, samples[1], 1.0e-5F); assertEquals(true, Float.isNaN(samples[2])); assertEquals(320.0F, samples[N - 1], 1.0e-5F); }
@Test public void testGetSamplesFloatWithNoDataAndBorderExtender() { Product product = new Product("n", "t", 1000, 1000); product.setPreferredTileSize(100, 100); Band band = product.addBand("x", ProductData.TYPE_FLOAT32); band.setScalingFactor(10.0); band.setGeophysicalNoDataValue(5025); band.setNoDataValueUsed(true); band.setSourceImage(VirtualBandOpImage.create("Y * 1000 + X", band.getDataType(), Float.NaN, product, ResolutionLevel.MAXRES)); MultiLevelImage sourceImage = band.getSourceImage(); Rectangle tileBounds = sourceImage.getTile(0,0).getBounds(); tileBounds.grow(10,0); BorderExtenderConstant nanExtender = new BorderExtenderConstant(new double[]{Float.NaN}); TileImpl tile = new TileImpl(band, sourceImage.getExtendedData(tileBounds, nanExtender)); try { float[] samplesFloat = tile.getSamplesFloat(); assertEquals(120*100, samplesFloat.length); assertEquals(Float.NaN, samplesFloat[2], 1.0e-6f); assertEquals(5005, samplesFloat[10], 1.0e-6f); assertEquals(Float.NaN, samplesFloat[12], 1.0e-6f); } catch (OperatorException e) { Assert.fail("OperatorException should not been thrown."); } }