Search in sources :

Example 6 with ChannelSelection

use of org.geotools.styling.ChannelSelection in project sldeditor by robward-scisys.

the class VOGeoServerContrastEnhancementNormalizeRedTest method testVOGeoServerContrastEnhancementNormalizeRed.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.vendor.geoserver.raster.VOGeoServerContrastEnhancementNormalizeRed#VOGeoServerContrastEnhancementNormalizeRed(java.lang.Class, com.sldeditor.ui.detail.RasterSymbolizerDetails)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.vendor.geoserver.raster.VOGeoServerContrastEnhancementNormalizeRed#getContrastEnhancement(com.sldeditor.common.xml.ui.GroupIdEnum, org.geotools.styling.ChannelSelection)}.
 */
@Test
public void testVOGeoServerContrastEnhancementNormalizeRed() {
    RasterSymbolizerDetails panel = new RasterSymbolizerDetails();
    VOGeoServerContrastEnhancementNormalizeRed testObj = new VOGeoServerContrastEnhancementNormalizeRed(panel.getClass(), panel);
    RasterSymbolizer rasterSymbolizer = null;
    testObj.setParentPanel(panel);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    rasterSymbolizer = styleFactory.createRasterSymbolizer();
    GroupConfigInterface constrastMethodGroup = panel.getGroup(GroupIdEnum.RASTER_RGB_CHANNEL_RED_CONTRAST_METHOD);
    assertNotNull(constrastMethodGroup);
    MultiOptionGroup constrastMethodGroup2 = (MultiOptionGroup) constrastMethodGroup;
    Box box = Box.createVerticalBox();
    constrastMethodGroup2.createUI(panel.getFieldDataManager(), box, panel, panel.getPanelId());
    constrastMethodGroup2.setOption(GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD_LOGARITHMIC);
    ChannelSelection channelSelection = createChannelSelection(styleFactory, ContrastMethod.LOGARITHMIC);
    rasterSymbolizer.setChannelSelection(channelSelection);
    testObj.populate(rasterSymbolizer);
    SelectedSymbol.getInstance().setSymbolizer(rasterSymbolizer);
    Controller.getInstance().setPopulating(true);
    panel.populate(SelectedSymbol.getInstance());
    Controller.getInstance().setPopulating(false);
    testObj.updateSymbol(rasterSymbolizer);
    channelSelection = createChannelSelection(styleFactory, ContrastMethod.EXPONENTIAL);
    rasterSymbolizer.setChannelSelection(channelSelection);
    constrastMethodGroup2.setOption(GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD_EXPONENTIAL);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);
    channelSelection = createChannelSelection(styleFactory, ContrastMethod.HISTOGRAM);
    rasterSymbolizer.setChannelSelection(channelSelection);
    constrastMethodGroup2.setOption(GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD_HISTOGRAM);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);
    channelSelection = createChannelSelection(styleFactory, ContrastMethod.NORMALIZE);
    constrastMethodGroup2.setOption(GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD_NORMALIZE);
    rasterSymbolizer.setChannelSelection(channelSelection);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);
    // Error
    channelSelection = createChannelSelectionError(styleFactory, ContrastMethod.NORMALIZE);
    rasterSymbolizer.setChannelSelection(channelSelection);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);
    // Increase code coverage
    testObj.populate((SelectedSymbol) null);
    testObj.populate((TextSymbolizer) null);
    testObj.populate((PolygonSymbolizer) null);
    testObj.updateSymbol((TextSymbolizer) null);
    testObj.updateSymbol((PolygonSymbolizer) null);
    testObj.preLoadSymbol();
    assertTrue(testObj.isDataPresent());
    testObj.dataChanged(FieldIdEnum.DESCRIPTION);
}
Also used : RasterSymbolizer(org.geotools.styling.RasterSymbolizer) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) ChannelSelection(org.geotools.styling.ChannelSelection) RasterSymbolizerDetails(com.sldeditor.ui.detail.RasterSymbolizerDetails) VOGeoServerContrastEnhancementNormalizeRed(com.sldeditor.ui.detail.vendor.geoserver.raster.VOGeoServerContrastEnhancementNormalizeRed) Box(javax.swing.Box) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup) Test(org.junit.Test)

