protected void setPixelPosY(Object value, Placemark placemark) { if (value instanceof Float) { float pixelX; if (placemark.getPixelPos() == null) { pixelX = -1; } else { pixelX = placemark.getPixelPos().x; } placemark.setPixelPos(new PixelPos(pixelX, (Float) value)); } }
protected void setPixelPosX(Object value, Placemark placemark) { if (value instanceof Float) { float pixelY; if (placemark.getPixelPos() == null) { pixelY = -1; } else { pixelY = placemark.getPixelPos().y; } placemark.setPixelPos(new PixelPos((Float) value, pixelY)); } }
private double readEnergy(Placemark pin, Band spectralBand) { final MultiLevelModel multiLevelModel = ImageManager.getMultiLevelModel(spectralBand); final AffineTransform i2mTransform = multiLevelModel.getImageToModelTransform(0); final AffineTransform m2iTransform = multiLevelModel.getModelToImageTransform(level); final Point2D modelPixel = i2mTransform.transform(pin.getPixelPos(), null); final Point2D imagePixel = m2iTransform.transform(modelPixel, null); int pinPixelX = (int) Math.floor(imagePixel.getX()); int pinPixelY = (int) Math.floor(imagePixel.getY()); return ProductUtils.getGeophysicalSampleDouble(spectralBand, pinPixelX, pinPixelY, level); }
private static Placemark[] getValidGcps(ProductNodeGroup<Placemark> gcpGroup) { final List<Placemark> gcpList = new ArrayList<Placemark>(gcpGroup.getNodeCount()); for (int i = 0; i < gcpGroup.getNodeCount(); i++) { final Placemark p = gcpGroup.get(i); final PixelPos pixelPos = p.getPixelPos(); final GeoPos geoPos = p.getGeoPos(); if (pixelPos != null && pixelPos.isValid() && geoPos != null && geoPos.isValid()) { gcpList.add(p); } } return gcpList.toArray(new Placemark[gcpList.size()]); }
@Override protected void computeRect(PlanarImage[] sourceImages, WritableRaster tile, Rectangle destRect) { final BufferedImage image = new BufferedImage(colorModel, RasterFactory.createWritableRaster(tile.getSampleModel(), tile.getDataBuffer(), new Point(0, 0)), false, null); final Graphics2D graphics2D = image.createGraphics(); graphics2D.translate(-tile.getMinX(), -tile.getMinY()); graphics2D.setColor(Color.WHITE); ProductNodeGroup<Placemark> placemarkGroup = getPlacemarkGroup(); Placemark[] placemarks = placemarkGroup.toArray(new Placemark[placemarkGroup.getNodeCount()]); for (Placemark placemark : placemarks) { final PixelPos pixelPos = placemark.getPixelPos(); if (pixelPos != null) { final int x = (int) pixelPos.x - placemarkSize / 2; final int y = (int) pixelPos.y - placemarkSize / 2; graphics2D.fillRect(x, y, placemarkSize, placemarkSize); } } graphics2D.dispose(); final byte[] data = ((DataBufferByte) tile.getDataBuffer()).getData(); for (int i = 0; i < data.length; i++) { data[i] = (data[i] != 0) ? TRUE : FALSE; } }
static ArrayList<Point2D> createPointList(Product product, Random random) { ArrayList<Point2D> pointList = new ArrayList<Point2D>(); if (product.getPinGroup().getNodeCount() > 0) { final PlacemarkGroup pinGroup = product.getPinGroup(); for (int i = 0; i < pinGroup.getNodeCount(); i++) { pointList.add(pinGroup.get(i).getPixelPos()); } } else { for (int i = 0; i < 2; i++) { final int x = (int) (random.nextFloat() * product.getSceneRasterWidth()); final int y = (int) (random.nextFloat() * product.getSceneRasterHeight()); pointList.add(new Point(x, y)); } } return pointList; } }
private static boolean isValid(Placemark p) { final PixelPos pixelPos = p.getPixelPos(); final GeoPos geoPos = p.getGeoPos(); return pixelPos != null && pixelPos.isValid() && geoPos != null && geoPos.isValid(); }
private String setUpRow(Placemark pin, List<Band> bandList) { Band refBand = bandList.get(0); final StringBuilder row = new StringBuilder(); row.append(pin.getLabel()); row.append(getSeparator()); PixelPos pixelPos = pin.getPixelPos(); if (exportImageCoords) { exportImageCoords(row, pixelPos); } if (exportLonLat) { exportLatLon(refBand, row, pixelPos); } row.append(AbstractTimeSeries.rasterToVariableName(refBand.getName())); row.append(getSeparator()); if (exportUnit) { row.append(refBand.getUnit()); row.append(getSeparator()); } for (int i = 0; i < bandList.size(); i++) { Band band = bandList.get(i); row.append(getValue(band, (int) pixelPos.x, (int) pixelPos.y, level)); if (i < bandList.size() - 1) { row.append(getSeparator()); } } return row.toString(); }
public void readValues() { Debug.assertNotNull(bands); for (int i = 0; i < bands.length; i++) { final Band band = bands[i]; if (placemark != null) { // position of placemark is given in image (L0) coordinates // we have to transform them to the current level final MultiLevelModel multiLevelModel = ImageManager.getMultiLevelModel(band); final AffineTransform i2mTransform = multiLevelModel.getImageToModelTransform(0); final AffineTransform m2iTransform = multiLevelModel.getModelToImageTransform(0); final Point2D modelPixel = i2mTransform.transform(placemark.getPixelPos(), null); final Point2D imagePixel = m2iTransform.transform(modelPixel, null); int pixelX = (int) Math.floor(imagePixel.getX()); int pixelY = (int) Math.floor(imagePixel.getY()); energies[i] = getSample(band, pixelX, pixelY, 0); } } IndexValidator validator = new IndexValidator() { @Override public boolean validateIndex(int index) { return energies[index] != bands[index].getGeophysicalNoDataValue(); } }; Range.computeRangeDouble(energies, validator, energyRange, ProgressMonitor.NULL); // no invalidate() call here, SpectrumDiagram does this }
void zoomToActivePin() { Guardian.assertNotNull("product", product); Placemark activePlacemark = getSelectedPlacemark(); Guardian.assertNotNull("activePlacemark", activePlacemark); final ProductSceneView view = getSceneView(); final PixelPos imagePos = activePlacemark.getPixelPos(); // in image coordinates on Level 0, can be null if (view != null && imagePos != null) { final ImageLayer layer = view.getBaseImageLayer(); final AffineTransform imageToModelTransform = layer.getImageToModelTransform(0); final Point2D modelPos = imageToModelTransform.transform(imagePos, null); view.zoom(modelPos.getX(), modelPos.getY(), view.getZoomFactor()); updateUIState(); } }
private void initCoordinates(Placemark[] gcps) { for (final Placemark gcp : gcps) { final PixelPos pixelPos = gcp.getPixelPos(); final GeoPos geoPos = gcp.getGeoPos(); if (pixelPos == null || !pixelPos.isValid() || geoPos == null || !geoPos.isValid()) { throw new IllegalArgumentException("Invalid ground control point."); } } x = new double[gcps.length]; y = new double[gcps.length]; lons = new double[gcps.length]; lats = new double[gcps.length]; for (int i = 0; i < gcps.length; i++) { final PixelPos pixelPos = gcps[i].getPixelPos(); x[i] = pixelPos.getX(); y[i] = pixelPos.getY(); final GeoPos geoPos = gcps[i].getGeoPos(); lons[i] = geoPos.getLon(); lats[i] = geoPos.getLat(); } }
private void snapToSelectedPin() { final Placemark pin = currentView != null ? currentView.getSelectedPin() : null; if (pin != null) { final PixelPos pos = pin.getPixelPos(); final int x = MathUtils.floorInt(pos.x); final int y = MathUtils.floorInt(pos.y); pixelInfoView.updatePixelValues(currentView, x, y, 0, true); } else { pixelInfoView.updatePixelValues(currentView, -1, -1, 0, false); } }
private void handleGeoCodingChange() { for (int i = 0; i < pinGroup.getNodeCount(); i++) { final Placemark pin = pinGroup.get(i); final PlacemarkDescriptor pinDescriptor = pin.getDescriptor(); final PixelPos pixelPos = pin.getPixelPos(); GeoPos geoPos = pin.getGeoPos(); if (pixelPos != null) { geoPos = pinDescriptor.updateGeoPos(getGeoCoding(), pixelPos, geoPos); } pin.setGeoPos(geoPos); } }
private void setGeoPosAttribute(GeoPos geoPos, boolean updatePixelPos) { final Coordinate newCoordinate = toCoordinate(geoPos); final Coordinate oldCoordinate = getGeoPosAttribute(); if (!ObjectUtils.equalObjects(oldCoordinate, newCoordinate)) { if (oldCoordinate == null) { final GeometryFactory geometryFactory = new GeometryFactory(); setAttributeValue(PROPERTY_NAME_GEOPOS, geometryFactory.createPoint(newCoordinate)); } else if (newCoordinate != null) { final Point point = (Point) getAttributeValue(PROPERTY_NAME_GEOPOS); point.getCoordinate().setCoordinate(newCoordinate); point.geometryChanged(); } if (updatePixelPos && getProduct() != null) { final PixelPos pixelPos = getPixelPos(); descriptor.updatePixelPos(getProduct().getGeoCoding(), geoPos, pixelPos); setPixelPosAttribute(pixelPos, false, true); } fireProductNodeChanged(PROPERTY_NAME_GEOPOS); } }
private void testReadStandardResult(List<Placemark> expectedPlacemarks, List<Placemark> actualPlacemarks, PlacemarkDescriptor descriptorInstance) { for (int i = 0; i < actualPlacemarks.size(); i++) { Placemark actualPlacemark = actualPlacemarks.get(i); Placemark expectedPlacemark = expectedPlacemarks.get(i); assertNotSame(expectedPlacemark, actualPlacemark); assertEquals(expectedPlacemark.getName(), actualPlacemark.getName()); assertEquals(expectedPlacemark.getLabel(), actualPlacemark.getLabel()); assertEquals(expectedPlacemark.getPixelPos(), actualPlacemark.getPixelPos()); assertEquals(expectedPlacemark.getGeoPos(), actualPlacemark.getGeoPos()); assertEquals(expectedPlacemark.getDescription(), actualPlacemark.getDescription()); PlacemarkDescriptor descriptor = expectedPlacemark.getDescriptor(); assertEquals(descriptor.getRoleLabel(), descriptorInstance.getRoleLabel()); } }
@Test public void initialState() { final double x = placemark.getPixelPos().getX(); final double y = placemark.getPixelPos().getY(); assertEquals(1.0, x, 0.0); assertEquals(1.0, y, 0.0); final Point point = (Point) placemark.getFeature().getDefaultGeometry(); assertEquals(2.0, point.getX(), 0.0); assertEquals(2.0, point.getY(), 0.0); final double lon = placemark.getGeoPos().getLon(); final double lat = placemark.getGeoPos().getLat(); assertEquals(2.0, lon, 0.0); assertEquals(2.0, lat, 0.0); }
void copyActivePlacemark() { Guardian.assertNotNull("product", product); Placemark activePlacemark = getSelectedPlacemark(); Guardian.assertNotNull("activePlacemark", activePlacemark); Placemark newPlacemark = Placemark.createPointPlacemark(activePlacemark.getDescriptor(), "copy_of_" + activePlacemark.getName(), activePlacemark.getLabel(), activePlacemark.getDescription(), activePlacemark.getPixelPos(), activePlacemark.getGeoPos(), activePlacemark.getProduct().getGeoCoding()); newPlacemark.setStyleCss(activePlacemark.getStyleCss()); if (PlacemarkDialog.showEditPlacemarkDialog(getPaneWindow(), product, newPlacemark, placemarkDescriptor)) { makePlacemarkNameUnique(newPlacemark); updateUIState(); } }
@Test public void movePinByPixelPosition() { placemark.setPixelPos(new PixelPos(2.0f, 1.0f)); final double x = placemark.getPixelPos().getX(); final double y = placemark.getPixelPos().getY(); assertEquals(2.0, x, 0.0); assertEquals(1.0, y, 0.0); // todo: rq/?? - make asserts successful final Point point = (Point) placemark.getFeature().getDefaultGeometry(); assertEquals(4.0, point.getX(), 0.0); assertEquals(2.0, point.getY(), 0.0); // todo: rq/?? - make asserts successful final double lon = placemark.getGeoPos().getLon(); final double lat = placemark.getGeoPos().getLat(); assertEquals(4.0, lon, 0.0); assertEquals(2.0, lat, 0.0); }
@Test public void movePinByGeometry() { placemark.getFeature().setDefaultGeometry(newPoint(4.0, 2.0)); placemark.getProduct().getVectorDataGroup().get("pins").fireFeaturesChanged(placemark.getFeature()); final Point point = (Point) placemark.getFeature().getDefaultGeometry(); assertEquals(4.0, point.getX(), 0.0); assertEquals(2.0, point.getY(), 0.0); // todo: rq/?? - make asserts successful final double x = placemark.getPixelPos().getX(); final double y = placemark.getPixelPos().getY(); assertEquals(2.0, x, 0.0); assertEquals(1.0, y, 0.0); // todo: rq/?? - make asserts successful final double lon = placemark.getGeoPos().getLon(); final double lat = placemark.getGeoPos().getLat(); assertEquals(4.0, lon, 0.0); assertEquals(2.0, lat, 0.0); }
@Test public void testCopyPlacemarkGroups() throws IOException { final PlacemarkDescriptor pinDescriptor = PinDescriptor.getInstance(); final Placemark pin = Placemark.createPointPlacemark(pinDescriptor, "P1", "", "", new PixelPos(1.5f, 1.5f), null, sourceProduct.getGeoCoding()); final Placemark gcp = Placemark.createPointPlacemark(pinDescriptor, "G1", "", "", new PixelPos(2.5f, 2.5f), null, sourceProduct.getGeoCoding()); sourceProduct.getPinGroup().add(pin); sourceProduct.getGcpGroup().add(gcp); parameterMap.put("crs", WGS84_CODE); Product targetProduct = createReprojectedProduct(); assertEquals(1, targetProduct.getPinGroup().getNodeCount()); assertEquals(1, targetProduct.getGcpGroup().getNodeCount()); final Placemark pin2 = targetProduct.getPinGroup().get(0); final Placemark gcp2 = targetProduct.getGcpGroup().get(0); assertEquals("P1", pin2.getName()); assertEquals("G1", gcp2.getName()); assertEquals(pin.getGeoPos(), pin2.getGeoPos()); assertEquals(gcp.getGeoPos(), gcp2.getGeoPos()); assertNotNull(pin2.getPixelPos()); assertNotNull(gcp2.getPixelPos()); } }