/** * Creates and returns a copy of this object. * * @return a copy of this object */ public BitmaskDef createCopy() { return new BitmaskDef(getName(), getDescription(), getExpr(), getColor(), getTransparency()); }
/** * Sets the transparency value. The valid value range is <code>0.0F</code> to <code>1.0F</code>. * * @param transparency the transparency value * @throws IllegalArgumentException if the given transparency value is out of range. */ public void setTransparency(float transparency) { if (transparency < 0.0F || transparency > 1.0F) { throw new IllegalArgumentException("transparency must be >= 0 and <= 1"); } if (_transparency != transparency) { _transparency = transparency; fireProductNodeChanged(PROPERTY_NAME_TRANSPARENCY); setModified(true); } }
@Override public void visit(BitmaskDef bitmaskDef) { bitmaskDef.updateExpression(oldExternName, newExternName); }
/** * Returns whether or not this product node equals another object. */ @Override public boolean equals(Object object) { if (!super.equals(object)) { return false; } final BitmaskDef def = (BitmaskDef) object; return ObjectUtils.equalObjects(getExpr(), def.getExpr()) && ObjectUtils.equalObjects(getColor(), def.getColor()) && getTransparency() == def.getTransparency(); }
public void testFail() { final BitmaskDef bitmaskDef = new BitmaskDef("name", "desc", "abc def ghi", Color.red, 0.5f); bitmaskDef.setModified(false); assertFalse(bitmaskDef.isModified()); assertEquals("abc def ghi", bitmaskDef.getExpr()); bitmaskDef.updateExpression("def", "BBBBBB"); assertEquals("abc BBBBBB ghi", bitmaskDef.getExpr()); assertTrue(bitmaskDef.isModified()); } }
/** * Adds the given bitmask definition to this product. * * @param bitmaskDef the bitmask definition to added, ignored if <code>null</code> * * @deprecated since BEAM 4.7, use {@link #getMaskGroup()} instead */ @Deprecated public void addBitmaskDef(final BitmaskDef bitmaskDef) { if (StringUtils.isNullOrEmpty(bitmaskDef.getDescription())) { final String defaultDescription = getSuitableBitmaskDefDescription(bitmaskDef.getExpr()); bitmaskDef.setDescription(defaultDescription); } bitmaskDefGroup.add(bitmaskDef); maskGroup.add(bitmaskDef.createMask(sceneRasterWidth, sceneRasterHeight)); }
@Override public void visit(BitmaskDef bitmaskDef) { if (!product.isCompatibleBandArithmeticExpression(bitmaskDef.getExpr())) { String pattern = "Bitmask definition ''{0}'' removed from output product because it is not applicable."; /*I18N*/ messages.add(MessageFormat.format(pattern, bitmaskDef.getName())); } }
public static BitmaskDef createBitmaskDef(Element element) { //@todo replace BitmaskDef constructor by multiple param constuctor final String name = element.getAttributeValue(DimapProductConstants.ATTRIB_NAME); String description = null; Element descElem = element.getChild(DimapProductConstants.TAG_BITMASK_DESCRIPTION); if (descElem != null) { description = descElem.getAttributeValue(DimapProductConstants.ATTRIB_VALUE).trim(); } final String expression = element.getChild(DimapProductConstants.TAG_BITMASK_EXPRESSION).getAttributeValue( DimapProductConstants.ATTRIB_VALUE).trim(); final Color color = DimapProductHelpers.createColor(element.getChild(DimapProductConstants.TAG_BITMASK_COLOR)); final String value = element.getChild(DimapProductConstants.TAG_BITMASK_TRANSPARENCY).getAttributeValue( DimapProductConstants.ATTRIB_VALUE); float transparency = 0.5F; try { transparency = Float.parseFloat(value); } catch (NumberFormatException e) { Debug.trace(e); } return new BitmaskDef(name, description, expression, color, transparency); }
public void testBitmaskDefExpressionsAreUpdateIfForeignNodeNameChanged() { 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 BitmaskDef p2bd = new BitmaskDef("P2BD", "P2-Bitmask", "$1.P1V1 == 42.0", Color.RED, 0.5f); product2.addBitmaskDef(p2bd); _productManager.addProduct(product1); _productManager.addProduct(product2); p1v1.setName("TheAnswer"); assertEquals("$1.TheAnswer == 42.0", p2bd.getExpr()); }
@Override public void visit(BitmaskDef bitmaskDef) { visitedList.add(bitmaskDef.getName()); }
/** * Gets the alpha value of the bitmask, which is <code>1 - getTransparency()</code>. * * @return the alpha value */ public float getAlpha() { return 1.0F - getTransparency(); }
/** * Replaces in the expression that this class contains * all occurences of the oldExternalName with the given newExternalName. * * @param oldExternalName * @param newExternalName */ @Override public void updateExpression(final String oldExternalName, final String newExternalName) { if (_expr == null) { return; } final String expression = StringUtils.replaceWord(_expr, oldExternalName, newExternalName); if (!_expr.equals(expression)) { _expr = expression; setModified(true); } super.updateExpression(oldExternalName, newExternalName); }
private void addBitmaskDefinitions(Product product) { final Element bitmaskDefs = getRootElement().getChild(DimapProductConstants.TAG_BITMASK_DEFINITIONS); List bitmaskDefList; if (bitmaskDefs != null) { bitmaskDefList = bitmaskDefs.getChildren(DimapProductConstants.TAG_BITMASK_DEFINITION); } else { bitmaskDefList = getRootElement().getChildren(DimapProductConstants.TAG_BITMASK_DEFINITION); } for (Object child : bitmaskDefList) { final Element bitmaskDefElem = (Element) child; final BitmaskDef bitmaskDef = BitmaskDef.createBitmaskDef(bitmaskDefElem); if (bitmaskDef != null) { product.addBitmaskDef(bitmaskDef); } } }
private void addBitmaskDefsToProduct() { BitmaskDef bitmaskDef1 = new BitmaskDef("bitmaskDef1", "description1", "!l1_flags.INVALID", Color.BLUE, 0.75f); product.addBitmaskDef(bitmaskDef1); BitmaskDef bitmaskDef2 = new BitmaskDef("bitmaskDef2", "description2", "l1_flags.LAND", Color.GREEN, 0.5f); product.addBitmaskDef(bitmaskDef2); }
@Override protected void convertProductNodeToDom(BitmaskDef bitmaskDef, DomElement parentElement) { final DomElement bitmaskName = parentElement.createChild("bitmaskName"); bitmaskName.setValue(bitmaskDef.getName()); } }
public Mask createMask(int width, int height) { return Mask.BandMathsType.create(getName(), getDescription(), width, height, getExpr(), getColor(), getTransparency()); } }
private void addBitmaskDefs(Product product) { String name = "name1"; String desc = "bitmask.description1"; String expr = "bitmask.expression1"; Color color = Color.black; float trans = 1.0F; product.addBitmaskDef(new BitmaskDef(name, desc, expr, color, trans)); name = "name2"; desc = "bitmask.description2"; expr = "bitmask.expression2"; color = Color.blue; trans = 0.75F; product.addBitmaskDef(new BitmaskDef(name, desc, expr, color, trans)); name = "name3"; desc = "bitmask.description3"; expr = "bitmask.expression3"; color = Color.green; trans = 0.2341F; product.addBitmaskDef(new BitmaskDef(name, desc, expr, color, trans)); }
/** * Sets the boolean flag expression code of this <code>BitmaskDef</code> instance. Also sets the <code>term</code> * property if the given string representation of the expression can be compiled. * * @param expr the string representation of the expression * @throws IllegalArgumentException if the expression is invalid (and not parsable) */ public void setExpr(String expr) { if (!ObjectUtils.equalObjects(expr, _expr)) { _expr = (expr != null) ? expr : ""; fireProductNodeChanged(PROPERTY_NAME_EXPR); setModified(true); } }
@Override public void visit(BitmaskDef bitmaskDef) { bitmaskDef.updateExpression(oldExternName, newExternName); }
public void writeXML(XmlWriter writer, int indent) { Guardian.assertNotNull("writer", writer); Guardian.assertGreaterThan("indent", indent, -1); String[][] attributes = new String[1][]; attributes[0] = new String[]{DimapProductConstants.ATTRIB_NAME, getName()}; String[] bdTags = XmlWriter.createTags(indent, DimapProductConstants.TAG_BITMASK_DEFINITION, attributes); writer.println(bdTags[0]); String description = getDescription(); if (description == null) { description = ""; } attributes[0] = new String[]{DimapProductConstants.ATTRIB_VALUE, description}; writer.printLine(indent + 1, DimapProductConstants.TAG_BITMASK_DESCRIPTION, attributes, null); String expr = getExpr(); if (expr == null) { expr = ""; } attributes[0] = new String[]{DimapProductConstants.ATTRIB_VALUE, expr}; writer.printLine(indent + 1, DimapProductConstants.TAG_BITMASK_EXPRESSION, attributes, null); DimapProductHelpers.printColorTag(indent + 1, getColor(), writer); attributes[0] = new String[]{DimapProductConstants.ATTRIB_VALUE, String.valueOf(getTransparency())}; writer.printLine(indent + 1, DimapProductConstants.TAG_BITMASK_TRANSPARENCY, attributes, null); writer.println(bdTags[1]); }