@Override protected RenderedImage createSourceImage() { return createVirtualSourceImage(this, getExpression()); }
@Override public void visit(VirtualBand virtualBand) { if (!product.isCompatibleBandArithmeticExpression(virtualBand.getExpression())) { product.removeBand(virtualBand); String pattern = "Virtual band ''{0}'' removed from output product because it is not applicable."; /*I18N*/ messages.add(MessageFormat.format(pattern, virtualBand.getName())); } else { checkRaster(virtualBand, "virtual band"); } }
private static List<RasterDataNode> getReferencedVirtualBands(final RasterDataNode node) { final Product product = node.getProduct(); final List<RasterDataNode> rasterList = new ArrayList<RasterDataNode>(); if (product != null) { for (int i = 0; i < product.getNumBands(); i++) { final Band band = product.getBandAt(i); if (band instanceof VirtualBand) { final VirtualBand virtualBand = (VirtualBand) band; if (isNodeReferencedByExpression(node, virtualBand.getExpression())) { rasterList.add(virtualBand); } } } } return rasterList; }
private void collectReferencedRasters(String nodeName, ArrayList<String> referencedNodeNames) { RasterDataNode rasterDataNode = sourceProduct.getRasterDataNode(nodeName); if (rasterDataNode == null) { throw new OperatorException(String.format("Source product does not contain a raster named '%s'.", nodeName)); } final String validPixelExpression = rasterDataNode.getValidPixelExpression(); collectReferencedRastersInExpression(validPixelExpression, referencedNodeNames); if (rasterDataNode instanceof VirtualBand) { VirtualBand vBand = (VirtualBand) rasterDataNode; collectReferencedRastersInExpression(vBand.getExpression(), referencedNodeNames); } }
private static String getExpression(RasterDataNode raster) { Product product = raster.getProduct(); if (product != null) { if (product.containsBand(raster.getName())) { return raster.getName(); } else { if (raster instanceof VirtualBand) { return ((VirtualBand) raster).getExpression(); } } } return null; }
public static RGBImageProfile getCurrentProfile(final Product product) { RGBImageProfile profile = new RGBImageProfile("Current Profile"); String[] rgbaExpressions = new String[]{"", "", "", ""}; final String[] rBandNames = new String[]{RED_BAND_NAME, PROPERTY_KEY_RED, "r"}; final String[] gBandNames = new String[]{GREEN_BAND_NAME, PROPERTY_KEY_GREEN, "g"}; final String[] bBandNames = new String[]{BLUE_BAND_NAME, PROPERTY_KEY_BLUE, "b"}; final String[] aBandNames = new String[]{ALPHA_BAND_NAME, PROPERTY_KEY_ALPHA, "a"}; final String[][] allBandNames = new String[][]{rBandNames, gBandNames, bBandNames, aBandNames}; for (int i = 0; i < allBandNames.length; i++) { final String[] names = allBandNames[i]; for (final String currentBandName : names) { if (rgbaExpressions[i].equals("")) { final Band band = product.getBand(currentBandName); if (band != null) { if (band instanceof VirtualBand) { rgbaExpressions[i] = ((VirtualBand) band).getExpression(); } else { rgbaExpressions[i] = band.getName(); } } } } } profile.setRgbExpressions(rgbaExpressions); return profile; }
private static String getExpression(RasterDataNode raster) { final Product product = raster.getProduct(); if (product != null) { if (product.containsBand(raster.getName())) { return BandArithmetic.createExternalName(raster.getName()); } else { if (raster instanceof VirtualBand) { return ((VirtualBand) raster).getExpression(); } } } return null; }
private BandDescriptor[] createBandDescriptors() { final Product product = getSourceProduct(); final Band[] bands = product.getBands(); ArrayList<BandDescriptor> bandList = new ArrayList<BandDescriptor>(bands.length); for (Band band : bands) { if (band.getClass() == Band.class) { bandList.add(new BandDescriptor(band.getName(), ProductData.getTypeString(band.getDataType()), band.getScalingOffset(), band.getScalingFactor(), null, band.getDescription() )); } else if (band.getClass() == VirtualBand.class) { bandList.add(new BandDescriptor(band.getName(), ProductData.getTypeString(band.getDataType()), band.getScalingOffset(), band.getScalingFactor(), ((VirtualBand) band).getExpression(), band.getDescription() )); } } return bandList.toArray(new BandDescriptor[bandList.size()]); }
expressions.add(virtualBand.getExpression());
@Test public void testStoreRgbaExpressionsOverwrite() { final Product p1 = createTestProduct(); RGBImageProfile.storeRgbaExpressions(p1, new String[]{"U", "V", "W", "X"}); assertNotNull(p1.getBand(RGBImageProfile.RED_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.GREEN_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.BLUE_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.ALPHA_BAND_NAME)); RGBImageProfile.storeRgbaExpressions(p1, new String[]{"0.3", "2.0", "6.7", ""}); assertNotNull(p1.getBand(RGBImageProfile.RED_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.GREEN_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.BLUE_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.ALPHA_BAND_NAME)); // since exist before assertEquals("0.3", ((VirtualBand) p1.getBand(RGBImageProfile.RED_BAND_NAME)).getExpression()); assertEquals("2.0", ((VirtualBand) p1.getBand(RGBImageProfile.GREEN_BAND_NAME)).getExpression()); assertEquals("6.7", ((VirtualBand) p1.getBand(RGBImageProfile.BLUE_BAND_NAME)).getExpression()); assertEquals("", ((VirtualBand) p1.getBand(RGBImageProfile.ALPHA_BAND_NAME)).getExpression()); }
public void testVirtualBandExpressionsAreUpdateIfForeignNodeNameChanged() { final Product product1 = new Product("P1", "t", 1, 1); final VirtualBand p1v1 = new VirtualBand("P1V1", ProductData.TYPE_FLOAT32, 1, 1, "42"); product1.addBand(p1v1); final Product product2 = new Product("P2", "t", 1, 1); final VirtualBand p2v1 = new VirtualBand("P2V1", ProductData.TYPE_FLOAT32, 1, 1, "$1.P1V1"); product2.addBand(p2v1); final Product product3 = new Product("P3", "t", 1, 1); final VirtualBand p3v1 = new VirtualBand("P3V1", ProductData.TYPE_FLOAT32, 1, 1, "$1.P1V1 + $2.P2V1"); product3.addBand(p3v1); _productManager.addProduct(product1); _productManager.addProduct(product2); _productManager.addProduct(product3); p1v1.setName("TheAnswer"); assertEquals("$1.TheAnswer", p2v1.getExpression()); assertEquals("$1.TheAnswer + $2.P2V1", p3v1.getExpression()); }
product.setModified(false); assertFalse(virtualBand.isModified()); assertEquals(initialExpression, virtualBand.getExpression()); assertEquals(renamedExpression, virtualBand.getExpression()); assertTrue(virtualBand.isModified());
public void testExprAndTerm() { final Product product = new Product("p", "t", 10, 10); final VirtualBand virtualBand = new VirtualBand("vb", ProductData.TYPE_FLOAT32, 10, 10, "1.0"); product.addBand(virtualBand); assertEquals("1.0", virtualBand.getExpression()); try { virtualBand.readRasterDataFully(ProgressMonitor.NULL); } catch (IOException e) { fail("IOException not expected"); } for (int y = 0; y < 10; y++) { for (int x = 0; x < 10; x++) { assertEquals(1.0f, virtualBand.getPixelFloat(x, y), 1e-6f); } } }
@Test public void testExpressionIsChangedIfANodeNameIsChanged() { final Product product = new Product("p", "t", 10, 10); final VirtualBand virtualBand = new VirtualBand("vb", ProductData.TYPE_FLOAT32, 10, 10, "band1 + band2 - band3"); final File fileLocation = new File("dummy.dim"); product.setFileLocation(fileLocation); product.addBand(virtualBand); product.addBand("band1", ProductData.TYPE_FLOAT32); product.addBand("band2", ProductData.TYPE_FLOAT32); product.addBand("band3", ProductData.TYPE_FLOAT32); product.getBand("band1").setName("b1"); assertEquals("Name 'band1' is not changed", "b1 + band2 - band3", virtualBand.getExpression()); assertSame(fileLocation, product.getFileLocation()); }
private void initVirtualBandExpressionParam() { final ParamProperties properties = new ParamProperties(String.class); properties.setNullValueAllowed(true); properties.setLabel("Virtual band expression"); /*I18N*/ properties.setNumRows(2); properties.setNumCols(42); properties.setDescription("The expression used to compute the pixel values of this band."); /*I18N*/ properties.setEditorClass(GeneralExpressionEditor.class); // todo setting namespace as property to the ExpressionEditor for validating the expression properties.setPropertyValue(GeneralExpressionEditor.PROPERTY_KEY_SELECTED_PRODUCT, virtualBand.getProduct()); properties.setPropertyValue(GeneralExpressionEditor.PROPERTY_KEY_INPUT_PRODUCTS, getCompatibleProducts(virtualBand)); properties.setPropertyValue(GeneralExpressionEditor.PROPERTY_KEY_PREFERENCES, VisatApp.getApp().getPreferences()); paramVBExpression = new Parameter("virtualBandExpr", virtualBand.getExpression(), properties); paramName.addParamChangeListener(new ParamChangeListener() { @Override public void parameterValueChanged(final ParamChangeEvent event) { final String expresion = paramVBExpression.getValueAsText(); final String newExpression = StringUtils.replaceWord(expresion, (String) event.getOldValue(), paramName.getValueAsText()); paramVBExpression.setValueAsText(newExpression, null); } }); }
@Test public void testStoreRgbaExpressionsWithoutGreen() { final Product p1 = createTestProduct(); RGBImageProfile.storeRgbaExpressions(p1, new String[]{"U", "", "W", ""}); assertNotNull(p1.getBand(RGBImageProfile.RED_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.GREEN_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.BLUE_BAND_NAME)); assertNull(p1.getBand(RGBImageProfile.ALPHA_BAND_NAME)); assertEquals("0", ((VirtualBand) p1.getBand(RGBImageProfile.GREEN_BAND_NAME)).getExpression()); }
getSceneRasterWidth(), getSceneRasterHeight(), virtualSource.getExpression()); } else { destBand = new Band(bandName,
targetProduct.getSceneRasterWidth(), targetProduct.getSceneRasterHeight(), ((VirtualBand) sourceBand).getExpression()); } else if (sourceBand.isScalingApplied()) { targetBand = new Band(sourceBand.getName(),
if (selectedProductNode instanceof VirtualBand) { VirtualBand virtualBand = (VirtualBand) selectedProductNode; String expression = virtualBand.getExpression(); realBand = new Band(bandName, ProductData.TYPE_FLOAT32, width, height); realBand.setDescription(createDescription(virtualBand.getDescription(), expression));
final VirtualBand vb = (VirtualBand) band; printLine(indent + 2, DimapProductConstants.TAG_VIRTUAL_BAND, true); printLine(indent + 2, DimapProductConstants.TAG_VIRTUAL_BAND_EXPRESSION, vb.getExpression());