private void refreshGroup() { final ProductNodeGroup<Mask> productMaskGroup = product.getMaskGroup(); if (group != productMaskGroup) { final Product.AutoGrouping autoGrouping = product.getAutoGrouping(); if (autoGrouping != null) { final int groupIndex = autoGrouping.indexOf(group.getDisplayName()); group.removeAll(); for (int i = 0; i < productMaskGroup.getNodeCount(); i++) { final Mask mask = productMaskGroup.get(i); if (autoGrouping.indexOf(mask.getName()) == groupIndex) { group.add(mask); } } } } }
private String getNewMaskName(ProductNodeGroup<Mask> maskGroup) { String possibleName = DEFAULT_MASK_NAME_PREFIX + maskGroup.getNodeCount(); for (int i = 0; i <= maskGroup.getNodeCount(); i++) { possibleName = DEFAULT_MASK_NAME_PREFIX + (maskGroup.getNodeCount() + i + 1); if (!maskGroup.contains(possibleName)) { break; } } return possibleName; }
protected String[] getGeometries() { final ArrayList<String> geometryNames = new ArrayList<>(5); if (sourceProducts != null) { for (Product prod : sourceProducts) { if (sourceProducts.length > 1) { for (String name : prod.getMaskGroup().getNodeNames()) { geometryNames.add(name + "::" + prod.getName()); } } else { geometryNames.addAll(Arrays.asList(prod.getMaskGroup().getNodeNames())); } } } return geometryNames.toArray(new String[geometryNames.size()]); }
@Override boolean isDirectChild(ProductNode productNode) { int nodeCount = group.getNodeCount(); for (int i = 0; i < nodeCount; i++) { if (group.get(i) == productNode) { return true; } } return false; }
private synchronized void addPlacemark(final Placemark pin) { targetGCPGroup.add(pin); }
/** * Copy GCPs of the first target band to current target band. * * @param firstTargetBand First target band. * @param targetBand Current target band. */ private static void copyFirstTargetBandGCPs(final Band firstTargetBand, final Band targetBand) { final ProductNodeGroup<Placemark> firstTargetBandGcpGroup = GCPManager.instance().getGcpGroup(firstTargetBand); final ProductNodeGroup<Placemark> currentTargetBandGCPGroup = GCPManager.instance().getGcpGroup(targetBand); final int numberOfGCPs = firstTargetBandGcpGroup.getNodeCount(); for (int i = 0; i < numberOfGCPs; ++i) { currentTargetBandGCPGroup.add(firstTargetBandGcpGroup.get(i)); } }
@Override public void areaSelected(PlotAreaSelectionTool.AreaType areaType, Shape shape) { Product product = pagePanel.getProduct(); final RasterDataNode raster = pagePanel.getRaster(); if (product == null || raster == null) { return; } String expression = createMaskExpression(areaType, shape); Mask mask = product.getMaskGroup().get(maskName); if (mask != null) { if (!mask.getRasterSize().equals(raster.getRasterSize())) { // if sizes are different we need to remove the mask first and add it as new one product.getMaskGroup().remove(mask); mask = addMask(product, raster, expression); } else { mask.getImageConfig().setValue("expression", expression); } } else { mask = addMask(product, raster, expression); } ProductNodeGroup<Mask> overlayMaskGroup = raster.getOverlayMaskGroup(); if (!overlayMaskGroup.contains(mask)) { overlayMaskGroup.add(mask); } }
private void copyMasks(Product sourceProduct, Product targetProduct, String...bandNames) { if (isSentinelProduct(sourceProduct)) { final ProductNodeGroup<Mask> sourceMaskGroup = sourceProduct.getMaskGroup(); int nodeCount = sourceMaskGroup.getNodeCount(); for (int i = 0; i < nodeCount; i++) { final Mask mask = sourceMaskGroup.get(i); String maskName = mask.getName(); if (!targetProduct.getMaskGroup().contains(maskName) && StringHelper.endsWithIgnoreCase(maskName, bandNames)) { if (mask.getImageType().transferMask(mask, targetProduct) == null) { Mask targetMask = new Mask(maskName, mask.getRasterWidth(), mask.getRasterHeight(), mask.getImageType()); ProductUtils.copyRasterDataNodeProperties(mask, targetMask); targetMask.setSourceImage(mask.getSourceImage()); targetProduct.getMaskGroup().add(targetMask); } } } } else { final ProductNodeGroup<Mask> sourceMaskGroup = sourceProduct.getMaskGroup(); for (int i = 0; i < sourceMaskGroup.getNodeCount(); i++) { final Mask mask = sourceMaskGroup.get(i); if (!targetProduct.getMaskGroup().contains(mask.getName())) { mask.getImageType().transferMask(mask, targetProduct); } } } }
private ProductNodeGroup<Mask> getMaskGroup() { if (product == null) { return null; } else if (visibleBand == null) { return product.getMaskGroup(); } else { final ProductNodeGroup<Mask> visibleMasks = new ProductNodeGroup<Mask>("Masks for " + visibleBand.getName()); final ProductNodeGroup<Mask> maskGroup = product.getMaskGroup(); for (int i = 0; i < maskGroup.getNodeCount(); i++) { final Mask mask = maskGroup.get(i); // todo - [multisize_products] fix: ask ImageGeometry whether mask and band have the same scenerastertransform if (mask.getRasterWidth() == visibleBand.getRasterWidth() && mask.getRasterHeight() == visibleBand.getRasterHeight()) { visibleMasks.add(mask); } } return visibleMasks; } }
private static boolean productContainsMasks(Product sourceProduct) { for(int k = 0; k < ForestCoverChangeConstants.SENTINEL_MASK_NAMES.length; k++) { Mask sourceMask = sourceProduct.getMaskGroup().get(ForestCoverChangeConstants.SENTINEL_MASK_NAMES[k]); if(sourceMask == null) { return false; } } return true; }
@Override public void undo() throws CannotUndoException { super.undo(); if (index < productNodeGroup.getNodeCount()) { productNodeGroup.add(index, productNode); } else { productNodeGroup.add(productNode); } }
private void addMasks(Product target, ImageMetadata metadata) { ProductNodeGroup<Mask> maskGroup = target.getMaskGroup(); if (!maskGroup.contains(Spot6Constants.NODATA)) { int noDataValue = metadata.getNoDataValue(); maskGroup.add(Mask.BandMathsType.create(Spot6Constants.NODATA, Spot6Constants.NODATA, target.getSceneRasterWidth(), target.getSceneRasterHeight(), String.valueOf(noDataValue), Color.BLACK, 0.5)); } if (!maskGroup.contains(Spot6Constants.SATURATED)) { int saturatedValue = metadata.getSaturatedValue(); maskGroup.add(Mask.BandMathsType.create(Spot6Constants.SATURATED, Spot6Constants.SATURATED, target.getSceneRasterWidth(), target.getSceneRasterHeight(), String.valueOf(saturatedValue), Color.ORANGE, 0.5)); } }
private void ensureMaskVisible(ProductSceneView view) { Product product = view.getProduct(); ProductNodeGroup<Mask> overlayMaskGroup = view.getRaster().getOverlayMaskGroup(); Mask mask = overlayMaskGroup.getByDisplayName(MagicWandModel.MAGIC_WAND_MASK_NAME); if (mask == null) { mask = product.getMaskGroup().get(MagicWandModel.MAGIC_WAND_MASK_NAME); if (mask != null) { overlayMaskGroup.add(mask); } } }
Placemark[] getDisplayedPins() { if (isShowingSpectraForSelectedPins() && currentView != null) { return currentView.getSelectedPins(); } else if (isShowingSpectraForAllPins() && getCurrentProduct() != null) { ProductNodeGroup<Placemark> pinGroup = getCurrentProduct().getPinGroup(); return pinGroup.toArray(new Placemark[pinGroup.getNodeCount()]); } else { return new Placemark[0]; } }
for (String flagCodingName : srcProduct.getFlagCodingGroup().getNodeNames()) { FlagCoding srcFC = srcProduct.getFlagCodingGroup().get(flagCodingName); String[] flagNames = srcFC.getFlagNames(); FlagCoding contextFC = new FlagCoding(flagCodingName); contextFC.addFlag(flagName, srcFC.getFlagMask(flagName), srcFC.getFlag(flagName).getDescription()); contextProduct.getFlagCodingGroup().add(contextFC); contextBand.setSampleCoding(contextProduct.getFlagCodingGroup().get(srcBand.getFlagCoding().getName())); contextProduct.addTiePointGrid(new TiePointGrid(grid.getName(), 10, 10, 0, 0, 1, 1, new float[100])); for (String vectorDataName : srcProduct.getVectorDataGroup().getNodeNames()) { VectorDataNode vectorData = srcProduct.getVectorDataGroup().get(vectorDataName); contextProduct.getVectorDataGroup().add(new VectorDataNode(vectorDataName, vectorData.getFeatureType())); for (String maskName : srcProduct.getMaskGroup().getNodeNames()) { Mask mask = srcProduct.getMaskGroup().get(maskName); contextProduct.addMask(maskName, mask.getImageType());
private static void addGCPGrid(final int width, final int height, final int numPins, final ProductNodeGroup<Placemark> group, final GeoCoding targetGeoCoding) { final double ratio = width / (double) height; final double n = Math.sqrt(numPins / ratio); final double m = ratio * n; final double spacingX = width / m; final double spacingY = height / n; final GcpDescriptor gcpDescriptor = GcpDescriptor.getInstance(); group.removeAll(); int pinNumber = group.getNodeCount() + 1; for (double y = spacingY / 2f; y < height; y += spacingY) { for (double x = spacingX / 2f; x < width; x += spacingX) { final String name = PlacemarkNameFactory.createName(gcpDescriptor, pinNumber); final String label = PlacemarkNameFactory.createLabel(gcpDescriptor, pinNumber, true); final Placemark newPin = Placemark.createPointPlacemark(gcpDescriptor, name, label, "", new PixelPos((int) x, (int) y), null, targetGeoCoding); group.add(newPin); ++pinNumber; } } }
private boolean makePlacemarkNameUnique0(Placemark placemark, Product targetProduct) { ProductNodeGroup<Placemark> placemarkGroup = getPlacemarkGroup(targetProduct); if (placemarkGroup.get(placemark.getName()) == placemark) { return false; } String name0 = placemark.getName(); String name = name0; String label0 = placemark.getLabel(); String label = label0; int id = 1; while (placemarkGroup.contains(name)) { if (placemarkGroup.get(name).getLabel().equals(label)) { label = label0 + "_" + id; } name = name0 + "_" + id; id++; } if (!name0.equals(name)) { placemark.setName(name); if (!label0.equals(label)) { placemark.setLabel(label); } return true; } return false; }
@Test public void testUpdatePointDataSource() throws Exception { final BindingContext bindingContext = new BindingContext(); bindingContext.getPropertySet().addProperties(Property.create("pointDataSource", VectorDataNode.class)); bindingContext.getPropertySet().addProperties(Property.create("dataField", AttributeDescriptor.class)); final CorrelativeFieldSelector correlativeFieldSelector = new CorrelativeFieldSelector(bindingContext); final Product product = new Product("name", "type", 10, 10); product.getVectorDataGroup().add(new VectorDataNode("a", createFeatureType(Geometry.class))); product.getVectorDataGroup().add(new VectorDataNode("b", createFeatureType(Point.class))); assertEquals(0, correlativeFieldSelector.pointDataSourceList.getItemCount()); assertEquals(0, correlativeFieldSelector.dataFieldList.getItemCount()); correlativeFieldSelector.updatePointDataSource(product); assertEquals(3, correlativeFieldSelector.pointDataSourceList.getItemCount()); assertEquals(0, correlativeFieldSelector.dataFieldList.getItemCount()); correlativeFieldSelector.pointDataSourceProperty.setValue(product.getVectorDataGroup().get("b")); assertEquals(3, correlativeFieldSelector.dataFieldList.getItemCount()); }
@Override public int getRowCount() { ProductNodeGroup<Mask> maskGroup = getMaskGroup(); return maskGroup != null ? maskGroup.getNodeCount() : 0; }