/**
     * Performs one line of sight calculation between the reference position and a specified grid
     * position.
     *
     * @param gridPosition the grid position.
     * @throws InterruptedException if the operation is interrupted.
     */
    protected void performIntersection(Position gridPosition) throws InterruptedException {
      // Intersect the line between this grid point and the selected position.
      Intersection[] intersections = this.terrain.intersect(this.referencePosition, gridPosition);
      if (intersections == null || intersections.length == 0) {
        // No intersection, so the line goes from the center to the grid point.
        this.sightLines.add(new Position[] {this.referencePosition, gridPosition});
        return;
      }

      // Only the first intersection is shown.
      Vec4 iPoint = intersections[0].getIntersectionPoint();
      Vec4 gPoint =
          terrain.getSurfacePoint(
              gridPosition.getLatitude(), gridPosition.getLongitude(), gridPosition.getAltitude());

      // Check to see whether the intersection is beyond the grid point.
      if (iPoint.distanceTo3(this.referencePoint) >= gPoint.distanceTo3(this.referencePoint)) {
        // Intersection is beyond the grid point; the line goes from the center to the grid point.
        this.addSightLine(this.referencePosition, gridPosition);
        return;
      }

      // Compute the position corresponding to the intersection.
      Position iPosition = this.terrain.getGlobe().computePositionFromPoint(iPoint);

      // The sight line goes from the user-selected position to the intersection position.
      this.addSightLine(this.referencePosition, new Position(iPosition, 0));

      // Keep track of the intersection positions.
      this.addIntersectionPosition(iPosition);

      this.updateProgress();
    }
示例#2
0
 public AStarNode createStartNode(Object state) {
   Position p = (Position) state;
   AStarNode n = new AStarNode(p);
   n.setDistTravelled(0);
   n.setApproxTotalDist(p.distance((Position) getEndingState()));
   List<Position> path = new ArrayList<Position>();
   path.add(p);
   n.setPath(path);
   // System.out.print("createStartNode"); n.printNode();
   return n;
 }
示例#3
0
 private boolean inPath(Position pos, List<Position> path) {
   for (Position n : path) {
     if (pos.equals(n)) return true;
   }
   ;
   return false;
 }
    protected void showIntersections(List<Position> intersections) {
      this.intersectionsLayer.removeAllRenderables();

      // Display the intersections as CYAN points.
      PointPlacemarkAttributes intersectionPointAttributes;
      intersectionPointAttributes = new PointPlacemarkAttributes();
      intersectionPointAttributes.setLineMaterial(Material.CYAN);
      intersectionPointAttributes.setScale(6d);
      intersectionPointAttributes.setUsePointAsDefaultImage(true);

      for (Position p : intersections) {
        PointPlacemark pm = new PointPlacemark(p);
        pm.setAltitudeMode(WorldWind.CLAMP_TO_GROUND);
        pm.setAttributes(intersectionPointAttributes);
        pm.setValue(AVKey.DISPLAY_NAME, p.toString());
        this.intersectionsLayer.addRenderable(pm);
      }
    }
    protected void performIntersectionTests(final Position curPos) throws InterruptedException {
      // Clear the results lists when the user selects a new location.
      this.firstIntersectionPositions.clear();
      this.sightLines.clear();

      // Raise the selected location and the grid points a little above ground just to show we can.
      final double height = 5; // meters

      // Form the grid.
      double gridRadius = GRID_RADIUS.degrees;
      Sector sector =
          Sector.fromDegrees(
              curPos.getLatitude().degrees - gridRadius, curPos.getLatitude().degrees + gridRadius,
              curPos.getLongitude().degrees - gridRadius,
                  curPos.getLongitude().degrees + gridRadius);

      this.grid = buildGrid(sector, height, GRID_DIMENSION, GRID_DIMENSION);
      this.numGridPoints = grid.size();

      // Compute the position of the selected location (incorporate its height).
      this.referencePosition = new Position(curPos.getLatitude(), curPos.getLongitude(), height);
      this.referencePoint =
          terrain.getSurfacePoint(curPos.getLatitude(), curPos.getLongitude(), height);

      //            // Pre-caching is unnecessary and is useful only when it occurs before the
      // intersection
      //            // calculations. It will incur extra overhead otherwise. The normal intersection
      // calculations
      //            // cause the same caching, making subsequent calculations on the same area
      // faster.
      //            this.preCache(grid, this.referencePosition);

      // On the EDT, show the grid.
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              progressBar.setValue(0);
              progressBar.setString(null);
              clearLayers();
              showGrid(grid, referencePosition);
              getWwd().redraw();
            }
          });

      // Perform the intersection calculations.
      this.startTime = System.currentTimeMillis();
      for (Position gridPos : this.grid) // for each grid point.
      {
        //noinspection ConstantConditions
        if (NUM_THREADS > 0) this.threadPool.execute(new Intersector(gridPos));
        else performIntersection(gridPos);
      }
    }
    protected void showGrid(List<Position> grid, Position cPos) {
      this.gridLayer.removeAllRenderables();

      // Display the grid points in yellow.
      PointPlacemarkAttributes gridPointAttributes;
      gridPointAttributes = new PointPlacemarkAttributes();
      gridPointAttributes.setLineMaterial(Material.YELLOW);
      gridPointAttributes.setScale(6d);
      gridPointAttributes.setUsePointAsDefaultImage(true);

      for (Position p : grid) {
        PointPlacemark pm = new PointPlacemark(p);
        pm.setAltitudeMode(WorldWind.RELATIVE_TO_GROUND);
        pm.setAttributes(gridPointAttributes);
        pm.setLineEnabled(true);
        pm.setValue(AVKey.DISPLAY_NAME, p.toString());
        this.gridLayer.addRenderable(pm);
      }

      showCenterPoint(cPos);
    }
    protected void showGridSightLines(List<Position> grid, Position cPos) {
      this.sightLinesLayer.removeAllRenderables();

      // Display lines from the center to each grid point.
      ShapeAttributes lineAttributes;
      lineAttributes = new BasicShapeAttributes();
      lineAttributes.setDrawOutline(true);
      lineAttributes.setDrawInterior(false);
      lineAttributes.setOutlineMaterial(Material.GREEN);
      lineAttributes.setOutlineOpacity(0.6);

      for (Position p : grid) {
        List<Position> endPoints = new ArrayList<Position>();
        endPoints.add(cPos);
        endPoints.add(new Position(p.getLatitude(), p.getLongitude(), 0));

        Path path = new Path(endPoints);
        path.setAltitudeMode(WorldWind.RELATIVE_TO_GROUND);
        path.setAttributes(lineAttributes);
        this.sightLinesLayer.addRenderable(path);
      }
    }
    protected void showCenterPoint(Position cPos) {
      // Display the center point in red.
      PointPlacemarkAttributes selectedLocationAttributes;
      selectedLocationAttributes = new PointPlacemarkAttributes();
      selectedLocationAttributes.setLineMaterial(Material.RED);
      selectedLocationAttributes.setScale(8d);
      selectedLocationAttributes.setUsePointAsDefaultImage(true);

      PointPlacemark pm = new PointPlacemark(cPos);
      pm.setAltitudeMode(WorldWind.RELATIVE_TO_GROUND);
      pm.setAttributes(selectedLocationAttributes);
      pm.setValue(AVKey.DISPLAY_NAME, cPos.toString());
      pm.setLineEnabled(true);
      this.gridLayer.addRenderable(pm);
    }
    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;
    }
