Esempio n. 1
0
 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;
 }
Esempio n. 2
0
  public static void init() {
    EmptyPanel emptyPanel = new EmptyPanel();

    ADDITIONAL_PANELS = new HashMap<>();
    Algorithm randomAlgorithm =
        new FullRandomAlgorithm(Mediator.getMessage(PropertiesKeys.FULL_RANDOM_ALGORITHM));
    Algorithm height = new HeightAlgorithm(Mediator.getMessage(PropertiesKeys.HEIGHT_ALGORITHM));
    Algorithm regularAlgorithm =
        new RegularAlgorithm(Mediator.getMessage(PropertiesKeys.REGULAR_ALGORITHM));
    Algorithm aggregation =
        new AggregationAlgorithm(Mediator.getMessage(PropertiesKeys.AGGREGATION_ALGORITHM));
    Algorithm spread = new SpreadAlgorithm(Mediator.getMessage(PropertiesKeys.SPREAD_ALGORITHM));
    Algorithm mask = new MaskAlgorithm(Mediator.getMessage(PropertiesKeys.MASK_ALGORITHM));

    ADDITIONAL_PANELS.put(randomAlgorithm, emptyPanel);
    ADDITIONAL_PANELS.put(regularAlgorithm, emptyPanel);
    ADDITIONAL_PANELS.put(height, new HeightAlgorithmPanel());
    ADDITIONAL_PANELS.put(aggregation, emptyPanel);
    ADDITIONAL_PANELS.put(spread, new SpreadAlgorithmPanel());
    ADDITIONAL_PANELS.put(mask, new MaskAlgorithmPanel());

    EmptyMainPanel emptyMainPanel = new EmptyMainPanel();
    MAIN_PANELS = new HashMap<>();
    MAIN_PANELS.put(randomAlgorithm, emptyMainPanel);
    MAIN_PANELS.put(regularAlgorithm, new RegularAlgorithmMainPanel());
    MAIN_PANELS.put(height, emptyMainPanel);
    MAIN_PANELS.put(aggregation, new AggregationAlgorithmPanel());
    MAIN_PANELS.put(spread, emptyMainPanel);
    MAIN_PANELS.put(mask, emptyMainPanel);
  }
Esempio n. 3
0
  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;
  }
Esempio n. 4
0
  public List<GeneratedObject> generate(GenerationInfo info) {
    long time = System.currentTimeMillis();
    int collisionsValue = info.getArgs().get(Consts.COLLISIONS).intValue();
    collisions = collisionsValue == 1 ? true : false;
    Dimension mapDimensions = Mediator.getMapDimensions();
    if (mapDimensions == null) {
      WindowUtil.displayError(PropertiesKeys.NO_HEIGHTMAP);
      return new ArrayList<>();
    }
    if (collisions) {
      collisionTree =
          TreeNode.createTree(
              Mediator.getMapWidth(),
              Mediator.getMapHeight(),
              (short) (Math.log(mapDimensions.getWidth()) / Math.log(2)));
    }
    xRatio = Mediator.getMapWidth() / mapDimensions.width;
    zRatio = Mediator.getMapHeight() / mapDimensions.height;
    yRatio = Mediator.getMapMaxYSetting() / Mediator.getMapMaxY();
    HeightInfo.setThreshold((xRatio + zRatio) / 2.0);

    List<GeneratedObject> result = generationMethod(info);
    Mediator.updateModels(result);
    time = System.currentTimeMillis() - time;
    System.out.println("Time used: " + time + " ms.");
    time /= 1000F;
    collisionTree = null;
    int size = result.size();
    if (collisionDetected) {
      collisionDetected = false;
      WindowUtil.displayError(PropertiesKeys.COLLISION, size, time);
    } else {
      if (size > 0) {
        WindowUtil.displayInfo(PropertiesKeys.RESULT, size, time);
      } else {
        WindowUtil.displayError(PropertiesKeys.NO_RESULT);
      }
    }
    return result;
  }
Esempio n. 5
0
 public String getHelp() {
   return Mediator.getMessage(helpKey);
 }
Esempio n. 6
0
 protected List<List<HeightInfo>> findHeights() {
   return findHeights(Mediator.getMapImage(), xRatio, zRatio);
 }
 public AlgorithmAdditionalPanel() {
   setBorder(
       BorderFactory.createTitledBorder(
           Mediator.getMessage(PropertiesKeys.ALGORITHM_ADDITIONAL_ARGUMENTS)));
 }