Example 7 with ChannelSelection

use of org.geotools.styling.ChannelSelection in project sldeditor by robward-scisys.

the class RasterReader method createRGBChannelSymbol.

/**
 * Creates the RGB channel symbol.
 *
 * @param sym the sym
 * @param cov the cov
 * @param numBands the num bands
 */
private void createRGBChannelSymbol(RasterSymbolizer sym, GridCoverage2D cov, int numBands) {
    // Get the names of the bands
    String[] sampleDimensionNames = new String[numBands];
    for (int i = 0; i < numBands; i++) {
        GridSampleDimension dim = cov.getSampleDimension(i);
        sampleDimensionNames[i] = dim.getDescription().toString();
    }
    final int RED = 0;
    final int GREEN = 1;
    final int BLUE = 2;
    int[] channelNum = { -1, -1, -1 };
    // Note that the channel numbers we record are indexed from 1, not 0.
    for (int i = 0; i < numBands; i++) {
        String name = sampleDimensionNames[i].toLowerCase();
        if (name != null) {
            if (name.matches("red.*")) {
                channelNum[RED] = i + 1;
            } else if (name.matches("green.*")) {
                channelNum[GREEN] = i + 1;
            } else if (name.matches("blue.*")) {
                channelNum[BLUE] = i + 1;
            }
        }
    }
    // we fall back to using the first three bands in order
    if (channelNum[RED] < 0 || channelNum[GREEN] < 0 || channelNum[BLUE] < 0) {
        channelNum[RED] = 1;
        channelNum[GREEN] = 2;
        channelNum[BLUE] = 3;
    }
    // Now we create a RasterSymbolizer using the selected channels
    SelectedChannelType[] sct = new SelectedChannelType[cov.getNumSampleDimensions()];
    ContrastEnhancement ce = sf.contrastEnhancement(ff.literal(1.0), ContrastMethod.NORMALIZE);
    for (int i = 0; i < 3; i++) {
        sct[i] = sf.createSelectedChannelType(String.valueOf(channelNum[i]), ce);
    }
    ChannelSelection sel = sf.channelSelection(sct[RED], sct[GREEN], sct[BLUE]);
    sym.setChannelSelection(sel);
}
Also used : SelectedChannelType(org.geotools.styling.SelectedChannelType) ContrastEnhancement(org.geotools.styling.ContrastEnhancement) ChannelSelection(org.geotools.styling.ChannelSelection) GridSampleDimension(org.geotools.coverage.GridSampleDimension)

Example 8 with ChannelSelection

use of org.geotools.styling.ChannelSelection in project sldeditor by robward-scisys.

the class VOGeoServerContrastEnhancementNormalize method updateSymbol.

/*
     * (non-Javadoc)
     * 
     * @see
     * com.sldeditor.ui.detail.vendor.geoserver.VendorOptionInterface#updateSymbol(org.geotools.
     * styling.RasterSymbolizer)
     */
@Override
public void updateSymbol(RasterSymbolizer rasterSymbolizer) {
    if (parentPanel != null) {
        GroupConfigInterface group = parentPanel.getGroup(GroupIdEnum.RASTER_CHANNELSELECTION);
        if (group != null) {
            if (group.isPanelEnabled()) {
                MultiOptionGroup contrastEnhancementGroup = (MultiOptionGroup) group;
                ChannelSelection channelSelection = rasterSymbolizer.getChannelSelection();
                OptionGroup selectedOption = contrastEnhancementGroup.getSelectedOptionGroup();
                ContrastEnhancement contrastEnhancement = getContrastEnhancement(selectedOption.getId(), channelSelection);
                if (contrastEnhancement != null) {
                    extractNormalizeVendorOption(contrastEnhancement);
                }
            }
        }
    }
}
Also used : OptionGroup(com.sldeditor.ui.detail.config.base.OptionGroup) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup) ContrastEnhancement(org.geotools.styling.ContrastEnhancement) ChannelSelection(org.geotools.styling.ChannelSelection) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup)