示例#10
0
  public List<Node> expandFunc(Node n) {
    AStarNode node = (AStarNode) n;
    // loop computes the positions you can get to from node
    List<Node> expandedNodes = new ArrayList<Node>();
    List<Position> path = node.getPath();
    Position pos = node.getPosition();
    int x = pos.getX();
    int y = pos.getY();
    // this next pair of loops will create all the possible moves
    // from pos.
    for (int i = -1; i <= 1; i += 2) { // Checks nodes to left and right
      // create the potential next position
      int nextX = x + i;
      int nextY = y;
      // make sure next point is on the grid
      if ((nextX + 1 > grid.length || nextY + 1 > grid[0].length) || (nextX < 0 || nextY < 0))
        continue;
      Position next = new Position(nextX, nextY);
      // System.out.println("considering"+next);
      if (inPath(next, path) || !next.open(grid)) continue;
      // printCurrentList();
      // System.out.println("available"+next);
      AStarNode nodeTemp = new AStarNode(next);

      // update distance travelled
      nodeTemp.setDistTravelled(node.getDistTravelled() + pos.distance(next));
      // update approximate total distance to destination
      // note that we are computing the straight-line
      // heuristic on the fly right here from next to endingState
      nodeTemp.setApproxTotalDist(next.distance((Position) endingState));
      // update internal path
      nodeTemp.updatePath(path);
      expandedNodes.add(nodeTemp); // could have just added
      // them directly to nodelist
    }

    for (int j = -1; j <= 1; j += 2) { // Checks nodes above and below
      // create the potential next position
      int nextX = x;
      int nextY = y + j;
      // make sure next point is on the grid
      if ((nextX + 1 > grid.length || nextY + 1 > grid[0].length) || (nextX < 0 || nextY < 0))
        continue;
      Position next = new Position(nextX, nextY);
      // System.out.println("considering"+next);
      if (inPath(next, path) || !next.open(grid)) continue;
      // printCurrentList();
      // System.out.println("available"+next);
      AStarNode nodeTemp = new AStarNode(next);

      // update distance travelled
      nodeTemp.setDistTravelled(node.getDistTravelled() + pos.distance(next));
      // update approximate total distance to destination
      // note that we are computing the straight-line
      // heuristic on the fly right here from next to endingState
      nodeTemp.setApproxTotalDist(next.distance((Position) endingState));
      // update internal path
      nodeTemp.updatePath(path);
      expandedNodes.add(nodeTemp); // could have just added
      // them directly to nodelist
    }
    return expandedNodes;
  } // end expandFunc