@Test public void testBuildUpperLeftTierDimensionsList() { final Bounds roughStackBounds = new Bounds(50000.0, 40000.0, 1.0, 70000.0, 65000.0, 3.0); final List<TierDimensions> tierDimensionsList = TierDimensions.buildUpperLeftTierDimensionsList(roughStackBounds, 1024, 1024); final Object[][] expectedTierValues = { { 50000, 40000, 70000, 65000, 1, 1, 0.04096 }, { 50000, 40000, 70480, 68672, 7, 5, 0.25 }, { 48976, 38976, 71504, 65600, 13, 11, 0.5 }, { 49488, 39488, 70992, 65088, 25, 21, 1.0 } }; validateTiers(expectedTierValues, tierDimensionsList); }
static List<TierDimensions> buildUpperLeftTierDimensionsList(final Bounds roughStackFullScaleBounds, final int cellPixelWidth, final int cellPixelHeight) { final int fullScaleWidth = (int) Math.ceil(roughStackFullScaleBounds.getDeltaX()); final int fullScaleHeight = (int) Math.ceil(roughStackFullScaleBounds.getDeltaY()); int fullScaleCellWidth = cellPixelWidth; int fullScaleCellHeight = cellPixelHeight; double scale = 1.0; int tierCount = 0; int rows; int columns; do { tierCount++; fullScaleCellWidth *= 2; fullScaleCellHeight *= 2; scale /= 2.0; rows = (int) Math.ceil(fullScaleHeight / (double) fullScaleCellHeight); columns = (int) Math.ceil(fullScaleWidth / (double) fullScaleCellWidth); } while (((fullScaleCellWidth < fullScaleWidth) || (fullScaleCellHeight < fullScaleHeight)) && (rows > 3) && (columns > 3)); fullScaleCellWidth /= 2; fullScaleCellHeight /= 2; scale *= 2.0; rows = (int) Math.ceil(fullScaleHeight / (cellPixelHeight / scale)); columns = (int) Math.ceil(fullScaleWidth / (cellPixelWidth / scale)); final List<TierDimensions> list = new ArrayList<>(tierCount); list.add(buildTierZero(roughStackFullScaleBounds, cellPixelWidth, cellPixelHeight)); if (tierCount > 1) { int minX = (int) Math.floor(roughStackFullScaleBounds.getMinX()); int minY = (int) Math.floor(roughStackFullScaleBounds.getMinY()); Bounds fullScaleBounds = new Bounds((double) minX, (double) minY, roughStackFullScaleBounds.getMinZ(), (double) (minX + (columns * fullScaleCellWidth)), (double) (minY + (rows * fullScaleCellHeight)), roughStackFullScaleBounds.getMaxZ()); list.add(new TierDimensions(fullScaleCellWidth, fullScaleCellHeight, scale, rows, columns, fullScaleBounds)); int insideCenterX = (int) Math.floor(fullScaleBounds.getMinX() + (fullScaleCellWidth * 0.25)); int insideCenterY = (int) Math.floor(fullScaleBounds.getMinY() + (fullScaleCellHeight * 0.25)); int cellsFromInside = 1; for (int tier = 2; tier <= tierCount; tier++) { fullScaleCellWidth /= 2; fullScaleCellHeight /= 2; scale *= 2.0; minX = (int) Math.floor(insideCenterX - (cellsFromInside * fullScaleCellWidth)); minY = (int) Math.floor(insideCenterY - (cellsFromInside * fullScaleCellHeight)); rows = (int) Math.ceil((roughStackFullScaleBounds.getMaxY() - minY) / fullScaleCellHeight); columns = (int) Math.ceil((roughStackFullScaleBounds.getMaxX() - minX) / fullScaleCellWidth); fullScaleBounds = new Bounds((double) minX, (double) minY, roughStackFullScaleBounds.getMinZ(), (double) (minX + (columns * fullScaleCellWidth)), (double) (minY + (rows * fullScaleCellHeight)), roughStackFullScaleBounds.getMaxZ()); list.add(new TierDimensions(fullScaleCellWidth, fullScaleCellHeight, scale, rows, columns, fullScaleBounds)); insideCenterX = (int) Math.floor(insideCenterX + (fullScaleCellWidth * 0.25)); insideCenterY = (int) Math.floor(insideCenterY + (fullScaleCellHeight * 0.25)); cellsFromInside = (int) Math.pow(2, (tier - 1)); } } LOG.info("buildUpperLeftTierDimensionsList: returning dimensions for {} tiers: {}", list.size(), list); return list; }
TierDimensions implements Serializable { static List<TierDimensions> buildUpperLeftTierDimensionsList(final Bounds roughStackFullScaleBounds, final int cellPixelWidth, final int cellPixelHeight) { final int fullScaleWidth = (int) Math.ceil(roughStackFullScaleBounds.getDeltaX()); final int fullScaleHeight = (int) Math.ceil(roughStackFullScaleBounds.getDeltaY()); int fullScaleCellWidth = cellPixelWidth; int fullScaleCellHeight = cellPixelHeight; double scale = 1.0; int tierCount = 0; int rows; int columns; do { tierCount++; fullScaleCellWidth *= 2; fullScaleCellHeight *= 2; scale /= 2.0; rows = (int) Math.ceil(fullScaleHeight / (double) fullScaleCellHeight); columns = (int) Math.ceil(fullScaleWidth / (double) fullScaleCellWidth); } while (((fullScaleCellWidth < fullScaleWidth) || (fullScaleCellHeight < fullScaleHeight)) && (rows > 3) && (columns > 3)); fullScaleCellWidth /= 2; fullScaleCellHeight /= 2; scale *= 2.0; rows = (int) Math.ceil(fullScaleHeight / (cellPixelHeight / scale)); columns = (int) Math.ceil(fullScaleWidth / (cellPixelWidth / scale)); final List<TierDimensions> list = new ArrayList<>(tierCount); list.add(buildTierZero(roughStackFullScaleBounds, cellPixelWidth, cellPixelHeight)); if (tierCount > 1) { int minX = (int) Math.floor(roughStackFullScaleBounds.getMinX()); int minY = (int) Math.floor(roughStackFullScaleBounds.getMinY()); Bounds fullScaleBounds = new Bounds((double) minX, (double) minY, roughStackFullScaleBounds.getMinZ(), (double) (minX + (columns * fullScaleCellWidth)), (double) (minY + (rows * fullScaleCellHeight)), roughStackFullScaleBounds.getMaxZ()); list.add(new TierDimensions(fullScaleCellWidth, fullScaleCellHeight, scale, rows, columns, fullScaleBounds)); int insideCenterX = (int) Math.floor(fullScaleBounds.getMinX() + (fullScaleCellWidth * 0.25)); int insideCenterY = (int) Math.floor(fullScaleBounds.getMinY() + (fullScaleCellHeight * 0.25)); int cellsFromInside = 1; for (int tier = 2; tier <= tierCount; tier++) { fullScaleCellWidth /= 2; fullScaleCellHeight /= 2; scale *= 2.0; minX = (int) Math.floor(insideCenterX - (cellsFromInside * fullScaleCellWidth)); minY = (int) Math.floor(insideCenterY - (cellsFromInside * fullScaleCellHeight)); rows = (int) Math.ceil((roughStackFullScaleBounds.getMaxY() - minY) / fullScaleCellHeight); columns = (int) Math.ceil((roughStackFullScaleBounds.getMaxX() - minX) / fullScaleCellWidth); fullScaleBounds = new Bounds((double) minX, (double) minY, roughStackFullScaleBounds.getMinZ(), (double) (minX + (columns * fullScaleCellWidth)), (double) (minY + (rows * fullScaleCellHeight)), roughStackFullScaleBounds.getMaxZ()); list.add(new TierDimensions(fullScaleCellWidth, fullScaleCellHeight, scale, rows, columns, fullScaleBounds)); insideCenterX = (int) Math.floor(insideCenterX + (fullScaleCellWidth * 0.25)); insideCenterY = (int) Math.floor(insideCenterY + (fullScaleCellHeight * 0.25)); cellsFromInside = (int) Math.pow(2, (tier - 1)); } } LOG.info("buildUpperLeftTierDimensionsList: returning dimensions for {} tiers: {}", list.size(), list); return list; } }
TierDimensions implements Serializable { static List<TierDimensions> buildUpperLeftTierDimensionsList(final Bounds roughStackFullScaleBounds, final int cellPixelWidth, final int cellPixelHeight) { final int fullScaleWidth = (int) Math.ceil(roughStackFullScaleBounds.getDeltaX()); final int fullScaleHeight = (int) Math.ceil(roughStackFullScaleBounds.getDeltaY()); int fullScaleCellWidth = cellPixelWidth; int fullScaleCellHeight = cellPixelHeight; double scale = 1.0; int tierCount = 0; int rows; int columns; do { tierCount++; fullScaleCellWidth *= 2; fullScaleCellHeight *= 2; scale /= 2.0; rows = (int) Math.ceil(fullScaleHeight / (double) fullScaleCellHeight); columns = (int) Math.ceil(fullScaleWidth / (double) fullScaleCellWidth); } while (((fullScaleCellWidth < fullScaleWidth) || (fullScaleCellHeight < fullScaleHeight)) && (rows > 3) && (columns > 3)); fullScaleCellWidth /= 2; fullScaleCellHeight /= 2; scale *= 2.0; rows = (int) Math.ceil(fullScaleHeight / (cellPixelHeight / scale)); columns = (int) Math.ceil(fullScaleWidth / (cellPixelWidth / scale)); final List<TierDimensions> list = new ArrayList<>(tierCount); list.add(buildTierZero(roughStackFullScaleBounds, cellPixelWidth, cellPixelHeight)); if (tierCount > 1) { int minX = (int) Math.floor(roughStackFullScaleBounds.getMinX()); int minY = (int) Math.floor(roughStackFullScaleBounds.getMinY()); Bounds fullScaleBounds = new Bounds((double) minX, (double) minY, roughStackFullScaleBounds.getMinZ(), (double) (minX + (columns * fullScaleCellWidth)), (double) (minY + (rows * fullScaleCellHeight)), roughStackFullScaleBounds.getMaxZ()); list.add(new TierDimensions(fullScaleCellWidth, fullScaleCellHeight, scale, rows, columns, fullScaleBounds)); int insideCenterX = (int) Math.floor(fullScaleBounds.getMinX() + (fullScaleCellWidth * 0.25)); int insideCenterY = (int) Math.floor(fullScaleBounds.getMinY() + (fullScaleCellHeight * 0.25)); int cellsFromInside = 1; for (int tier = 2; tier <= tierCount; tier++) { fullScaleCellWidth /= 2; fullScaleCellHeight /= 2; scale *= 2.0; minX = (int) Math.floor(insideCenterX - (cellsFromInside * fullScaleCellWidth)); minY = (int) Math.floor(insideCenterY - (cellsFromInside * fullScaleCellHeight)); rows = (int) Math.ceil((roughStackFullScaleBounds.getMaxY() - minY) / fullScaleCellHeight); columns = (int) Math.ceil((roughStackFullScaleBounds.getMaxX() - minX) / fullScaleCellWidth); fullScaleBounds = new Bounds((double) minX, (double) minY, roughStackFullScaleBounds.getMinZ(), (double) (minX + (columns * fullScaleCellWidth)), (double) (minY + (rows * fullScaleCellHeight)), roughStackFullScaleBounds.getMaxZ()); list.add(new TierDimensions(fullScaleCellWidth, fullScaleCellHeight, scale, rows, columns, fullScaleBounds)); insideCenterX = (int) Math.floor(insideCenterX + (fullScaleCellWidth * 0.25)); insideCenterY = (int) Math.floor(insideCenterY + (fullScaleCellHeight * 0.25)); cellsFromInside = (int) Math.pow(2, (tier - 1)); } } LOG.info("buildUpperLeftTierDimensionsList: returning dimensions for {} tiers: {}", list.size(), list); return list; } private  TierDimensions(final int fullScaleCellWidth,
                           final int fullScaleCellHeight,
                           final double scale,
                           final int rows,
                           final int columns,
                           final Bounds fullScaleBounds); }
