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; }
public void createRenderables() { this.gridElements = new ArrayList<GridElement>(); double gridStep = this.size / 10; Position p1, p2; ArrayList<Position> positions = new ArrayList<Position>(); // South-North lines for (int i = 1; i <= 9; i++) { double easting = this.SWEasting + gridStep * i; positions.clear(); p1 = computePosition(this.UTMZone, this.hemisphere, easting, SWNorthing); p2 = computePosition(this.UTMZone, this.hemisphere, easting, SWNorthing + this.size); if (this.isTruncated) { computeTruncatedSegment(p1, p2, this.UTMZoneSector, positions); } else { positions.add(p1); positions.add(p2); } if (positions.size() > 0) { p1 = positions.get(0); p2 = positions.get(1); Object polyline = createLineRenderable(positions, Polyline.GREAT_CIRCLE); Sector lineSector = Sector.boundingSector(p1, p2); GridElement ge = new GridElement(lineSector, polyline, GridElement.TYPE_LINE_EASTING); ge.setValue(easting); this.gridElements.add(ge); } } // West-East lines for (int i = 1; i <= 9; i++) { double northing = this.SWNorthing + gridStep * i; positions.clear(); p1 = computePosition(this.UTMZone, this.hemisphere, SWEasting, northing); p2 = computePosition(this.UTMZone, this.hemisphere, SWEasting + this.size, northing); if (this.isTruncated) { computeTruncatedSegment(p1, p2, this.UTMZoneSector, positions); } else { positions.add(p1); positions.add(p2); } if (positions.size() > 0) { p1 = positions.get(0); p2 = positions.get(1); Object polyline = createLineRenderable(positions, Polyline.GREAT_CIRCLE); Sector lineSector = Sector.boundingSector(p1, p2); GridElement ge = new GridElement(lineSector, polyline, GridElement.TYPE_LINE_NORTHING); ge.setValue(northing); this.gridElements.add(ge); } } }
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 void createRectangularArray() { this.arraySector = Sector.fromDegrees(20, 30, -110, -100); this.arrayWidth = 60; this.arrayHeight = 60; this.arrayValues = ExampleUtil.readCommaDelimitedNumbers( "gov/nasa/worldwindx/examples/data/GridValues01_60x60.csv"); }
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; }
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 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); } }
private boolean needToSplit(DrawContext dc, Sector sector) { Vec4[] corners = sector.computeCornerPoints(dc.getGlobe(), dc.getVerticalExaggeration()); Vec4 centerPoint = sector.computeCenterPoint(dc.getGlobe(), dc.getVerticalExaggeration()); View view = dc.getView(); double d1 = view.getEyePoint().distanceTo3(corners[0]); double d2 = view.getEyePoint().distanceTo3(corners[1]); double d3 = view.getEyePoint().distanceTo3(corners[2]); double d4 = view.getEyePoint().distanceTo3(corners[3]); double d5 = view.getEyePoint().distanceTo3(centerPoint); double minDistance = d1; if (d2 < minDistance) minDistance = d2; if (d3 < minDistance) minDistance = d3; if (d4 < minDistance) minDistance = d4; if (d5 < minDistance) minDistance = d5; double cellSize = (Math.PI * sector.getDeltaLatRadians() * dc.getGlobe().getRadius()) / 20; // TODO return !(Math.log10(cellSize) <= (Math.log10(minDistance) - this.splitScale)); }
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 static VirtualEarthTile[] createTiles( Sector bbox /*int wwLevel, int wwRow, int wwCol*/, VirtualEarthLayer layer) throws WWRuntimeException { if (null == bbox) { String message = Logging.getMessage("nullValue.SectorIsNull"); Logging.logger().severe(message); throw new WWRuntimeException(message); } if (null == layer) { String message = Logging.getMessage("nullValue.LayerIsNull"); Logging.logger().severe(message); throw new WWRuntimeException(message); } int level = getZoomLevelByTrueViewRange(bbox.getDeltaLatDegrees()); Point startPixel = LatLongToPixelXY(bbox.getMaxLatitude().degrees, bbox.getMinLongitude().degrees, level); Point endPixel = LatLongToPixelXY(bbox.getMinLatitude().degrees, bbox.getMaxLongitude().degrees, level); Point startTile = PixelXYToTileXY(startPixel.x, startPixel.y); Point endTile = PixelXYToTileXY(endPixel.x, endPixel.y); ArrayList<VirtualEarthTile> tileList = new ArrayList<VirtualEarthTile>(); for (int y = startTile.y; y <= endTile.y; y++) { for (int x = startTile.x; x <= endTile.x; x++) { try { int ulPixelX = x * VE_MAX_TILE_SIZE; int ulPixelY = y * VE_MAX_TILE_SIZE; LatLon ul = PixelXYToLatLong(ulPixelX, ulPixelY, level); int lrPixelX = ulPixelX + VE_MAX_TILE_SIZE; int lrPixelY = ulPixelY + VE_MAX_TILE_SIZE; LatLon lr = PixelXYToLatLong(lrPixelX, lrPixelY, level); Sector tileSector = Sector.boundingSector(ul, lr); tileList.add(new VirtualEarthTile(x, y, level, layer, tileSector)); } catch (Exception ex) { Logging.logger().log(Level.SEVERE, ex.getMessage(), ex); } } } VirtualEarthTile[] tiles = new VirtualEarthTile[tileList.size()]; return tileList.toArray(tiles); }
@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()); } }
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()); }
public SquareSector( int UTMZone, String hemisphere, Sector UTMZoneSector, double SWEasting, double SWNorthing, double size) { this.UTMZone = UTMZone; this.hemisphere = hemisphere; this.UTMZoneSector = UTMZoneSector; this.SWEasting = SWEasting; this.SWNorthing = SWNorthing; this.size = size; // Compute corners positions this.sw = computePosition(this.UTMZone, this.hemisphere, SWEasting, SWNorthing); this.se = computePosition(this.UTMZone, this.hemisphere, SWEasting + size, SWNorthing); this.nw = computePosition(this.UTMZone, this.hemisphere, SWEasting, SWNorthing + size); this.ne = computePosition(this.UTMZone, this.hemisphere, SWEasting + size, SWNorthing + size); this.squareCenter = computePosition( this.UTMZone, this.hemisphere, SWEasting + size / 2, SWNorthing + size / 2); // Compute approximate bounding sector and center point if (this.sw != null && this.se != null && this.nw != null && this.ne != null) { adjustDateLineCrossingPoints(); this.boundingSector = Sector.boundingSector(Arrays.asList(sw, se, nw, ne)); if (!isInsideGridZone()) this.boundingSector = this.UTMZoneSector.intersection(this.boundingSector); this.centroid = this.boundingSector != null ? this.boundingSector.getCentroid() : this.squareCenter; // this.squareCenter = this.boundingSector.getCentroid(); } // Check whether this square is truncated by the grid zone boundary this.isTruncated = !isInsideGridZone(); }
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; }
public void createRenderables() { this.gridElements = new ArrayList<GridElement>(); ArrayList<Position> positions = new ArrayList<Position>(); Position p1, p2; Object polyline; Sector lineSector; // left segment positions.clear(); if (this.isTruncated) { computeTruncatedSegment(sw, nw, this.UTMZoneSector, positions); } else { positions.add(sw); positions.add(nw); } if (positions.size() > 0) { p1 = positions.get(0); p2 = positions.get(1); polyline = createLineRenderable(positions, Polyline.GREAT_CIRCLE); lineSector = Sector.boundingSector(p1, p2); GridElement ge = new GridElement(lineSector, polyline, GridElement.TYPE_LINE_WEST); ge.setValue(this.SWEasting); this.gridElements.add(ge); } // right segment positions.clear(); if (this.isTruncated) { computeTruncatedSegment(se, ne, this.UTMZoneSector, positions); } else { positions.add(se); positions.add(ne); } if (positions.size() > 0) { p1 = positions.get(0); p2 = positions.get(1); polyline = createLineRenderable(positions, Polyline.GREAT_CIRCLE); lineSector = Sector.boundingSector(p1, p2); GridElement ge = new GridElement(lineSector, polyline, GridElement.TYPE_LINE_EAST); ge.setValue(this.SWEasting + this.size); this.gridElements.add(ge); } // bottom segment positions.clear(); if (this.isTruncated) { computeTruncatedSegment(sw, se, this.UTMZoneSector, positions); } else { positions.add(sw); positions.add(se); } if (positions.size() > 0) { p1 = positions.get(0); p2 = positions.get(1); polyline = createLineRenderable(positions, Polyline.GREAT_CIRCLE); lineSector = Sector.boundingSector(p1, p2); GridElement ge = new GridElement(lineSector, polyline, GridElement.TYPE_LINE_SOUTH); ge.setValue(this.SWNorthing); this.gridElements.add(ge); } // top segment positions.clear(); if (this.isTruncated) { computeTruncatedSegment(nw, ne, this.UTMZoneSector, positions); } else { positions.add(nw); positions.add(ne); } if (positions.size() > 0) { p1 = positions.get(0); p2 = positions.get(1); polyline = createLineRenderable(positions, Polyline.GREAT_CIRCLE); lineSector = Sector.boundingSector(p1, p2); GridElement ge = new GridElement(lineSector, polyline, GridElement.TYPE_LINE_NORTH); ge.setValue(this.SWNorthing + this.size); this.gridElements.add(ge); } // Label if (this.name != null) { // Only add a label to squares above some dimension if (this.boundingSector.getDeltaLon().degrees * Math.cos(this.centroid.getLatitude().radians) > .2 && this.boundingSector.getDeltaLat().degrees > .2) { LatLon labelPos = null; if (this.UTMZone != 0) // Not at poles { labelPos = this.centroid; } else if (this.isPositionInside(new Position(this.squareCenter, 0))) { labelPos = this.squareCenter; } else if (this.squareCenter.getLatitude().degrees <= this.UTMZoneSector.getMaxLatitude().degrees && this.squareCenter.getLatitude().degrees >= this.UTMZoneSector.getMinLatitude().degrees) { labelPos = this.centroid; } if (labelPos != null) { GeographicText text = new UserFacingText(this.name, new Position(labelPos, 0)); text.setPriority(this.size * 10); this.gridElements.add( new GridElement(this.boundingSector, text, GridElement.TYPE_GRIDZONE_LABEL)); } } } }
public Extent getExtent(Globe globe, double ve) { return Sector.computeBoundingCylinder(globe, ve, this.boundingSector); }
/** Create the graticule grid elements */ private void createUTMRenderables() { this.gridElements = new ArrayList<GridElement>(); ArrayList<Position> positions = new ArrayList<Position>(); // Generate meridians and zone labels int lon = -180; int zoneNumber = 1; int maxLat; for (int i = 0; i < 60; i++) { Angle longitude = Angle.fromDegrees(lon); // Meridian positions.clear(); positions.add(new Position(Angle.fromDegrees(-80), longitude, 10e3)); positions.add(new Position(Angle.fromDegrees(-60), longitude, 10e3)); positions.add(new Position(Angle.fromDegrees(-30), longitude, 10e3)); positions.add(new Position(Angle.ZERO, longitude, 10e3)); positions.add(new Position(Angle.fromDegrees(30), longitude, 10e3)); if (lon < 6 || lon > 36) { // 'regular' UTM meridians maxLat = 84; positions.add(new Position(Angle.fromDegrees(60), longitude, 10e3)); positions.add(new Position(Angle.fromDegrees(maxLat), longitude, 10e3)); } else { // Exceptions: shorter meridians around and north-east of Norway if (lon == 6) { maxLat = 56; positions.add(new Position(Angle.fromDegrees(maxLat), longitude, 10e3)); } else { maxLat = 72; positions.add(new Position(Angle.fromDegrees(60), longitude, 10e3)); positions.add(new Position(Angle.fromDegrees(maxLat), longitude, 10e3)); } } Object polyline = createLineRenderable(positions, Polyline.GREAT_CIRCLE); Sector sector = Sector.fromDegrees(-80, maxLat, lon, lon); this.gridElements.add(new GridElement(sector, polyline, GridElement.TYPE_LINE)); // Zone label GeographicText text = new UserFacingText(zoneNumber + "", Position.fromDegrees(0, lon + 3, 0)); sector = Sector.fromDegrees(-90, 90, lon + 3, lon + 3); this.gridElements.add(new GridElement(sector, text, GridElement.TYPE_LONGITUDE_LABEL)); // Increase longitude and zone number lon += 6; zoneNumber++; } // Generate special meridian segments for exceptions around and north-east of Norway for (int i = 0; i < 5; i++) { positions.clear(); lon = specialMeridians[i][0]; positions.add( new Position(Angle.fromDegrees(specialMeridians[i][1]), Angle.fromDegrees(lon), 10e3)); positions.add( new Position(Angle.fromDegrees(specialMeridians[i][2]), Angle.fromDegrees(lon), 10e3)); Object polyline = createLineRenderable(positions, Polyline.GREAT_CIRCLE); Sector sector = Sector.fromDegrees(specialMeridians[i][1], specialMeridians[i][2], lon, lon); this.gridElements.add(new GridElement(sector, polyline, GridElement.TYPE_LINE)); } // Generate parallels - no exceptions int lat = -80; for (int i = 0; i < 21; i++) { Angle latitude = Angle.fromDegrees(lat); for (int j = 0; j < 4; j++) { // Each prallel is divided into four 90 degrees segments positions.clear(); lon = -180 + j * 90; positions.add(new Position(latitude, Angle.fromDegrees(lon), 10e3)); positions.add(new Position(latitude, Angle.fromDegrees(lon + 30), 10e3)); positions.add(new Position(latitude, Angle.fromDegrees(lon + 60), 10e3)); positions.add(new Position(latitude, Angle.fromDegrees(lon + 90), 10e3)); Object polyline = createLineRenderable(positions, Polyline.LINEAR); Sector sector = Sector.fromDegrees(lat, lat, lon, lon + 90); this.gridElements.add(new GridElement(sector, polyline, GridElement.TYPE_LINE)); } // Latitude band label if (i < 20) { GeographicText text = new UserFacingText(latBands.charAt(i) + "", Position.fromDegrees(lat + 4, 0, 0)); Sector sector = Sector.fromDegrees(lat + 4, lat + 4, -180, 180); this.gridElements.add(new GridElement(sector, text, GridElement.TYPE_LATITUDE_LABEL)); } // Increase latitude lat += lat < 72 ? 8 : 12; } }
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 void doDrawOnTo(BufferedImageRaster canvas) { Sector sector = this.getSector(); if (null == sector) { String message = Logging.getMessage("nullValue.SectorIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (!sector.intersects(canvas.getSector())) { return; } java.awt.Graphics2D g2d = null; java.awt.Shape prevClip = null; java.awt.Composite prevComposite = null; java.lang.Object prevInterpolation = null, prevAntialiasing = null; try { int canvasWidth = canvas.getWidth(); int canvasHeight = canvas.getHeight(); // Apply the transform that correctly maps the image onto the canvas. java.awt.geom.AffineTransform transform = this.computeSourceToDestTransform( this.getWidth(), this.getHeight(), this.getSector(), canvasWidth, canvasHeight, canvas.getSector()); AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR); Rectangle2D rect = op.getBounds2D(this.getBufferedImage()); int clipWidth = (int) Math.ceil((rect.getMaxX() >= canvasWidth) ? canvasWidth : rect.getMaxX()); int clipHeight = (int) Math.ceil((rect.getMaxY() >= canvasHeight) ? canvasHeight : rect.getMaxY()); if (clipWidth <= 0 || clipHeight <= 0) { return; } g2d = canvas.getGraphics(); prevClip = g2d.getClip(); prevComposite = g2d.getComposite(); prevInterpolation = g2d.getRenderingHint(RenderingHints.KEY_INTERPOLATION); prevAntialiasing = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING); // Set the alpha composite for appropriate alpha blending. g2d.setComposite(java.awt.AlphaComposite.SrcOver); g2d.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.drawImage(this.getBufferedImage(), transform, null); } // catch (java.awt.image.ImagingOpException ioe) // { // // If we catch a ImagingOpException, then the transformed image has a width or // height of 0. // // This indicates that there is no intersection between the source image and the // canvas, // // or the intersection is smaller than one pixel. // } // catch (java.awt.image.RasterFormatException rfe) // { // // If we catch a RasterFormatException, then the transformed image has a width or // height of 0. // // This indicates that there is no intersection between the source image and the // canvas, // // or the intersection is smaller than one pixel. // } catch (Throwable t) { String reason = WWUtil.extractExceptionReason(t); Logging.logger().log(java.util.logging.Level.SEVERE, reason, t); } finally { // Restore the previous clip, composite, and transform. try { if (null != g2d) { if (null != prevClip) g2d.setClip(prevClip); if (null != prevComposite) g2d.setComposite(prevComposite); if (null != prevInterpolation) g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, prevInterpolation); if (null != prevAntialiasing) g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, prevAntialiasing); } } catch (Throwable t) { Logging.logger().log(java.util.logging.Level.FINEST, WWUtil.extractExceptionReason(t), t); } } }
public static DataRaster wrapAsGeoreferencedRaster(BufferedImage image, AVList params) { if (null == image) { String message = Logging.getMessage("nullValue.ImageIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (null == params) { String msg = Logging.getMessage("nullValue.AVListIsNull"); Logging.logger().finest(msg); throw new IllegalArgumentException(msg); } if (params.hasKey(AVKey.WIDTH)) { int width = (Integer) params.getValue(AVKey.WIDTH); if (width != image.getWidth()) { String msg = Logging.getMessage("generic.InvalidWidth", "" + width + "!=" + image.getWidth()); Logging.logger().finest(msg); throw new IllegalArgumentException(msg); } } if (params.hasKey(AVKey.HEIGHT)) { int height = (Integer) params.getValue(AVKey.HEIGHT); if (height != image.getHeight()) { String msg = Logging.getMessage("generic.InvalidHeight", "" + height + "!=" + image.getHeight()); Logging.logger().finest(msg); throw new IllegalArgumentException(msg); } } if (!params.hasKey(AVKey.SECTOR)) { String msg = Logging.getMessage("generic.MissingRequiredParameter", AVKey.SECTOR); Logging.logger().finest(msg); throw new IllegalArgumentException(msg); } Sector sector = (Sector) params.getValue(AVKey.SECTOR); if (null == sector) { String msg = Logging.getMessage("nullValue.SectorIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } if (!params.hasKey(AVKey.COORDINATE_SYSTEM)) { // assume Geodetic Coordinate System params.setValue(AVKey.COORDINATE_SYSTEM, AVKey.COORDINATE_SYSTEM_GEOGRAPHIC); } String cs = params.getStringValue(AVKey.COORDINATE_SYSTEM); if (!params.hasKey(AVKey.PROJECTION_EPSG_CODE)) { if (AVKey.COORDINATE_SYSTEM_GEOGRAPHIC.equals(cs)) { // assume WGS84 params.setValue(AVKey.PROJECTION_EPSG_CODE, GeoTiff.GCS.WGS_84); } else { String msg = Logging.getMessage("generic.MissingRequiredParameter", AVKey.PROJECTION_EPSG_CODE); Logging.logger().finest(msg); throw new IllegalArgumentException(msg); } } // if PIXEL_WIDTH is specified, we are not overriding it because UTM images // will have different pixel size if (!params.hasKey(AVKey.PIXEL_WIDTH)) { if (AVKey.COORDINATE_SYSTEM_GEOGRAPHIC.equals(cs)) { double pixelWidth = sector.getDeltaLonDegrees() / (double) image.getWidth(); params.setValue(AVKey.PIXEL_WIDTH, pixelWidth); } else { String msg = Logging.getMessage("generic.MissingRequiredParameter", AVKey.PIXEL_WIDTH); Logging.logger().finest(msg); throw new IllegalArgumentException(msg); } } // if PIXEL_HEIGHT is specified, we are not overriding it // because UTM images will have different pixel size if (!params.hasKey(AVKey.PIXEL_HEIGHT)) { if (AVKey.COORDINATE_SYSTEM_GEOGRAPHIC.equals(cs)) { double pixelHeight = sector.getDeltaLatDegrees() / (double) image.getHeight(); params.setValue(AVKey.PIXEL_HEIGHT, pixelHeight); } else { String msg = Logging.getMessage("generic.MissingRequiredParameter", AVKey.PIXEL_HEIGHT); Logging.logger().finest(msg); throw new IllegalArgumentException(msg); } } if (!params.hasKey(AVKey.PIXEL_FORMAT)) { params.setValue(AVKey.PIXEL_FORMAT, AVKey.IMAGE); } else if (!AVKey.IMAGE.equals(params.getStringValue(AVKey.PIXEL_FORMAT))) { String msg = Logging.getMessage( "generic.UnknownValueForKey", params.getStringValue(AVKey.PIXEL_FORMAT), AVKey.PIXEL_FORMAT); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } if (!params.hasKey(AVKey.ORIGIN) && AVKey.COORDINATE_SYSTEM_GEOGRAPHIC.equals(cs)) { // set UpperLeft corner as the origin, if not specified LatLon origin = new LatLon(sector.getMaxLatitude(), sector.getMinLongitude()); params.setValue(AVKey.ORIGIN, origin); } if (!params.hasKey(AVKey.DATE_TIME)) { // add NUL (\0) termination as required by TIFF v6 spec (20 bytes length) String timestamp = String.format("%1$tY:%1$tm:%1$td %tT\0", Calendar.getInstance()); params.setValue(AVKey.DATE_TIME, timestamp); } if (!params.hasKey(AVKey.VERSION)) { params.setValue(AVKey.VERSION, Version.getVersion()); } boolean hasAlpha = (null != image.getColorModel() && image.getColorModel().hasAlpha()); params.setValue(AVKey.RASTER_HAS_ALPHA, hasAlpha); return new BufferedImageRaster(sector, image, params); }
public BufferedImage composeImageForSector( Sector sector, int imageWidth, int imageHeight, int levelNumber, String mimeType, boolean abortOnError, BufferedImage image) { if (sector == null) { String message = Logging.getMessage("nullValue.SectorIsNull"); Logging.logger().severe(message); throw new IllegalStateException(message); } if (levelNumber < 0) { levelNumber = this.levels.getLastLevel().getLevelNumber(); } else if (levelNumber > this.levels.getLastLevel().getLevelNumber()) { Logging.logger() .warning( Logging.getMessage( "generic.LevelRequestedGreaterThanMaxLevel", levelNumber, this.levels.getLastLevel().getLevelNumber())); levelNumber = this.levels.getLastLevel().getLevelNumber(); } MercatorTextureTile[][] tiles = this.getTilesInSector(sector, levelNumber); if (tiles.length == 0 || tiles[0].length == 0) { Logging.logger().severe(Logging.getMessage("layers.TiledImageLayer.NoImagesAvailable")); return null; } if (image == null) image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); for (MercatorTextureTile[] row : tiles) { for (MercatorTextureTile tile : row) { if (tile == null) continue; BufferedImage tileImage; try { tileImage = this.getImage(tile, mimeType); double sh = ((double) imageHeight / (double) tileImage.getHeight()) * (tile.getSector().getDeltaLat().divide(sector.getDeltaLat())); double sw = ((double) imageWidth / (double) tileImage.getWidth()) * (tile.getSector().getDeltaLon().divide(sector.getDeltaLon())); double dh = imageHeight * (-tile.getSector().getMaxLatitude().subtract(sector.getMaxLatitude()).degrees / sector.getDeltaLat().degrees); double dw = imageWidth * (tile.getSector().getMinLongitude().subtract(sector.getMinLongitude()).degrees / sector.getDeltaLon().degrees); AffineTransform txf = g.getTransform(); g.translate(dw, dh); g.scale(sw, sh); g.drawImage(tileImage, 0, 0, null); g.setTransform(txf); } catch (Exception e) { if (abortOnError) throw new RuntimeException(e); String message = Logging.getMessage("generic.ExceptionWhileRequestingImage", tile.getPath()); Logging.logger().log(java.util.logging.Level.WARNING, message, e); } } } return image; }