Search in sources :

Example 1 with InterpolationPoint

use of org.geotoolkit.style.function.InterpolationPoint in project geotoolkit by Geomatys.

the class StyleCacheTest method GraphicCacheTest.

@Test
public void GraphicCacheTest() throws Exception {
    // Test a complex graphic
    final Expression Lookup = FF.property("POP_CNTRY");
    final List<InterpolationPoint> values = new ArrayList<InterpolationPoint>();
    // test color interpolation ---------------------------------------------
    values.clear();
    values.add(new DefaultInterpolationPoint(0d, FF.literal(3d)));
    values.add(new DefaultInterpolationPoint(500000000d, FF.literal(50d)));
    Interpolate interpolate = new DefaultInterpolate(Lookup, values, Method.COLOR, Mode.CUBIC, null);
    List<GraphicalSymbol> symbols = new ArrayList<GraphicalSymbol>();
    symbols.add(SF.mark(StyleConstants.MARK_CIRCLE, SF.fill(Color.RED), SF.stroke()));
    Graphic graphic = SF.graphic(symbols, StyleConstants.DEFAULT_GRAPHIC_OPACITY, interpolate, StyleConstants.DEFAULT_GRAPHIC_ROTATION, StyleConstants.DEFAULT_ANCHOR_POINT, StyleConstants.DEFAULT_DISPLACEMENT);
    CachedGraphic cached = CachedGraphic.cache(graphic);
    assertFalse(cached.isStatic());
    assertEquals(VisibilityState.DYNAMIC, cached.isStaticVisible());
}
Also used : DefaultInterpolationPoint(org.geotoolkit.style.function.DefaultInterpolationPoint) InterpolationPoint(org.geotoolkit.style.function.InterpolationPoint) DefaultInterpolate(org.geotoolkit.style.function.DefaultInterpolate) Interpolate(org.geotoolkit.style.function.Interpolate) CachedGraphic(org.geotoolkit.display2d.style.CachedGraphic) Expression(org.opengis.filter.Expression) Graphic(org.opengis.style.Graphic) CachedGraphic(org.geotoolkit.display2d.style.CachedGraphic) ExternalGraphic(org.opengis.style.ExternalGraphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) ArrayList(java.util.ArrayList) DefaultInterpolate(org.geotoolkit.style.function.DefaultInterpolate) DefaultInterpolationPoint(org.geotoolkit.style.function.DefaultInterpolationPoint) Test(org.junit.Test)

Example 2 with InterpolationPoint

use of org.geotoolkit.style.function.InterpolationPoint in project geotoolkit by Geomatys.

the class Styles method colorInterpolationRaster.

public static MutableStyle colorInterpolationRaster() {
    final List<InterpolationPoint> values = new ArrayList<>();
    values.add(SF.interpolationPoint(1003, SF.literal(new Color(46, 154, 88))));
    values.add(SF.interpolationPoint(1800, SF.literal(new Color(251, 255, 128))));
    values.add(SF.interpolationPoint(2800, SF.literal(new Color(224, 108, 31))));
    values.add(SF.interpolationPoint(3500, SF.literal(new Color(200, 55, 55))));
    values.add(SF.interpolationPoint(4397, SF.literal(new Color(215, 244, 244))));
    final Expression lookup = DEFAULT_CATEGORIZE_LOOKUP;
    final Literal fallback = DEFAULT_FALLBACK;
    final Expression function = SF.interpolateFunction(lookup, values, Method.COLOR, Mode.LINEAR, fallback);
    final ChannelSelection selection = null;
    final Expression opacity = LITERAL_ONE_FLOAT;
    final OverlapBehavior overlap = OverlapBehavior.LATEST_ON_TOP;
    final ColorMap colorMap = SF.colorMap(function);
    final ContrastEnhancement enchance = SF.contrastEnhancement(LITERAL_ONE_FLOAT, ContrastMethod.NONE);
    final ShadedRelief relief = SF.shadedRelief(LITERAL_ONE_FLOAT);
    final Symbolizer outline = null;
    final Unit uom = Units.POINT;
    final String geom = DEFAULT_GEOM;
    final String name = "raster symbol name";
    final Description desc = DEFAULT_DESCRIPTION;
    final RasterSymbolizer symbol = SF.rasterSymbolizer(name, geom, desc, uom, opacity, selection, overlap, colorMap, enchance, relief, outline);
    return SF.style(symbol);
}
Also used : InterpolationPoint(org.geotoolkit.style.function.InterpolationPoint) Description(org.opengis.style.Description) ColorMap(org.opengis.style.ColorMap) ArrayList(java.util.ArrayList) Unit(javax.measure.Unit) ShadedRelief(org.opengis.style.ShadedRelief) PointSymbolizer(org.opengis.style.PointSymbolizer) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) LineSymbolizer(org.opengis.style.LineSymbolizer) RasterSymbolizer(org.opengis.style.RasterSymbolizer) TextSymbolizer(org.opengis.style.TextSymbolizer) Symbolizer(org.opengis.style.Symbolizer) RasterSymbolizer(org.opengis.style.RasterSymbolizer) ContrastEnhancement(org.opengis.style.ContrastEnhancement) Expression(org.opengis.filter.Expression) ChannelSelection(org.opengis.style.ChannelSelection) Literal(org.opengis.filter.Literal) OverlapBehavior(org.opengis.style.OverlapBehavior)

