    001    //$HeadURL: https://sushibar/svn/deegree/base/trunk/resources/eclipse/svn_classfile_header_template.xml $
    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
    037    package org.deegree.graphics.sld;
    038
    039    import java.util.List;
    040
    041    import org.deegree.graphics.sld.SLDFactory.Method;
    042    import org.deegree.graphics.sld.SLDFactory.Mode;
    043
    044    /**
    045     * <code>Interpolate</code> encapsulates data from the Symbology Encoding Schema (InterpolateType).
    046     *
    047     * @author <a href="mailto:schmitz@lat-lon.de">Andreas Schmitz</a>
    048     * @author last edited by: $Author:$
    049     *
    050     * @version $Revision:$, $Date:$
    051     */
    052    public class Interpolate {
    053
    054        private String fallbackValue;
    055
    056        private ParameterValueType lookupValue;
    057
    058        private Mode mode;
    059
    060        private Method method;
    061
    062        private List<InterpolationPoint> points;
    063
    064        /**
    065         * @param fallbackValue
    066         */
    067        public Interpolate( String fallbackValue ) {
    068            this.fallbackValue = fallbackValue;
    069        }
    070
    071        /**
    072         * @param lookupValue
    073         */
    074        public void setLookupValue( ParameterValueType lookupValue ) {
    075            this.lookupValue = lookupValue;
    076        }
    077
    078        /**
    079         * @return the fallbackValue
    080         */
    081        public String getFallbackValue() {
    082            return fallbackValue;
    083        }
    084
    085        /**
    086         * @return the lookupValue
    087         */
    088        public ParameterValueType getLookupValue() {
    089            return lookupValue;
    090        }
    091
    092        /**
    093         * @return the method
    094         */
    095        public Method getMethod() {
    096            return method;
    097        }
    098
    099        /**
    100         * @return the mode
    101         */
    102        public Mode getMode() {
    103            return mode;
    104        }
    105
    106        /**
    107         * @param mode
    108         */
    109        public void setMode( Mode mode ) {
    110            this.mode = mode;
    111        }
    112
    113        /**
    114         * @param method
    115         */
    116        public void setMethod( Method method ) {
    117            this.method = method;
    118        }
    119
    120        /**
    121         * @param d
    122         * @param opac
    123         *            the default opacity if none has been set
    124         * @return the color value as int
    125         */
    126        public int interpolate( float d, int opac ) {
    127            int opacity = opac >> 24;
    128
    129            InterpolationPoint p = points.get( 0 );
    130            int r = p.redValue, g = p.greenValue, b = p.blueValue, o = p.opacitySet ? p.opacity : opacity;
    131            double data = p.data;
    132            if ( d < p.data ) {
    133                return ( o << 24 ) + ( r << 16 ) + ( g << 8 ) + b;
    134            }
    135
    136            for ( int i = 1; i < points.size(); ++i ) {
    137                p = points.get( i );
    138                if ( p.data > d ) {
    139                    double f = ( p.data - d ) / ( p.data - data );
    140                    return ( ( (int) ( ( 1 - f ) * ( p.opacitySet ? p.opacity : opacity ) + f * o ) ) << 24 )
    141                           + ( ( (int) ( ( 1 - f ) * p.redValue + f * r ) ) << 16 )
    142                           + ( ( (int) ( ( 1 - f ) * p.greenValue + f * g ) ) << 8 )
    143                           + ( (int) ( ( ( 1 - f ) * p.blueValue + f * b ) ) );
    144                }
    145                r = p.redValue;
    146                g = p.greenValue;
    147                b = p.blueValue;
    148                o = p.opacitySet ? p.opacity : opacity;
    149                data = p.data;
    150            }
    151
    152            return ( o << 24 ) + ( r << 16 ) + ( g << 8 ) + b;
    153        }
    154
    155        /**
    156         * @param points
    157         */
    158        public void setInterpolationPoints( List<InterpolationPoint> points ) {
    159            this.points = points;
    160        }
    161
    162    }