Ejemplo n.º 1
0
  public void loadGridNet(String mapGrid) throws IOException {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(mapGrid));

    logger.debug("loading {}...", mapGrid);

    CSVReader reader = new CSVReader(new FileReader(mapGrid), ',', '"', 1);
    String[] row;
    while ((row = reader.readNext()) != null) {
      String gridId = row[1].trim();
      String dmRoads = row[2].trim();
      String gjRoads = row[3].trim();

      Set<String> x =
          Sets.newHashSet(Splitter.on('|').trimResults().omitEmptyStrings().split(dmRoads));
      Set<String> y =
          Sets.newHashSet(Splitter.on('|').trimResults().omitEmptyStrings().split(gjRoads));
      if (x.size() > 0 || y.size() > 0) {
        MapGrid grid = new MapGrid();
        grid.dmRoads = x;
        grid.gjRoads = y;

        gridNet.put(gridId, grid);
        //                logger.debug("{},{},{}", gridId, x, y);
      }
    }

    reader.close();
  }
Ejemplo n.º 2
0
  public List<RoadLink> getRoadLinks(Point2D pos, boolean isGrid) {
    int row =
        (int)
            ((pos.getX() - fcdSettings.getMap().getxOffset())
                / fcdSettings.getMap().getGridLength());
    int col =
        (int)
            ((pos.getY() - fcdSettings.getMap().getyOffset())
                / fcdSettings.getMap().getGridLength());

    Set<String> links = new HashSet();
    for (int i = -1; i <= 1; i++) {
      for (int j = -1; j <= 1; j++) {
        String grid = row + "+" + col;
        Optional<MapGrid> mapGrid = Optional.fromNullable(gridNet.get(grid));
        if (mapGrid.isPresent()) {
          links.addAll(mapGrid.get().union());
        }
      }
    }

    //        logger.debug("---->{}", links);

    List<RoadLink> roads = new ArrayList();

    for (String linkId : links) {
      //            logger.debug("=>{}", linkId);

      Optional<RoadLink> roadLink = Optional.fromNullable(roadNet.get(Integer.valueOf(linkId)));
      if (roadLink.isPresent()) {
        RoadLink link = roadLink.get();
        if (link.xmin < pos.getX() + 50
            && link.ymin < pos.getY() + 50
            && link.xmax > pos.getX() - 50
            && link.ymax > pos.getY() - 50) {
          roads.add(link);
        }
      }
    }

    return roads;
  }