Example 3 with InterpolationPoint

use of org.geotoolkit.style.function.InterpolationPoint in project geotoolkit by Geomatys.

the class GTtoSE110Transformer method visit.

public InterpolateType visit(final Interpolate interpolate) {
    final InterpolateType type = se_factory.createInterpolateType();
    type.setFallbackValue(interpolate.getFallbackValue().toString());
    type.setLookupValue(visitExpression(interpolate.getLookupValue()));
    if (interpolate.getMethod() == Method.COLOR) {
        type.setMethod(MethodType.COLOR);
    } else {
        type.setMethod(MethodType.NUMERIC);
    }
    final Mode mode = interpolate.getMode();
    if (mode == Mode.COSINE) {
        type.setMode(ModeType.COSINE);
    } else if (mode == Mode.CUBIC) {
        type.setMode(ModeType.CUBIC);
    } else {
        type.setMode(ModeType.LINEAR);
    }
    final List<InterpolationPointType> points = type.getInterpolationPoint();
    points.clear();
    for (final InterpolationPoint ip : interpolate.getInterpolationPoints()) {
        final InterpolationPointType point = se_factory.createInterpolationPointType();
        point.setData(ip.getData().doubleValue());
        point.setValue(visitExpression(ip.getValue()));
        points.add(point);
    }
    return type;
}
Also used : InterpolationPoint(org.geotoolkit.style.function.InterpolationPoint) InterpolateType(org.geotoolkit.se.xml.v110.InterpolateType) Mode(org.geotoolkit.style.function.Mode) InterpolationPointType(org.geotoolkit.se.xml.v110.InterpolationPointType)

Example 4 with InterpolationPoint

use of org.geotoolkit.style.function.InterpolationPoint in project geotoolkit by Geomatys.

the class SE110toGTTransformer method visit.

/**
 *  Transform a SLD v1.1 interpolate function in GT interpolate function.
 */
public Interpolate visit(final InterpolateType interpolate) {
    if (interpolate == null)
        return null;
    final Literal fallback = filterFactory.literal(interpolate.getFallbackValue());
    final Expression lookup = visitExpression(interpolate.getLookupValue());
    final Method method;
    if (MethodType.COLOR.equals(interpolate.getMethod())) {
        method = Method.COLOR;
    } else {
        method = Method.NUMERIC;
    }
    final Mode mode;
    if (ModeType.COSINE.equals(interpolate.getMode())) {
        mode = Mode.COSINE;
    } else if (ModeType.CUBIC.equals(interpolate.getMode())) {
        mode = Mode.CUBIC;
    } else {
        mode = Mode.LINEAR;
    }
    final List<InterpolationPoint> values = new ArrayList<InterpolationPoint>();
    for (final InterpolationPointType ip : interpolate.getInterpolationPoint()) {
        values.add(styleFactory.interpolationPoint(ip.getData(), visitExpression(ip.getValue())));
    }
    return styleFactory.interpolateFunction(lookup, values, method, mode, fallback);
}
Also used : InterpolationPoint(org.geotoolkit.style.function.InterpolationPoint) Expression(org.opengis.filter.Expression) Literal(org.opengis.filter.Literal) Mode(org.geotoolkit.style.function.Mode) InterpolationPointType(org.geotoolkit.se.xml.v110.InterpolationPointType) ArrayList(java.util.ArrayList) Method(org.geotoolkit.style.function.Method) ContrastMethod(org.opengis.style.ContrastMethod)

Example 5 with InterpolationPoint

use of org.geotoolkit.style.function.InterpolationPoint in project geotoolkit by Geomatys.

