private void init(DataAccess da, int width, int height, int i) { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { da.setShort(2 * (y * width + x), (short) 1); } } } }
private void fillDataAccessWithElevationData(Raster raster, DataAccess heights, int dataAccessWidth) { final int height = raster.getHeight(); final int width = raster.getWidth(); int x = 0; int y = 0; try { for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { short val = (short) raster.getPixel(x, y, (int[]) null)[0]; if (val < -1000 || val > 12000) val = Short.MIN_VALUE; heights.setShort(2 * (y * dataAccessWidth + x), val); } } heights.flush(); } catch (Exception ex) { throw new RuntimeException("Problem at x:" + x + ", y:" + y, ex); } }
private void updateHeightsFromFile(double lat, double lon, DataAccess heights) throws FileNotFoundException { try { byte[] bytes = getByteArrayFromFile(lat, lon); heights.create(bytes.length); for (int bytePos = 0; bytePos < bytes.length; bytePos += 2) { short val = BIT_UTIL.toShort(bytes, bytePos); if (val < -1000 || val > 12000) val = Short.MIN_VALUE; heights.setShort(bytePos, val); } heights.setHeader(WIDTH_BYTE_INDEX, bytes.length / 2); heights.flush(); } catch (FileNotFoundException ex) { logger.warn("File not found for the coordinates for " + lat + "," + lon); throw ex; } catch (Exception ex) { throw new RuntimeException("There was an issue looking up the coordinates for " + lat + "," + lon, ex); } }
@Test public void testSet_Get_Short_Long() { DataAccess da = createDataAccess(name); da.create(300); da.setShort(6, (short) (Short.MAX_VALUE / 5)); da.setShort(8, (short) (Short.MAX_VALUE / 7)); da.setShort(10, (short) (Short.MAX_VALUE / 9)); da.setShort(14, (short) (Short.MAX_VALUE / 10)); int unsignedShort = (int) Short.MAX_VALUE + 5; da.setShort(12, (short) unsignedShort); assertEquals(Short.MAX_VALUE / 5, da.getShort(6)); assertEquals(Short.MAX_VALUE / 7, da.getShort(8)); assertEquals(Short.MAX_VALUE / 9, da.getShort(10)); assertEquals(Short.MAX_VALUE / 10, da.getShort(14)); assertEquals(unsignedShort, (int) da.getShort(12) & 0x0000FFFF); // currently RAMIntDA does not support arbitrary byte positions if (!(da instanceof RAMIntDataAccess)) { da.setShort(7, (short) (Short.MAX_VALUE / 3)); assertEquals(Short.MAX_VALUE / 3, da.getShort(7)); // should be overwritten assertNotEquals(Short.MAX_VALUE / 3, da.getShort(8)); } da.close(); } }
@Test public void testCalcMean() { int width = 10; HeightTile instance = new HeightTile(0, 0, width, width, 1e-6, 10, 10).setCalcMean(true); DataAccess heights = new RAMDirectory().find("tmp"); heights.create(2 * 10 * 10); instance.setHeights(heights); init(heights, width, width, 1); // x,y=0,9 heights.setShort(2 * (9 * width + 0), (short) 10); // x,y=1,7 heights.setShort(2 * (7 * width + 1), (short) 70); // x,y=2,8 heights.setShort(2 * (8 * width + 2), (short) 90); assertEquals((70 + 4) / 5d, instance.getHeight(2, 1), 1e-3); assertEquals((70 + 90 + 3) / 5d, instance.getHeight(2.5, 2.5), 1e-3); assertEquals((90 + 3) / 4d, instance.getHeight(-0.5, 2.5), 1e-3); assertEquals((10 + 2) / 3d, instance.getHeight(-0.5, -0.5), 1e-3); }
@Test public void testGetHeightForNegativeTile() { int width = 10; HeightTile instance = new HeightTile(-20, -20, width, width, 1e-6, 10, 10); DataAccess heights = new RAMDirectory().find("tmp"); heights.create(2 * 10 * 10); instance.setHeights(heights); init(heights, width, width, 1); // x,y=1,7 heights.setShort(2 * (7 * width + 1), (short) 70); // x,y=2,9 heights.setShort(2 * (9 * width + 2), (short) 90); assertEquals(1, instance.getHeight(-15, -15), 1e-3); assertEquals(70, instance.getHeight(-17.5, -18.5), 1e-3); // edge cases for one tile with the boundaries [min,min+degree/width) for lat and lon assertEquals(1, instance.getHeight(-17, -18), 1e-3); assertEquals(70, instance.getHeight(-18, -19), 1e-3); }
@Override public synchronized void setShort( long bytePos, short value ) { inner.setShort(bytePos, value); }
@Override public synchronized void setShort(long bytePos, short value) { inner.setShort(bytePos, value); }
/** * @return false if the value capacity was reached and instead of the real value the SHORT_MAX was stored. */ final boolean setWeight(long pointer, double value) { double tmpVal = value / factor; if (tmpVal > Integer.MAX_VALUE) throw new UnsupportedOperationException("Cannot store infinity explicitely, pointer=" + pointer + ", value: " + value); if (tmpVal >= SHORT_MAX) { landmarkWeightDA.setShort(pointer, (short) SHORT_MAX); return false; } else { landmarkWeightDA.setShort(pointer, (short) tmpVal); return true; } }
private void fillDataAccessWithElevationData(Raster raster, DataAccess heights, int dataAccessWidth) { final int height = raster.getHeight(); final int width = raster.getWidth(); int x = 0; int y = 0; try { for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { short val = (short) raster.getPixel(x, y, (int[]) null)[0]; if (val < -1000 || val > 12000) val = Short.MIN_VALUE; heights.setShort(2 * (y * dataAccessWidth + x), val); } } heights.flush(); } catch (Exception ex) { throw new RuntimeException("Problem at x:" + x + ", y:" + y, ex); } }
private void updateHeightsFromFile(double lat, double lon, DataAccess heights) throws FileNotFoundException { try { byte[] bytes = getByteArrayFromFile(lat, lon); heights.create(bytes.length); for (int bytePos = 0; bytePos < bytes.length; bytePos += 2) { short val = BIT_UTIL.toShort(bytes, bytePos); if (val < -1000 || val > 12000) val = Short.MIN_VALUE; heights.setShort(bytePos, val); } heights.setHeader(WIDTH_BYTE_INDEX, bytes.length / 2); heights.flush(); } catch (FileNotFoundException ex) { logger.warn("File not found for the coordinates for " + lat + "," + lon); throw ex; } catch (Exception ex) { throw new RuntimeException("There was an issue looking up the coordinates for " + lat + "," + lon, ex); } }
private void updateHeightsFromZipFile(String fileDetails, DataAccess heights) throws RuntimeException { try { byte[] bytes = getByteArrayFromZipFile(fileDetails); heights.create(bytes.length); for (int bytePos = 0; bytePos < bytes.length; bytePos += 2) { short val = BIT_UTIL.toShort(bytes, bytePos); if (val < -1000 || val > 12000) val = Short.MIN_VALUE; heights.setShort(bytePos, val); } heights.setHeader(WIDTH_BYTE_INDEX, bytes.length / 2); heights.flush(); } catch (Exception ex) { throw new RuntimeException(ex); } }
private void updateHeightsFromZipFile( String fileDetails, DataAccess heights ) throws RuntimeException { try { byte[] bytes = getByteArrayFromZipFile(fileDetails); heights.create(bytes.length); for (int bytePos = 0; bytePos < bytes.length; bytePos += 2) { short val = BIT_UTIL.toShort(bytes, bytePos); if (val < -1000 || val > 12000) val = Short.MIN_VALUE; heights.setShort(bytePos, val); } heights.setHeader(WIDTH_BYTE_INDEX, bytes.length / 2); heights.flush(); } catch (Exception ex) { throw new RuntimeException(ex); } }
val = Short.MIN_VALUE; heights.setShort(2 * (y * WIDTH + x), val);
val = Short.MIN_VALUE; heights.setShort(2 * (y * WIDTH + x), val);