    001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/graphics/sld/RasterSymbolizer.java $
    002    /*----------------------------------------------------------------------------
    003     This file is part of deegree, http://deegree.org/
    004     Copyright (C) 2001-2009 by:
    005       Department of Geography, University of Bonn
    006     and
    007       lat/lon GmbH
    008
    009     This library is free software; you can redistribute it and/or modify it under
    010     the terms of the GNU Lesser General Public License as published by the Free
    011     Software Foundation; either version 2.1 of the License, or (at your option)
    012     any later version.
    013     This library is distributed in the hope that it will be useful, but WITHOUT
    014     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    015     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
    016     details.
    017     You should have received a copy of the GNU Lesser General Public License
    018     along with this library; if not, write to the Free Software Foundation, Inc.,
    019     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    020
    021     Contact information:
    022
    023     lat/lon GmbH
    024     Aennchenstr. 19, 53177 Bonn
    025     Germany
    026     http://lat-lon.de/
    027
    028     Department of Geography, University of Bonn
    029     Prof. Dr. Klaus Greve
    030     Postfach 1147, 53001 Bonn
    031     Germany
    032     http://www.geographie.uni-bonn.de/deegree/
    033
    034     e-mail: info@deegree.org
    035    ----------------------------------------------------------------------------*/
    036    package org.deegree.graphics.sld;
    037
    038    import org.deegree.framework.log.ILogger;
    039    import org.deegree.framework.log.LoggerFactory;
    040    import org.deegree.framework.util.Pair;
    041    import org.deegree.framework.xml.Marshallable;
    042    import org.deegree.model.filterencoding.FilterEvaluationException;
    043    import org.deegree.ogcbase.CommonNamespaces;
    044
    045    /**
    046     * <code>RasterSymbolizer</code> encapsulates the Symbology Encoding values that may have been set.
    047     * Note that everything is optional, so all values may be null.
    048     *
    049     * @author <a href="mailto:schmitz@lat-lon.de">Andreas Schmitz</a>
    050     * @author last edited by: $Author: lbuesching $
    051     *
    052     * @version $Revision: 18404 $, $Date: 2009-07-09 10:27:49 +0200 (Do, 09. Jul 2009) $
    053     */
    054    public class RasterSymbolizer extends AbstractSymbolizer implements Marshallable {
    055
    056        private static final ILogger LOG = LoggerFactory.getLogger( RasterSymbolizer.class );
    057
    058        private double opacity;
    059
    060        private boolean opacitySet;
    061
    062        private Categorize categorize;
    063
    064        private Interpolate interpolate;
    065
    066        private boolean scaleSet;
    067
    068        private boolean shaded;
    069
    070        private int dim;
    071
    072        private float[] kernel;
    073
    074        private double gamma = 1;
    075
    076        /**
    077         * Initializes nothing.
    078         */
    079        public RasterSymbolizer() {
    080            // initialize nothing
    081        }
    082
    083        /**
    084         * @param min
    085         * @param max
    086         */
    087        public RasterSymbolizer( double min, double max ) {
    088            if ( min > 0 || max > 0 ) {
    089                scaleSet = true;
    090                this.minDenominator = min;
    091                this.maxDenominator = max;
    092            }
    093        }
    094
    095        /**
    096         * @param opac
    097         */
    098        public void setOpacity( ParameterValueType opac ) {
    099            try {
    100                opacity = Double.parseDouble( opac.evaluate( null ) );
    101                opacitySet = true;
    102            } catch ( NumberFormatException e ) {
    103                LOG.logError( "The opacity value of a RasterSymbolizer could not be parsed.", e );
    104            } catch ( FilterEvaluationException e ) {
    105                LOG.logError( "The opacity value of a RasterSymbolizer could not be parsed.", e );
    106            }
    107        }
    108
    109        /**
    110         * @return the opacity or 1, if none was set
    111         */
    112        public double getOpacity() {
    113            return opacitySet ? opacity : 1;
    114        }
    115
    116        /**
    117         * @param categorize
    118         */
    119        public void setCategorize( Categorize categorize ) {
    120            this.categorize = categorize;
    121        }
    122
    123        /**
    124         * @param interpolate
    125         */
    126        public void setInterpolate( Interpolate interpolate ) {
    127            this.interpolate = interpolate;
    128        }
    129
    130        /**
    131         * @return the categorize
    132         */
    133        public Categorize getCategorize() {
    134            return categorize;
    135        }
    136
    137        /**
    138         * @return the interpolate
    139         */
    140        public Interpolate getInterpolate() {
    141            return interpolate;
    142        }
    143
    144        /**
    145         * @return true, if none of the options has been set (scale is ignored)
    146         */
    147        public boolean isDefault() {
    148            return ( !opacitySet ) && categorize == null && interpolate == null;
    149        }
    150
    151        /**
    152         * @param shaded
    153         */
    154        public void setShaded( boolean shaded ) {
    155            this.shaded = shaded;
    156        }
    157
    158        /**
    159         * @return true, if the symbolization should be shaded
    160         */
    161        public boolean getShaded() {
    162            return shaded;
    163        }
    164
    165        /**
    166         * @param scale
    167         * @return true, if no scale hints have been set or if the given scale is valid
    168         */
    169        public boolean scaleValid( double scale ) {
    170            return ( scaleSet && minDenominator <= scale && maxDenominator >= scale ) || !scaleSet;
    171        }
    172
    173        @Override
    174        public String toString() {
    175            return opacity + ", " + categorize + ", " + interpolate;
    176        }
    177
    178        /**
    179         * @param dim
    180         * @param kernel
    181         */
    182        public void setShadeKernel( int dim, float[] kernel ) {
    183            this.dim = dim;
    184            this.kernel = kernel;
    185        }
    186
    187        /**
    188         * @return the shade kernel to be used
    189         */
    190        public Pair<Integer, float[]> getShadeKernel() {
    191            return new Pair<Integer, float[]>( dim, kernel );
    192        }
    193
    194        /**
    195         * @param gamma
    196         */
    197        public void setGamma( double gamma ) {
    198            this.gamma = gamma;
    199        }
    200
    201        /**
    202         * @return the gamma value
    203         */
    204        public double getGamma() {
    205            return gamma;
    206        }
    207
    208        /**
    209         * exports the content of the RasterSymbolizer as XML formated String. At the moment only the
    210         * export of opacity and gamma value is supported!
    211         *
    212         *
    213         * @return xml representation of the RasterSymbolizer
    214         */
    215        public String exportAsXML() {
    216            StringBuffer sb = new StringBuffer( 200 );
    217            sb.append( "<se:RasterSymbolizer xmlns:se=\"" + CommonNamespaces.SENS + "\" >" );
    218            sb.append( "<se:Opacity>" );
    219            sb.append( this.opacity );
    220            sb.append( "</se:Opacity>" );
    221            sb.append( "<se:ContrastEnhancement>" );
    222            sb.append( "<se:GammaValue>" );
    223            sb.append( this.gamma );
    224            sb.append( "</se:GammaValue>" );
    225            sb.append( "</se:ContrastEnhancement>" );
    226            sb.append( "</se:RasterSymbolizer>" );
    227            return sb.toString();
    228        }
    229
    230    }