Example 9 with ChannelSelection

use of org.geotools.styling.ChannelSelection in project sldeditor by robward-scisys.

the class VOGeoServerContrastEnhancementNormalizeBlueTest method testVOGeoServerContrastEnhancementNormalizeBlue.

/**
 * Test method for {@link com.sldeditor.ui.detail.vendor.geoserver.raster.VOGeoServerContrastEnhancementNormalizeBlue#VOGeoServerContrastEnhancementNormalizeBlue(java.lang.Class, com.sldeditor.ui.detail.RasterSymbolizerDetails)}.
 * Test method for {@link com.sldeditor.ui.detail.vendor.geoserver.raster.VOGeoServerContrastEnhancementNormalizeBlue#getContrastEnhancement(com.sldeditor.common.xml.ui.GroupIdEnum, org.geotools.styling.ChannelSelection)}.
 */
@Test
public void testVOGeoServerContrastEnhancementNormalizeBlue() {
    RasterSymbolizerDetails panel = new RasterSymbolizerDetails();
    VOGeoServerContrastEnhancementNormalizeBlue testObj = new VOGeoServerContrastEnhancementNormalizeBlue(panel.getClass(), panel);
    RasterSymbolizer rasterSymbolizer = null;
    testObj.setParentPanel(panel);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    rasterSymbolizer = styleFactory.createRasterSymbolizer();
    GroupConfigInterface constrastMethodGroup = panel.getGroup(GroupIdEnum.RASTER_RGB_CHANNEL_BLUE_CONTRAST_METHOD);
    assertNotNull(constrastMethodGroup);
    MultiOptionGroup constrastMethodGroup2 = (MultiOptionGroup) constrastMethodGroup;
    Box box = Box.createVerticalBox();
    constrastMethodGroup2.createUI(panel.getFieldDataManager(), box, panel, panel.getPanelId());
    constrastMethodGroup2.setOption(GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD_LOGARITHMIC);
    ChannelSelection channelSelection = createChannelSelection(styleFactory, ContrastMethod.LOGARITHMIC);
    rasterSymbolizer.setChannelSelection(channelSelection);
    testObj.populate(rasterSymbolizer);
    SelectedSymbol.getInstance().setSymbolizer(rasterSymbolizer);
    Controller.getInstance().setPopulating(true);
    panel.populate(SelectedSymbol.getInstance());
    Controller.getInstance().setPopulating(false);
    testObj.updateSymbol(rasterSymbolizer);
    channelSelection = createChannelSelection(styleFactory, ContrastMethod.EXPONENTIAL);
    rasterSymbolizer.setChannelSelection(channelSelection);
    constrastMethodGroup2.setOption(GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD_EXPONENTIAL);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);
    channelSelection = createChannelSelection(styleFactory, ContrastMethod.HISTOGRAM);
    rasterSymbolizer.setChannelSelection(channelSelection);
    constrastMethodGroup2.setOption(GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD_HISTOGRAM);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);
    channelSelection = createChannelSelection(styleFactory, ContrastMethod.NORMALIZE);
    constrastMethodGroup2.setOption(GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD_NORMALIZE);
    rasterSymbolizer.setChannelSelection(channelSelection);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);
    // Error
    channelSelection = createChannelSelectionError(styleFactory, ContrastMethod.NORMALIZE);
    rasterSymbolizer.setChannelSelection(channelSelection);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);
    // Increase code coverage
    testObj.populate((SelectedSymbol) null);
    testObj.populate((TextSymbolizer) null);
    testObj.populate((PolygonSymbolizer) null);
    testObj.updateSymbol((TextSymbolizer) null);
    testObj.updateSymbol((PolygonSymbolizer) null);
    testObj.preLoadSymbol();
    assertTrue(testObj.isDataPresent());
    testObj.dataChanged(FieldIdEnum.DESCRIPTION);
}
Also used : RasterSymbolizer(org.geotools.styling.RasterSymbolizer) VOGeoServerContrastEnhancementNormalizeBlue(com.sldeditor.ui.detail.vendor.geoserver.raster.VOGeoServerContrastEnhancementNormalizeBlue) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) ChannelSelection(org.geotools.styling.ChannelSelection) RasterSymbolizerDetails(com.sldeditor.ui.detail.RasterSymbolizerDetails) Box(javax.swing.Box) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup) Test(org.junit.Test)