the class GO2Utilities method inferStyle.

/**
 * Try to create a simple style from given statistics. For now, two cases exists:
 * <ol>
 *     <li>
 *         Less than 3 bands are detected. In this case, we simply create a color map over first band. The
 *         color map make use of standard deviation to compute interpolation boundaries.
 *     </li>
 *     <li>
 *         For 3 bands or more, we create a dynamic range RGB rendering based on first bands in the statistics. We
 *         define value boundary for each band using {@link #buildRanges(ImageStatistics, int) a custom empiric
 *         method removing extremums}.
 *     </li>
 * </ol>
 * @param stats The statistics to use for style creation. Can be null or empty, in which case nothing is returned.
 * @param forceAlpha A flag used only if given statistics contains more than 3 bands. Indicates that for RGB styling,
 *                   we must interpret 4th band as alpha component.
 * @return A style inferred from input statistics, or an empty shell if given argument does not contains enough
 * information.
 * @throws IOException It can happen when trying to access a color map definition on disk, but it fails.
 */
public static Optional<MutableStyle> inferStyle(final ImageStatistics stats, final boolean forceAlpha) throws IOException {
    if (stats == null)
        return Optional.empty();
    final ImageStatistics.Band[] bands = stats.getBands();
    if (bands == null || bands.length < 1)
        return Optional.empty();
    if (bands.length < 3) {
        LOGGER.log(Level.FINE, "applyColorMapStyle : fallBack way is choosen." + "GrayScale interpretation of the first coverage image band.");
        final ImageStatistics.Band band0 = bands[0];
        final Double bmin = band0.getMin();
        final Double bmax = band0.getMax();
        if (bmin == null || bmax == null || !Double.isFinite(bmin) || !Double.isFinite(bmax)) {
            LOGGER.log(Level.WARNING, "Image statistics object is present but contains null or non-finite extremas. Ignore it");
            return Optional.empty();
        }
        double palMin = bmin;
        double palMax = bmax;
        final Double mean = band0.getMean();
        final Double std = band0.getStd();
        if (mean != null && std != null && Double.isFinite(mean) && Double.isFinite(std)) {
            palMin = Math.max(bmin, mean - 2 * std);
            palMax = Math.min(bmax, mean + 2 * std);
        }
        if (!Double.isFinite(palMin) || !Double.isFinite(palMax)) {
            LOGGER.finest("Adapting rendering distribution failed. Fallback on input min/max");
            palMin = bmin;
            palMax = bmax;
        }
        assert Double.isFinite(palMin) : "Raster Style fallback : minimum value should be finite. min = " + palMin;
        assert Double.isFinite(palMax) : "Raster Style fallback : maximum value should be finite. max = " + palMax;
        assert palMin >= bmin;
        assert palMax <= bmax;
        final List<InterpolationPoint> values = new ArrayList<>();
        final double[] nodatas = band0.getNoData();
        if (nodatas != null)
            for (double nodata : nodatas) {
                values.add(STYLE_FACTORY.interpolationPoint(nodata, STYLE_FACTORY.literal(new Color(0, 0, 0, 0))));
            }
        values.add(STYLE_FACTORY.interpolationPoint(Float.NaN, STYLE_FACTORY.literal(new Color(0, 0, 0, 0))));
        // -- Color palette
        // Color[] colorsPal = PaletteFactory.getDefault().getColors("rainbow-t");
        Color[] colorsPal = PaletteFactory.getDefault().getColors("grayscale");
        assert colorsPal.length >= 2;
        if (colorsPal.length < 4) {
            final double percent_5 = (colorsPal.length == 3) ? 0.1 : 0.05;
            final Color[] colorsPalTemp = colorsPal;
            colorsPal = Arrays.copyOf(colorsPal, colorsPal.length + 2);
            System.arraycopy(colorsPalTemp, 2, colorsPal, 2, colorsPalTemp.length - 2);
            colorsPal[colorsPal.length - 1] = colorsPalTemp[colorsPalTemp.length - 1];
            colorsPal[1] = DefaultInterpolate.interpolate(colorsPalTemp[0], colorsPalTemp[1], percent_5);
            colorsPal[colorsPal.length - 2] = DefaultInterpolate.interpolate(colorsPalTemp[colorsPalTemp.length - 2], colorsPalTemp[colorsPalTemp.length - 1], 1 - percent_5);
        }
        // -- if difference between band minimum statistic and palette minimum,
        // -- define values between them as transparency
        values.add(STYLE_FACTORY.interpolationPoint(bmin, STYLE_FACTORY.literal(colorsPal[0])));
        assert colorsPal.length >= 4;
        // -- min and max transparency
        final double step = (palMax - palMin) / (colorsPal.length - 3);
        double currentVal = palMin;
        for (int c = 1; c <= colorsPal.length - 2; c++) {
            values.add(STYLE_FACTORY.interpolationPoint(currentVal, STYLE_FACTORY.literal(colorsPal[c])));
            currentVal += step;
        }
        assert StrictMath.abs(currentVal - step - palMax) < 1E-9;
        values.add(STYLE_FACTORY.interpolationPoint(bmax, STYLE_FACTORY.literal(colorsPal[colorsPal.length - 1])));
        final Expression function = STYLE_FACTORY.interpolateFunction(DEFAULT_CATEGORIZE_LOOKUP, values, Method.COLOR, Mode.LINEAR, DEFAULT_FALLBACK);
        final ColorMap colorMap = STYLE_FACTORY.colorMap(function);
        final RasterSymbolizer symbol = STYLE_FACTORY.rasterSymbolizer(band0.getName(), null, null, null, colorMap, null, null, null);
        return Optional.of(STYLE_FACTORY.style(symbol));
    } else {
        LOGGER.log(Level.FINE, "RGBStyle : fallBack way is choosen." + "RGB interpretation of the three first coverage image bands.");
        final int rgbNumBand = forceAlpha && bands.length > 3 ? 4 : 3;
        assert rgbNumBand <= bands.length;
        final double[][] ranges = buildRanges(stats, 4);
        final List<DRChannel> channels = new ArrayList<>();
        for (int i = 0; i < rgbNumBand; i++) {
            final DRChannel channel = new DRChannel();
            final String bandName = bands[i].getName();
            channel.setBand(bandName == null || bandName.isEmpty() ? Integer.toString(i) : bandName);
            channel.setColorSpaceComponent(DynamicRangeSymbolizer.DRChannel.RGBA_COMPONENTS[i]);
            DynamicRangeSymbolizer.DRBound drBound = new DynamicRangeSymbolizer.DRBound();
            drBound.setValue(FILTER_FACTORY.literal(ranges[i][0]));
            channel.setLower(drBound);
            drBound = new DynamicRangeSymbolizer.DRBound();
            drBound.setValue(FILTER_FACTORY.literal(ranges[i][1]));
            channel.setUpper(drBound);
            channels.add(channel);
        }
        final DynamicRangeSymbolizer drgb = new DynamicRangeSymbolizer();
        drgb.setChannels(channels);
        return Optional.of(STYLE_FACTORY.style(drgb));
    }
}
Also used : InterpolationPoint(org.geotoolkit.style.function.InterpolationPoint) DRChannel(org.geotoolkit.display2d.ext.dynamicrange.DynamicRangeSymbolizer.DRChannel) Color(java.awt.Color) ArrayList(java.util.ArrayList) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) MultiPoint(org.locationtech.jts.geom.MultiPoint) Point(org.locationtech.jts.geom.Point) Paint(java.awt.Paint) InterpolationPoint(org.geotoolkit.style.function.InterpolationPoint) DynamicRangeSymbolizer(org.geotoolkit.display2d.ext.dynamicrange.DynamicRangeSymbolizer) Expression(org.opengis.filter.Expression) ImageStatistics(org.geotoolkit.storage.coverage.ImageStatistics)

Aggregations

InterpolationPoint (org.geotoolkit.style.function.InterpolationPoint)9 Expression (org.opengis.filter.Expression)7 ArrayList (java.util.ArrayList)6 ColorMap (org.opengis.style.ColorMap)5 Color (java.awt.Color)4 Interpolate (org.geotoolkit.style.function.Interpolate)4 HashMap (java.util.HashMap)2 InterpolationPointType (org.geotoolkit.se.xml.v110.InterpolationPointType)2 Categorize (org.geotoolkit.style.function.Categorize)2 DefaultInterpolationPoint (org.geotoolkit.style.function.DefaultInterpolationPoint)2 Jenks (org.geotoolkit.style.function.Jenks)2 Mode (org.geotoolkit.style.function.Mode)2 Test (org.junit.Test)2 Literal (org.opengis.filter.Literal)2 LinearGradientPaint (java.awt.LinearGradientPaint)1 MultipleGradientPaint (java.awt.MultipleGradientPaint)1 Paint (java.awt.Paint)1 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1