private Info[] buildSurfaceShapes() { LatLon position = new LatLon(Angle.fromDegrees(38), Angle.fromDegrees(-105)); ArrayList<LatLon> surfaceLinePositions = new ArrayList<LatLon>(); // surfaceLinePositions.add(LatLon.fromDegrees(37.8484, -119.9754)); // surfaceLinePositions.add(LatLon.fromDegrees(38.3540, -119.1526)); // surfaceLinePositions.add(new LatLon(Angle.fromDegrees(0), // Angle.fromDegrees(-150))); // surfaceLinePositions.add(new LatLon(Angle.fromDegrees(60), // Angle.fromDegrees(0))); surfaceLinePositions.add(position); surfaceLinePositions.add(LatLon.fromDegrees(39, -104)); surfaceLinePositions.add(LatLon.fromDegrees(39, -105)); surfaceLinePositions.add(position); return new Info[] { new Info("Circle", new SurfaceCircle(position, 100e3)), new Info("Ellipse", new SurfaceEllipse(position, 100e3, 90e3, Angle.ZERO)), new Info("Square", new SurfaceSquare(position, 100e3)), new Info("Quad", new SurfaceQuad(position, 100e3, 60e3, Angle.ZERO)), new Info("Sector", new SurfaceSector(Sector.fromDegrees(38, 40, -105, -103))), new Info("Polygon", new SurfacePolygon(surfaceLinePositions)), }; }
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; }
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); } }
public AppFrame() { super(true, true, false); try { // Create the Quad from a Sector Globe globe = this.getWwd().getModel().getGlobe(); double radius = globe.getRadiusAt(sector.getCentroid()); double quadWidth = sector.getDeltaLonRadians() * radius; double quadHeight = sector.getDeltaLatRadians() * radius; final SurfaceQuad quad = new SurfaceQuad(sector.getCentroid(), quadWidth, quadHeight, Angle.ZERO); // Create the layer to hold it final RenderableLayer layer = new RenderableLayer(); layer.setName("Rotating Sector"); layer.addRenderable(quad); // Add the layer to the model and update the ApplicationTemplate's layer manager insertBeforeCompass(this.getWwd(), layer); this.getLayerPanel().update(this.getWwd()); // Rotate the quad continuously Timer timer = new Timer( 50, new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { // Increment the current heading if the layer is visible if (layer.isEnabled()) { quad.setHeading( Angle.fromDegrees((quad.getHeading().getDegrees() + 1) % 360)); getWwd().redraw(); } } }); timer.start(); } catch (Exception e) { e.printStackTrace(); } }
private Info[] buildFreeShapes() { double elevation = 10e3; ArrayList<Position> positions = new ArrayList<Position>(); positions.add( new Position(Angle.fromDegrees(37.8484), Angle.fromDegrees(-119.9754), elevation)); positions.add( new Position(Angle.fromDegrees(39.3540), Angle.fromDegrees(-110.1526), elevation)); positions.add( new Position(Angle.fromDegrees(38.3540), Angle.fromDegrees(-100.1526), elevation)); ArrayList<Position> positions2 = new ArrayList<Position>(); positions2.add(new Position(Angle.fromDegrees(0), Angle.fromDegrees(-150), elevation)); positions2.add(new Position(Angle.fromDegrees(25), Angle.fromDegrees(-75), elevation)); positions2.add(new Position(Angle.fromDegrees(50), Angle.fromDegrees(0), elevation)); ArrayList<Position> positions3 = new ArrayList<Position>(); for (double lat = 42, lon = -100; lat <= 45; lat += .1, lon += .1) { positions3.add(new Position(Angle.fromDegrees(lat), Angle.fromDegrees(lon), elevation)); } ArrayList<Position> positions4 = new ArrayList<Position>(); positions4.add(new Position(Angle.fromDegrees(90), Angle.fromDegrees(-110), elevation)); positions4.add(new Position(Angle.fromDegrees(-90), Angle.fromDegrees(-110), elevation)); ArrayList<Position> positions5 = new ArrayList<Position>(); for (int i = 0; i < 100; i++) { positions5.add( Position.fromDegrees(38.0 + i * 0.0001, 30.0 + i * 0.0001, 1000.0 + i * 5.0)); } @SuppressWarnings({"UnnecessaryLocalVariable"}) Info[] infos = new Info[] { new Info("Short Path", new Polyline(positions)), new Info("Long Path", new Polyline(positions2)), new Info("Incremental Path", new Polyline(positions3)), new Info("Vertical Path", new Polyline(positions4)), new Info("Small-segment Path", new Polyline(positions5)), new Info("Quad", new Quadrilateral(Sector.fromDegrees(38, 40, -104, -105), elevation)), new Info("None", null) }; return infos; }
public void doActionOnButton2() { ArrayList<LatLon> latlons = new ArrayList<LatLon>(); latlons.add(LatLon.fromDegrees(45.50d, -123.3d)); // latlons.add( LatLon.fromDegrees( 45.51d, -123.3d ) ); latlons.add(LatLon.fromDegrees(45.52d, -123.3d)); // latlons.add( LatLon.fromDegrees( 45.53d, -123.3d ) ); latlons.add(LatLon.fromDegrees(45.54d, -123.3d)); // latlons.add( LatLon.fromDegrees( 45.55d, -123.3d ) ); latlons.add(LatLon.fromDegrees(45.56d, -123.3d)); // latlons.add( LatLon.fromDegrees( 45.57d, -123.3d ) ); latlons.add(LatLon.fromDegrees(45.58d, -123.3d)); // latlons.add( LatLon.fromDegrees( 45.59d, -123.3d ) ); latlons.add(LatLon.fromDegrees(45.60d, -123.3d)); Sector sector = Sector.fromDegrees(44d, 46d, -123d, -121d); // Sector sector = Sector.boundingSector( latlons ); double[] elevations = new double[latlons.size()]; // request resolution of DTED2 (1degree / 3600 ) double targetResolution = Angle.fromDegrees(1d).radians / 3600; double resolutionAchieved = this.wwd .getModel() .getGlobe() .getElevationModel() .getElevations(sector, latlons, targetResolution, elevations); StringBuffer sb = new StringBuffer(); for (double e : elevations) { sb.append("\n").append(e); } sb.append("\nresolutionAchieved = ").append(resolutionAchieved); sb.append(", requested resolution = ").append(targetResolution); Logging.logger().info(sb.toString()); }
@Override public void render(DrawContext dc) { if (dc.isPickingMode() && this.isResizeable()) return; // This is called twice: once during normal rendering, then again during ordered surface // rendering. During // normal renering we render both the interior and border shapes. During ordered surface // rendering, both // shapes are already added to the DrawContext and both will be individually processed. // Therefore we just // call our superclass behavior if (dc.isOrderedRenderingMode()) { super.render(dc); return; } if (!this.isResizeable()) { if (this.hasSelection()) { this.doRender(dc); } return; } PickedObjectList pos = dc.getPickedObjects(); PickedObject terrainObject = pos != null ? pos.getTerrainObject() : null; if (terrainObject == null) return; if (this.getStartPosition() != null) { Position end = terrainObject.getPosition(); if (!this.getStartPosition().equals(end)) { this.setEndPosition(end); this.setSector(Sector.boundingSector(this.getStartPosition(), this.getEndPosition())); this.doRender(dc); } } else { this.setStartPosition(pos.getTerrainObject().getPosition()); } }
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 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; }