Example 10 with ChannelSelection

use of org.geotools.styling.ChannelSelection in project sldeditor by robward-scisys.

the class VOGeoServerContrastEnhancementNormalizeBlueTest method createChannelSelectionError.

/**
 * Creates the channel selection error object.
 *
 * @param styleFactory the style factory
 * @param contrastMethod the contrast method
 * @return the channel selection
 */
private ChannelSelection createChannelSelectionError(StyleFactoryImpl styleFactory, ContrastMethod contrastMethod) {
    ContrastEnhancement contrastEnhancement = (ContrastEnhancement) styleFactory.contrastEnhancement(null, contrastMethod.name());
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Map<String, Expression> options = contrastEnhancement.getOptions();
    options.put("algorithm", ff.literal("TestStretchToMinimumMaximum"));
    options.put("minValue", ff.literal("1.0"));
    options.put("maxValue", ff.literal("5.0"));
    SelectedChannelType channelType = styleFactory.createSelectedChannelType("channel name", contrastEnhancement);
    SelectedChannelType[] channels = new SelectedChannelType[3];
    channels[0] = channelType;
    channels[1] = channelType;
    channels[2] = channelType;
    ChannelSelection channelSelection = styleFactory.createChannelSelection(channels);
    return channelSelection;
}
Also used : SelectedChannelType(org.geotools.styling.SelectedChannelType) ContrastEnhancement(org.geotools.styling.ContrastEnhancement) Expression(org.opengis.filter.expression.Expression) ChannelSelection(org.geotools.styling.ChannelSelection) FilterFactory(org.opengis.filter.FilterFactory)

Aggregations

ChannelSelection (org.geotools.styling.ChannelSelection)19 ContrastEnhancement (org.geotools.styling.ContrastEnhancement)14 SelectedChannelType (org.geotools.styling.SelectedChannelType)13 Expression (org.opengis.filter.expression.Expression)12 FilterFactory (org.opengis.filter.FilterFactory)10 GroupConfigInterface (com.sldeditor.ui.detail.config.base.GroupConfigInterface)8 MultiOptionGroup (com.sldeditor.ui.detail.config.base.MultiOptionGroup)8 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)7 RasterSymbolizerDetails (com.sldeditor.ui.detail.RasterSymbolizerDetails)5 Box (javax.swing.Box)5 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)5 Test (org.junit.Test)5 OptionGroup (com.sldeditor.ui.detail.config.base.OptionGroup)2 ColorMap (org.geotools.styling.ColorMap)2 ShadedRelief (org.geotools.styling.ShadedRelief)2 OverlapBehavior (org.opengis.style.OverlapBehavior)2 VOGeoServerContrastEnhancementNormalizeBlue (com.sldeditor.ui.detail.vendor.geoserver.raster.VOGeoServerContrastEnhancementNormalizeBlue)1 VOGeoServerContrastEnhancementNormalizeGreen (com.sldeditor.ui.detail.vendor.geoserver.raster.VOGeoServerContrastEnhancementNormalizeGreen)1 VOGeoServerContrastEnhancementNormalizeGrey (com.sldeditor.ui.detail.vendor.geoserver.raster.VOGeoServerContrastEnhancementNormalizeGrey)1 VOGeoServerContrastEnhancementNormalizeOverall (com.sldeditor.ui.detail.vendor.geoserver.raster.VOGeoServerContrastEnhancementNormalizeOverall)1