TierDimensions implements Serializable { static List<TierDimensions> buildUpperLeftTierDimensionsList(final Bounds roughStackFullScaleBounds, final int cellPixelWidth, final int cellPixelHeight) { final int fullScaleWidth = (int) Math.ceil(roughStackFullScaleBounds.getDeltaX()); final int fullScaleHeight = (int) Math.ceil(roughStackFullScaleBounds.getDeltaY()); int fullScaleCellWidth = cellPixelWidth; int fullScaleCellHeight = cellPixelHeight; double scale = 1.0; int tierCount = 0; int rows; int columns; do { tierCount++; fullScaleCellWidth *= 2; fullScaleCellHeight *= 2; scale /= 2.0; rows = (int) Math.ceil(fullScaleHeight / (double) fullScaleCellHeight); columns = (int) Math.ceil(fullScaleWidth / (double) fullScaleCellWidth); } while (((fullScaleCellWidth < fullScaleWidth) || (fullScaleCellHeight < fullScaleHeight)) && (rows > 3) && (columns > 3)); fullScaleCellWidth /= 2; fullScaleCellHeight /= 2; scale *= 2.0; rows = (int) Math.ceil(fullScaleHeight / (cellPixelHeight / scale)); columns = (int) Math.ceil(fullScaleWidth / (cellPixelWidth / scale)); final List<TierDimensions> list = new ArrayList<>(tierCount); list.add(buildTierZero(roughStackFullScaleBounds, cellPixelWidth, cellPixelHeight)); if (tierCount > 1) { int minX = (int) Math.floor(roughStackFullScaleBounds.getMinX()); int minY = (int) Math.floor(roughStackFullScaleBounds.getMinY()); Bounds fullScaleBounds = new Bounds((double) minX, (double) minY, roughStackFullScaleBounds.getMinZ(), (double) (minX + (columns * fullScaleCellWidth)), (double) (minY + (rows * fullScaleCellHeight)), roughStackFullScaleBounds.getMaxZ()); list.add(new TierDimensions(fullScaleCellWidth, fullScaleCellHeight, scale, rows, columns, fullScaleBounds)); int insideCenterX = (int) Math.floor(fullScaleBounds.getMinX() + (fullScaleCellWidth * 0.25)); int insideCenterY = (int) Math.floor(fullScaleBounds.getMinY() + (fullScaleCellHeight * 0.25)); int cellsFromInside = 1; for (int tier = 2; tier <= tierCount; tier++) { fullScaleCellWidth /= 2; fullScaleCellHeight /= 2; scale *= 2.0; minX = (int) Math.floor(insideCenterX - (cellsFromInside * fullScaleCellWidth)); minY = (int) Math.floor(insideCenterY - (cellsFromInside * fullScaleCellHeight)); rows = (int) Math.ceil((roughStackFullScaleBounds.getMaxY() - minY) / fullScaleCellHeight); columns = (int) Math.ceil((roughStackFullScaleBounds.getMaxX() - minX) / fullScaleCellWidth); fullScaleBounds = new Bounds((double) minX, (double) minY, roughStackFullScaleBounds.getMinZ(), (double) (minX + (columns * fullScaleCellWidth)), (double) (minY + (rows * fullScaleCellHeight)), roughStackFullScaleBounds.getMaxZ()); list.add(new TierDimensions(fullScaleCellWidth, fullScaleCellHeight, scale, rows, columns, fullScaleBounds)); insideCenterX = (int) Math.floor(insideCenterX + (fullScaleCellWidth * 0.25)); insideCenterY = (int) Math.floor(insideCenterY + (fullScaleCellHeight * 0.25)); cellsFromInside = (int) Math.pow(2, (tier - 1)); } } LOG.info("buildUpperLeftTierDimensionsList: returning dimensions for {} tiers: {}", list.size(), list); return list; } private  TierDimensions(final int fullScaleCellWidth,
                           final int fullScaleCellHeight,
                           final double scale,
                           final int rows,
                           final int columns,
                           final Bounds fullScaleBounds); int getRows(); int getColumns(); double getScale(); double getMinX(); double getMinY(); @Override String toString(); String toJson(); @JsonIgnore List<HierarchicalStack> getSplitStacks(final StackId roughTilesStackId,
                                                  final int tier); static List<TierDimensions> buildTierDimensionsList(final LayerSplitMethod splitMethod,
                                                               final Bounds roughStackFullScaleBounds,
                                                               final int cellPixelWidth,
                                                               final int cellPixelHeight,
                                                               final Integer maxNumberOfTiers); }
