public int countImagesInSector(Sector sector, int levelNumber) {
    if (sector == null) {
      String msg = Logging.getMessage("nullValue.SectorIsNull");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    Level targetLevel = this.levels.getLastLevel();
    if (levelNumber >= 0) {
      for (int i = levelNumber; i < this.getLevels().getLastLevel().getLevelNumber(); i++) {
        if (this.levels.isLevelEmpty(i)) continue;

        targetLevel = this.levels.getLevel(i);
        break;
      }
    }

    // Collect all the tiles intersecting the input sector.
    LatLon delta = targetLevel.getTileDelta();
    Angle latOrigin = this.levels.getTileOrigin().getLatitude();
    Angle lonOrigin = this.levels.getTileOrigin().getLongitude();
    final int nwRow = Tile.computeRow(delta.getLatitude(), sector.getMaxLatitude(), latOrigin);
    final int nwCol = Tile.computeColumn(delta.getLongitude(), sector.getMinLongitude(), lonOrigin);
    final int seRow = Tile.computeRow(delta.getLatitude(), sector.getMinLatitude(), latOrigin);
    final int seCol = Tile.computeColumn(delta.getLongitude(), sector.getMaxLongitude(), lonOrigin);

    int numRows = nwRow - seRow + 1;
    int numCols = seCol - nwCol + 1;

    return numRows * numCols;
  }
Esempio n. 2
0
  protected int determineAdjustmentSide(Movable dragObject, double factor) {
    if (dragObject instanceof SurfaceSector) {
      SurfaceSector quad = (SurfaceSector) dragObject;
      Sector s = quad.getSector(); // TODO: go over all sectors
      Position p = this.getWwd().getCurrentPosition();

      if (p == null) {
        return NONE;
      }

      double dN = abs(s.getMaxLatitude().subtract(p.getLatitude()).degrees);
      double dS = abs(s.getMinLatitude().subtract(p.getLatitude()).degrees);
      double dW = abs(s.getMinLongitude().subtract(p.getLongitude()).degrees);
      double dE = abs(s.getMaxLongitude().subtract(p.getLongitude()).degrees);

      double sLat = factor * s.getDeltaLatDegrees();
      double sLon = factor * s.getDeltaLonDegrees();

      if (dN < sLat && dW < sLon) return NORTHWEST;
      if (dN < sLat && dE < sLon) return NORTHEAST;
      if (dS < sLat && dW < sLon) return SOUTHWEST;
      if (dS < sLat && dE < sLon) return SOUTHEAST;
      if (dN < sLat) return NORTH;
      if (dS < sLat) return SOUTH;
      if (dW < sLon) return WEST;
      if (dE < sLon) return EAST;
    }

    return NONE;
  }
Esempio n. 3
0
  protected Sector resizeShape(Movable dragObject, int side) {
    if (dragObject instanceof SurfaceSector) {
      SurfaceSector quad = (SurfaceSector) dragObject;
      Sector s = quad.getSector(); // TODO: go over all sectors
      Position p = this.getWwd().getCurrentPosition();

      if (p == null || this.getPreviousPosition() == null) {
        return null;
      }

      Angle dLat = p.getLatitude().subtract(this.getPreviousPosition().getLatitude());
      Angle dLon = p.getLongitude().subtract(this.getPreviousPosition().getLongitude());

      Angle newMinLat = s.getMinLatitude();
      Angle newMinLon = s.getMinLongitude();
      Angle newMaxLat = s.getMaxLatitude();
      Angle newMaxLon = s.getMaxLongitude();

      if (side == NORTH) {
        newMaxLat = s.getMaxLatitude().add(dLat);
      } else if (side == SOUTH) {
        newMinLat = s.getMinLatitude().add(dLat);
      } else if (side == EAST) {
        newMaxLon = s.getMaxLongitude().add(dLon);
      } else if (side == WEST) {
        newMinLon = s.getMinLongitude().add(dLon);
      } else if (side == NORTHWEST) {
        newMaxLat = s.getMaxLatitude().add(dLat);
        newMinLon = s.getMinLongitude().add(dLon);
      } else if (side == NORTHEAST) {
        newMaxLat = s.getMaxLatitude().add(dLat);
        newMaxLon = s.getMaxLongitude().add(dLon);
      } else if (side == SOUTHWEST) {
        newMinLat = s.getMinLatitude().add(dLat);
        newMinLon = s.getMinLongitude().add(dLon);
      } else if (side == SOUTHEAST) {
        newMinLat = s.getMinLatitude().add(dLat);
        newMaxLon = s.getMaxLongitude().add(dLon);
      }

      return new Sector(newMinLat, newMaxLat, newMinLon, newMaxLon);
    }

    return null;
  }
  protected static boolean isSectorVisible(
      DrawContext dc, Sector sector, double minDistanceSquared, double maxDistanceSquared) {

    View view = dc.getView();
    Position eyePos = view.getEyePosition();
    if (eyePos == null) return false;

    Angle lat = clampAngle(eyePos.getLatitude(), sector.getMinLatitude(), sector.getMaxLatitude());
    Angle lon =
        clampAngle(eyePos.getLongitude(), sector.getMinLongitude(), sector.getMaxLongitude());
    Vec4 p = dc.getGlobe().computePointFromPosition(lat, lon, 0d);
    double distSquared = dc.getView().getEyePoint().distanceToSquared3(p);
    //noinspection RedundantIfStatement
    if (minDistanceSquared > distSquared || maxDistanceSquared < distSquared) return false;

    return true;
  }
  private MercatorTextureTile[][] getTilesInSector(Sector sector, int levelNumber) {
    if (sector == null) {
      String msg = Logging.getMessage("nullValue.SectorIsNull");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    Level targetLevel = this.levels.getLastLevel();
    if (levelNumber >= 0) {
      for (int i = levelNumber; i < this.getLevels().getLastLevel().getLevelNumber(); i++) {
        if (this.levels.isLevelEmpty(i)) continue;

        targetLevel = this.levels.getLevel(i);
        break;
      }
    }

    // Collect all the tiles intersecting the input sector.
    LatLon delta = targetLevel.getTileDelta();
    Angle latOrigin = this.levels.getTileOrigin().getLatitude();
    Angle lonOrigin = this.levels.getTileOrigin().getLongitude();
    final int nwRow = Tile.computeRow(delta.getLatitude(), sector.getMaxLatitude(), latOrigin);
    final int nwCol = Tile.computeColumn(delta.getLongitude(), sector.getMinLongitude(), lonOrigin);
    final int seRow = Tile.computeRow(delta.getLatitude(), sector.getMinLatitude(), latOrigin);
    final int seCol = Tile.computeColumn(delta.getLongitude(), sector.getMaxLongitude(), lonOrigin);

    int numRows = nwRow - seRow + 1;
    int numCols = seCol - nwCol + 1;
    MercatorTextureTile[][] sectorTiles = new MercatorTextureTile[numRows][numCols];

    for (int row = nwRow; row >= seRow; row--) {
      for (int col = nwCol; col <= seCol; col++) {
        TileKey key =
            new TileKey(targetLevel.getLevelNumber(), row, col, targetLevel.getCacheName());
        Sector tileSector = this.levels.computeSectorForKey(key);
        MercatorSector mSector = MercatorSector.fromSector(tileSector); // TODO: check
        sectorTiles[nwRow - row][col - nwCol] =
            new MercatorTextureTile(mSector, targetLevel, row, col);
      }
    }

    return sectorTiles;
  }
    protected List<Position> buildGrid(Sector sector, double height, int nLatCells, int nLonCells) {
      List<Position> grid = new ArrayList<Position>((nLatCells + 1) * (nLonCells + 1));

      double dLat = sector.getDeltaLatDegrees() / nLatCells;
      double dLon = sector.getDeltaLonDegrees() / nLonCells;

      for (int j = 0; j <= nLatCells; j++) {
        double lat =
            j == nLatCells
                ? sector.getMaxLatitude().degrees
                : sector.getMinLatitude().degrees + j * dLat;

        for (int i = 0; i <= nLonCells; i++) {
          double lon =
              i == nLonCells
                  ? sector.getMaxLongitude().degrees
                  : sector.getMinLongitude().degrees + i * dLon;

          grid.add(Position.fromDegrees(lat, lon, height));
        }
      }

      return grid;
    }
    protected boolean isNavSectorVisible(
        DrawContext dc, double minDistanceSquared, double maxDistanceSquared) {
      if (!navSector.intersects(dc.getVisibleSector())) return false;

      View view = dc.getView();
      Position eyePos = view.getEyePosition();
      if (eyePos == null) return false;

      // check for eyePos over globe
      if (Double.isNaN(eyePos.getLatitude().getDegrees())
          || Double.isNaN(eyePos.getLongitude().getDegrees())) return false;

      Angle lat =
          clampAngle(eyePos.getLatitude(), navSector.getMinLatitude(), navSector.getMaxLatitude());
      Angle lon =
          clampAngle(
              eyePos.getLongitude(), navSector.getMinLongitude(), navSector.getMaxLongitude());
      Vec4 p = dc.getGlobe().computePointFromPosition(lat, lon, 0d);
      double distSquared = dc.getView().getEyePoint().distanceToSquared3(p);
      //noinspection RedundantIfStatement
      if (minDistanceSquared > distSquared || maxDistanceSquared < distSquared) return false;

      return true;
    }