protected List<List<HeightInfo>> findOriginalHeights(BufferedImage img, double dx, double dz) { Map<Double, List<HeightInfo>> heights = new HashMap<>(); int width = img.getWidth(); int height = img.getHeight(); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { double y = PreviewPanel.getColor(img, i, j); List<HeightInfo> list = heights.get(y); if (list == null) { list = new ArrayList<>(); heights.put(y, list); } double x = (width / 2 - i) * dx; double z = (height / 2 - j) * dz; list.add(new HeightInfo(x, y, z)); } } List<List<HeightInfo>> points = new ArrayList<>(heights.values()); points.sort( new Comparator<List<HeightInfo>>() { @Override public int compare(List<HeightInfo> o1, List<HeightInfo> o2) { return o1.get(0).compareTo(o2.get(0)); } }); return points; }
protected List<HeightInfo> availableSpace(ModelInfo info) { List<HeightInfo> list = new LinkedList<>(); BufferedImage mask = info.getMask(); if (mask == null) { info.parseMask(); if (mask == null) { return list; } } int width = mask.getWidth(); int height = mask.getHeight(); double xr = Mediator.getMapWidth() / width; double zr = Mediator.getMapHeight() / height; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { double y = PreviewPanel.getColor(mask, i, j); if (y >= 128) { double x = (width / 2 - i) * xr; double z = (height / 2 - j) * zr; list.add(new HeightInfo(x, y, z)); } } } return list; }
protected List<List<HeightInfo>> findHeights(BufferedImage img, double dx, double dz) { Map<Double, List<HeightInfo>> heights = new HashMap<>(); int width = img.getWidth(); int height = img.getHeight(); max = Integer.MIN_VALUE; double mapMaxYSetting = Mediator.getMapMaxYSetting(); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { int tmp = PreviewPanel.getColor(img, i, j); if (tmp > max) { max = tmp; } } } for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { double y = (Mediator.getMapHeightAt(i, j) - 128) * (mapMaxYSetting / (max - 128)); List<HeightInfo> list = heights.get(y); if (list == null) { list = new ArrayList<>(); heights.put(y, list); } double x = (width / 2 - i) * dx; double z = (height / 2 - j) * dz; list.add(new HeightInfo(x, y, z)); } } List<List<HeightInfo>> points = new ArrayList<>(heights.values()); points.sort( new Comparator<List<HeightInfo>>() { @Override public int compare(List<HeightInfo> o1, List<HeightInfo> o2) { return o1.get(0).compareTo(o2.get(0)); } }); return points; }