TierDimensions implements Serializable { static List<TierDimensions> buildUpperLeftTierDimensionsList(final Bounds roughStackFullScaleBounds, final int cellPixelWidth, final int cellPixelHeight) { final int fullScaleWidth = (int) Math.ceil(roughStackFullScaleBounds.getDeltaX()); final int fullScaleHeight = (int) Math.ceil(roughStackFullScaleBounds.getDeltaY()); int fullScaleCellWidth = cellPixelWidth; int fullScaleCellHeight = cellPixelHeight; double scale = 1.0; int tierCount = 0; int rows; int columns; do { tierCount++; fullScaleCellWidth *= 2; fullScaleCellHeight *= 2; scale /= 2.0; rows = (int) Math.ceil(fullScaleHeight / (double) fullScaleCellHeight); columns = (int) Math.ceil(fullScaleWidth / (double) fullScaleCellWidth); } while (((fullScaleCellWidth < fullScaleWidth) || (fullScaleCellHeight < fullScaleHeight)) && (rows > 3) && (columns > 3)); fullScaleCellWidth /= 2; fullScaleCellHeight /= 2; scale *= 2.0; rows = (int) Math.ceil(fullScaleHeight / (cellPixelHeight / scale)); columns = (int) Math.ceil(fullScaleWidth / (cellPixelWidth / scale)); final List<TierDimensions> list = new ArrayList<>(tierCount); list.add(buildTierZero(roughStackFullScaleBounds, cellPixelWidth, cellPixelHeight)); if (tierCount > 1) { int minX = (int) Math.floor(roughStackFullScaleBounds.getMinX()); int minY = (int) Math.floor(roughStackFullScaleBounds.getMinY()); Bounds fullScaleBounds = new Bounds((double) minX, (double) minY, roughStackFullScaleBounds.getMinZ(), (double) (minX + (columns * fullScaleCellWidth)), (double) (minY + (rows * fullScaleCellHeight)), roughStackFullScaleBounds.getMaxZ()); list.add(new TierDimensions(fullScaleCellWidth, fullScaleCellHeight, scale, rows, columns, fullScaleBounds)); int insideCenterX = (int) Math.floor(fullScaleBounds.getMinX() + (fullScaleCellWidth * 0.25)); int insideCenterY = (int) Math.floor(fullScaleBounds.getMinY() + (fullScaleCellHeight * 0.25)); int cellsFromInside = 1; for (int tier = 2; tier <= tierCount; tier++) { fullScaleCellWidth /= 2; fullScaleCellHeight /= 2; scale *= 2.0; minX = (int) Math.floor(insideCenterX - (cellsFromInside * fullScaleCellWidth)); minY = (int) Math.floor(insideCenterY - (cellsFromInside * fullScaleCellHeight)); rows = (int) Math.ceil((roughStackFullScaleBounds.getMaxY() - minY) / fullScaleCellHeight); columns = (int) Math.ceil((roughStackFullScaleBounds.getMaxX() - minX) / fullScaleCellWidth); fullScaleBounds = new Bounds((double) minX, (double) minY, roughStackFullScaleBounds.getMinZ(), (double) (minX + (columns * fullScaleCellWidth)), (double) (minY + (rows * fullScaleCellHeight)), roughStackFullScaleBounds.getMaxZ()); list.add(new TierDimensions(fullScaleCellWidth, fullScaleCellHeight, scale, rows, columns, fullScaleBounds)); insideCenterX = (int) Math.floor(insideCenterX + (fullScaleCellWidth * 0.25)); insideCenterY = (int) Math.floor(insideCenterY + (fullScaleCellHeight * 0.25)); cellsFromInside = (int) Math.pow(2, (tier - 1)); } } LOG.info("buildUpperLeftTierDimensionsList: returning dimensions for {} tiers: {}", list.size(), list); return list; } private  TierDimensions(final int fullScaleCellWidth,
                           final int fullScaleCellHeight,
                           final double scale,
                           final int rows,
                           final int columns,
                           final Bounds fullScaleBounds); int getRows(); int getColumns(); double getScale(); double getMinX(); double getMinY(); @Override String toString(); String toJson(); @JsonIgnore List<HierarchicalStack> getSplitStacks(final StackId roughTilesStackId,
                                                  final int tier); static List<TierDimensions> buildTierDimensionsList(final LayerSplitMethod splitMethod,
                                                               final Bounds roughStackFullScaleBounds,
                                                               final int cellPixelWidth,
                                                               final int cellPixelHeight,
                                                               final Integer maxNumberOfTiers); static final JsonUtils.Helper<TierDimensions> JSON_HELPER; }